Skip to content

Commit

Permalink
Revert "Revert "resource/aws_storagegateway_cached_iscsi_volume: Add …
Browse files Browse the repository at this point in the history
…kms_encrypted and kms_key arguments (#12066)""

This reverts commit 5ae123f4
  • Loading branch information
DrFaust92 committed Sep 30, 2020
1 parent 67cb160 commit 654ea31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 27 additions & 1 deletion aws/resource_aws_storagegateway_cached_iscsi_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ func resourceAwsStorageGatewayCachedIscsiVolume() *schema.Resource {
ForceNew: true,
},
"tags": tagsSchema(),
"kms_encrypted": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"kms_key": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateArn,
RequiredWith: []string{"kms_encrypted"},
},
},
}
}
Expand All @@ -111,6 +123,14 @@ func resourceAwsStorageGatewayCachedIscsiVolumeCreate(d *schema.ResourceData, me
input.SourceVolumeARN = aws.String(v.(string))
}

if v, ok := d.GetOk("kms_key"); ok {
input.KMSKey = aws.String(v.(string))
}

if v, ok := d.GetOk("kms_encrypted"); ok {
input.KMSEncrypted = aws.Bool(v.(bool))
}

log.Printf("[DEBUG] Creating Storage Gateway cached iSCSI volume: %s", input)
output, err := conn.CreateCachediSCSIVolume(input)
if err != nil {
Expand Down Expand Up @@ -147,7 +167,7 @@ func resourceAwsStorageGatewayCachedIscsiVolumeRead(d *schema.ResourceData, meta
output, err := conn.DescribeCachediSCSIVolumes(input)

if err != nil {
if isAWSErr(err, storagegateway.ErrorCodeVolumeNotFound, "") {
if isAWSErr(err, storagegateway.ErrorCodeVolumeNotFound, "") || isAWSErr(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified volume was not found") {
log.Printf("[WARN] Storage Gateway cached iSCSI volume %q not found, removing from state", d.Id())
d.SetId("")
return nil
Expand All @@ -169,6 +189,12 @@ func resourceAwsStorageGatewayCachedIscsiVolumeRead(d *schema.ResourceData, meta
d.Set("volume_arn", arn)
d.Set("volume_id", aws.StringValue(volume.VolumeId))
d.Set("volume_size_in_bytes", int(aws.Int64Value(volume.VolumeSizeInBytes)))
d.Set("kms_key", volume.KMSKey)
if volume.KMSKey != nil {
d.Set("kms_encrypted", true)
} else {
d.Set("kms_encrypted", false)
}

tags, err := keyvaluetags.StoragegatewayListTags(conn, arn)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ The following arguments are supported:
* `volume_size_in_bytes` - (Required) The size of the volume in bytes.
* `snapshot_id` - (Optional) The snapshot ID of the snapshot to restore as the new cached volume. e.g. `snap-1122aabb`.
* `source_volume_arn` - (Optional) The ARN for an existing volume. Specifying this ARN makes the new volume into an exact copy of the specified existing volume's latest recovery point. The `volume_size_in_bytes` value for this new volume must be equal to or larger than the size of the existing volume, in bytes.
* `kms_encrypted` - (Optional) Set to `true` to use Amazon S3 server side encryption with your own AWS KMS key, or `false` to use a key managed by Amazon S3.
* `kms_key` - (Optional) The Amazon Resource Name (ARN) of the AWS KMS key used for Amazon S3 server side encryption. Is required when `kms_encrypted` is set.
* `tags` - (Optional) Key-value map of resource tags

## Attribute Reference
Expand Down

0 comments on commit 654ea31

Please sign in to comment.