Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/resource_aws_rds_cluster: Honor kms_key_id when restoring from snapshot #6012

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
opts.AvailabilityZones = expandStringList(attr.List())
}

if attr, ok := d.GetOk("kms_key_id"); ok {
opts.KmsKeyId = aws.String(attr.(string))
}

if attr, ok := d.GetOk("db_subnet_group_name"); ok {
opts.DBSubnetGroupName = aws.String(attr.(string))
}
Expand Down
59 changes: 59 additions & 0 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,38 @@ func TestAccAWSRDSCluster_SnapshotIdentifier_VpcSecurityGroupIds_Tags(t *testing
})
}

func TestAccAWSRDSCluster_SnapshotIdentifier_EncryptedRestore(t *testing.T) {
var dbCluster, sourceDbCluster rds.DBCluster
var dbClusterSnapshot rds.DBClusterSnapshot

keyRegex := regexp.MustCompile("^arn:aws:kms:")

rName := acctest.RandomWithPrefix("tf-acc-test")
sourceDbResourceName := "aws_rds_cluster.source"
snapshotResourceName := "aws_db_cluster_snapshot.test"
resourceName := "aws_rds_cluster.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRDSClusterConfig_SnapshotIdentifier_EncryptedRestore(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(sourceDbResourceName, &sourceDbCluster),
testAccCheckDbClusterSnapshotExists(snapshotResourceName, &dbClusterSnapshot),
testAccCheckAWSClusterExists(resourceName, &dbCluster),
resource.TestMatchResourceAttr(
"aws_rds_cluster.test", "kms_key_id", keyRegex),
resource.TestCheckResourceAttr(
"aws_rds_cluster.test", "storage_encrypted", "true"),
),
},
},
})
}

func testAccCheckAWSClusterDestroy(s *terraform.State) error {
return testAccCheckAWSClusterDestroyWithProvider(s, testAccProvider)
}
Expand Down Expand Up @@ -1924,3 +1956,30 @@ resource "aws_rds_cluster" "test" {
}
`, rName, rName, rName)
}

func testAccAWSRDSClusterConfig_SnapshotIdentifier_EncryptedRestore(rName string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "test" {}

resource "aws_rds_cluster" "source" {
cluster_identifier = "%s-source"
master_password = "barbarbarbar"
master_username = "foo"
skip_final_snapshot = true
}

resource "aws_db_cluster_snapshot" "test" {
db_cluster_identifier = "${aws_rds_cluster.source.id}"
db_cluster_snapshot_identifier = %q
}

resource "aws_rds_cluster" "test" {
cluster_identifier = %q
skip_final_snapshot = true
snapshot_identifier = "${aws_db_cluster_snapshot.test.id}"

storage_encrypted = true
kms_key_id = "${aws_kms_key.test.arn}"
}
`, rName, rName, rName)
}