Skip to content

Commit

Permalink
Added ebs_snapshot kms_key_id acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
jwieringa committed Jan 23, 2018
1 parent b42243c commit 350c7f9
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions aws/resource_aws_ebs_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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"
}
}
`

0 comments on commit 350c7f9

Please sign in to comment.