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/neptune_cluster: fix ignored kms key on snapshot restore #15240. #33413

Merged
merged 4 commits into from
Sep 13, 2023
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
3 changes: 3 additions & 0 deletions .changelog/33413.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_neptune_cluster: Fix ignored `kms_key_arn` on restore from DB cluster snapshot
```
1 change: 1 addition & 0 deletions internal/service/neptune/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
v := v.(string)

inputC.KmsKeyId = aws.String(v)
inputR.KmsKeyId = aws.String(v)
}

if v, ok := d.GetOk("neptune_cluster_parameter_group_name"); ok {
Expand Down
59 changes: 55 additions & 4 deletions internal/service/neptune/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ func TestAccNeptuneCluster_restoreFromSnapshot(t *testing.T) {
var dbCluster neptune.DBCluster
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_neptune_cluster.test"
keyResourceName := "aws_kms_key.test2"
parameterGroupResourceName := "aws_neptune_cluster_parameter_group.test"

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -587,6 +588,7 @@ func TestAccNeptuneCluster_restoreFromSnapshot(t *testing.T) {
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "backup_retention_period", "5"),
resource.TestCheckResourceAttr(resourceName, "cluster_identifier", rName),
resource.TestCheckResourceAttrPair(resourceName, "kms_key_arn", keyResourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "neptune_cluster_parameter_group_name", parameterGroupResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.Name", rName),
Expand Down Expand Up @@ -1295,6 +1297,52 @@ resource "aws_neptune_cluster_instance" "secondary" {

func testAccClusterConfig_restoreFromSnapshot(rName string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "test1" {
description = %[1]q

policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "kms-tf-1",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "kms:*",
"Resource": "*"
}
]
}
POLICY

}

resource "aws_kms_key" "test2" {
description = %[1]q

policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "kms-tf-2",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "kms:*",
"Resource": "*"
}
]
}
POLICY

}

resource "aws_default_vpc" "test" {}

resource "aws_security_group" "test" {
Expand All @@ -1312,6 +1360,8 @@ resource "aws_neptune_cluster" "source" {
cluster_identifier = "%[1]s-src"
neptune_cluster_parameter_group_name = "default.neptune1.2"
skip_final_snapshot = true
storage_encrypted = true
kms_key_arn = aws_kms_key.test1.arn
}

resource "aws_neptune_cluster_snapshot" "test" {
Expand All @@ -1330,10 +1380,11 @@ resource "aws_neptune_cluster_parameter_group" "test" {
}

resource "aws_neptune_cluster" "test" {
cluster_identifier = %[1]q
skip_final_snapshot = true
snapshot_identifier = aws_neptune_cluster_snapshot.test.id

cluster_identifier = %[1]q
skip_final_snapshot = true
storage_encrypted = true
snapshot_identifier = aws_neptune_cluster_snapshot.test.id
kms_key_arn = aws_kms_key.test2.arn
backup_retention_period = 5
neptune_cluster_parameter_group_name = aws_neptune_cluster_parameter_group.test.id
vpc_security_group_ids = aws_security_group.test[*].id
Expand Down
Loading