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

resource/aws_rds_global_cluster: Prevent recreation when using encrypted source_db_cluster_identifier without storage_encrypted #15916

Merged
merged 1 commit into from
Oct 29, 2020
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
1 change: 1 addition & 0 deletions aws/resource_aws_rds_global_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func resourceAwsRDSGlobalCluster() *schema.Resource {
"storage_encrypted": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},
},
Expand Down
54 changes: 54 additions & 0 deletions aws/resource_aws_rds_global_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,34 @@ func TestAccAWSRdsGlobalCluster_SourceDbClusterIdentifier(t *testing.T) {
})
}

func TestAccAWSRdsGlobalCluster_SourceDbClusterIdentifier_StorageEncrypted(t *testing.T) {
var globalCluster1 rds.GlobalCluster
rName := acctest.RandomWithPrefix("tf-acc-test")
clusterResourceName := "aws_rds_cluster.test"
resourceName := "aws_rds_global_cluster.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSRdsGlobalCluster(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRdsGlobalClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRdsGlobalClusterConfigSourceDbClusterIdentifierStorageEncrypted(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRdsGlobalClusterExists(resourceName, &globalCluster1),
resource.TestCheckResourceAttrPair(resourceName, "source_db_cluster_identifier", clusterResourceName, "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "source_db_cluster_identifier"},
},
},
})
}

func TestAccAWSRdsGlobalCluster_StorageEncrypted(t *testing.T) {
var globalCluster1, globalCluster2 rds.GlobalCluster
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -543,6 +571,32 @@ resource "aws_rds_global_cluster" "test" {
`, rName)
}

func testAccAWSRdsGlobalClusterConfigSourceDbClusterIdentifierStorageEncrypted(rName string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "test" {
cluster_identifier = %[1]q
engine = "aurora-postgresql"
engine_version = "10.11" # Minimum supported version for Global Clusters
master_password = "mustbeeightcharacters"
master_username = "test"
skip_final_snapshot = true
storage_encrypted = true

# global_cluster_identifier cannot be Computed

lifecycle {
ignore_changes = [global_cluster_identifier]
}
}

resource "aws_rds_global_cluster" "test" {
force_destroy = true
global_cluster_identifier = %[1]q
source_db_cluster_identifier = aws_rds_cluster.test.arn
}
`, rName)
}

func testAccAWSRdsGlobalClusterConfigStorageEncrypted(rName string, storageEncrypted bool) string {
return fmt.Sprintf(`
resource "aws_rds_global_cluster" "test" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/rds_global_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The following arguments are supported:
* **NOTE:** When the engine is set to `aurora-mysql`, an engine version compatible with global database is required. The earliest available version is `5.7.mysql_aurora.2.06.0`.
* `force_destroy` - (Optional) Enable to remove DB Cluster members from Global Cluster on destroy. Required with `source_db_cluster_identifier`.
* `source_db_cluster_identifier` - (Optional) Amazon Resource Name (ARN) to use as the primary DB Cluster of the Global Cluster on creation. Terraform cannot perform drift detection of this value.
* `storage_encrypted` - (Optional, Forces new resources) Specifies whether the DB cluster is encrypted. The default is `false`.
* `storage_encrypted` - (Optional, Forces new resources) Specifies whether the DB cluster is encrypted. The default is `false` unless `source_db_cluster_identifier` is specified and encrypted. Terraform will only perform drift detection if a configuration value is provided.

## Attribute Reference

Expand Down