From b42243c5b3811c56fb6a1682055c121702f040fa Mon Sep 17 00:00:00 2001 From: Jason Wieringa Date: Sun, 21 Jan 2018 17:53:39 -0800 Subject: [PATCH 1/2] Fixed name on resource_aws_ebs_snapshot.kms_key_id --- aws/resource_aws_ebs_snapshot.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_ebs_snapshot.go b/aws/resource_aws_ebs_snapshot.go index f444df4ef13..8ca7ef717f8 100644 --- a/aws/resource_aws_ebs_snapshot.go +++ b/aws/resource_aws_ebs_snapshot.go @@ -113,7 +113,7 @@ func resourceAwsEbsSnapshotRead(d *schema.ResourceData, meta interface{}) error d.Set("owner_alias", snapshot.OwnerAlias) d.Set("volume_id", snapshot.VolumeId) d.Set("data_encryption_key_id", snapshot.DataEncryptionKeyId) - d.Set("kms_keey_id", snapshot.KmsKeyId) + d.Set("kms_key_id", snapshot.KmsKeyId) d.Set("volume_size", snapshot.VolumeSize) if err := d.Set("tags", tagsToMap(snapshot.Tags)); err != nil { From 350c7f9ea0390333b004d558bc73d30b9f7814cc Mon Sep 17 00:00:00 2001 From: Jason Wieringa Date: Mon, 22 Jan 2018 18:40:19 -0800 Subject: [PATCH 2/2] Added ebs_snapshot kms_key_id acceptance test --- aws/resource_aws_ebs_snapshot_test.go | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/aws/resource_aws_ebs_snapshot_test.go b/aws/resource_aws_ebs_snapshot_test.go index cd1cfbee9b2..cc96e290995 100644 --- a/aws/resource_aws_ebs_snapshot_test.go +++ b/aws/resource_aws_ebs_snapshot_test.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "regexp" "testing" "github.com/aws/aws-sdk-go/aws" @@ -44,6 +45,24 @@ func TestAccAWSEBSSnapshot_withDescription(t *testing.T) { }) } +func TestAccAWSEBSSnapshot_withKms(t *testing.T) { + var v ec2.Snapshot + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccAwsEbsSnapshotConfigWithKms, + Check: resource.ComposeTestCheckFunc( + testAccCheckSnapshotExists("aws_ebs_snapshot.test", &v), + resource.TestMatchResourceAttr("aws_ebs_snapshot.test", "kms_key_id", + regexp.MustCompile("^arn:aws:kms:[a-z]{2}-[a-z]+-\\d{1}:[0-9]{12}:key/[a-z0-9-]{36}$")), + ), + }, + }, + }) +} + func testAccCheckSnapshotExists(n string, v *ec2.Snapshot) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -98,3 +117,32 @@ resource "aws_ebs_snapshot" "test" { description = "EBS Snapshot Acceptance Test" } ` + +const testAccAwsEbsSnapshotConfigWithKms = ` +resource "aws_kms_key" "test" { + deletion_window_in_days = 7 + + tags { + Name = "testAccAwsEbsSnapshotConfigWithKms" + } +} + +resource "aws_ebs_volume" "test" { + availability_zone = "us-west-2a" + size = 1 + encrypted = true + kms_key_id = "${aws_kms_key.test.arn}" + + tags { + Name = "testAccAwsEbsSnapshotConfigWithKms" + } +} + +resource "aws_ebs_snapshot" "test" { + volume_id = "${aws_ebs_volume.test.id}" + + tags { + Name = "testAccAwsEbsSnapshotConfigWithKms" + } +} +`