From b44420aff25de3d5182aa59e937e44d2d5b0a245 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 20 Mar 2023 16:57:45 -0400 Subject: [PATCH 1/4] r/aws_rds_cluster: snapshot_identifier conflicts with global_cluster_identifier --- internal/service/rds/cluster.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index e1a4532d18c..6897ec9f744 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -432,6 +432,13 @@ func ResourceCluster() *schema.Resource { "snapshot_identifier": { Type: schema.TypeString, Optional: true, + ConflictsWith: []string{ + // Clusters cannot be joined to an existing global cluster as part of + // the "restore from snapshot" operation. Trigger an error during plan + // to prevent an apply with unexpected results (ie. a regional + // cluster which is not joined to the provided global cluster). + "global_cluster_identifier", + }, }, "source_region": { Type: schema.TypeString, From 156a8048a5db584e8caf7a4b974c106c17eb7f79 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 20 Mar 2023 16:58:45 -0400 Subject: [PATCH 2/4] r/aws_rds_cluster: document snapshot and global cluster id conflict --- website/docs/r/rds_cluster.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/rds_cluster.html.markdown b/website/docs/r/rds_cluster.html.markdown index 443be624565..262954e97ff 100644 --- a/website/docs/r/rds_cluster.html.markdown +++ b/website/docs/r/rds_cluster.html.markdown @@ -191,7 +191,7 @@ The following arguments are supported: * `scaling_configuration` - (Optional) Nested attribute with scaling properties. Only valid when `engine_mode` is set to `serverless`. More details below. * `serverlessv2_scaling_configuration`- (Optional) Nested attribute with scaling properties for ServerlessV2. Only valid when `engine_mode` is set to `provisioned`. More details below. * `skip_final_snapshot` - (Optional) Determines whether a final DB snapshot is created before the DB cluster is deleted. If true is specified, no DB snapshot is created. If false is specified, a DB snapshot is created before the DB cluster is deleted, using the value from `final_snapshot_identifier`. Default is `false`. -* `snapshot_identifier` - (Optional) Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot. +* `snapshot_identifier` - (Optional) Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot. Conflicts with `global_cluster_identifier`. Clusters cannot be restored from snapshot **and** joined to an existing global cluster in a single operation. See the [AWS documentation](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-getting-started.html#aurora-global-database.use-snapshot) or this [`aws_rds_global_cluster` example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_global_cluster#new-global-cluster-from-existing-db-cluster) for instructions on building a global cluster starting from a snapshot. * `source_region` - (Optional) The source region for an encrypted replica DB cluster. * `allocated_storage` - (Optional) The amount of storage in gibibytes (GiB) to allocate to each DB instance in the Multi-AZ DB cluster. (This setting is required to create a Multi-AZ DB cluster). * `storage_type` - (Optional) Specifies the storage type to be associated with the DB cluster. (This setting is required to create a Multi-AZ DB cluster). Valid values: `io1`, Default: `io1`. From 5a78f694da857309ed85038040dd3e7838db4b16 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Tue, 21 Mar 2023 10:36:01 -0400 Subject: [PATCH 3/4] chore: changelog --- .changelog/30158.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/30158.txt diff --git a/.changelog/30158.txt b/.changelog/30158.txt new file mode 100644 index 00000000000..212905184c6 --- /dev/null +++ b/.changelog/30158.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_rds_cluster: Conflict `snapshot_identifier` and `global_cluster_identifier` attributes, preventing misleading results on restore +``` From 736d002b1ab2ccac8e4a4e77fcc0f369b741edf1 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 22 Mar 2023 10:04:33 -0400 Subject: [PATCH 4/4] r/aws_rds_cluster: add global cluster restored from snapshot example --- website/docs/r/rds_cluster.html.markdown | 32 +++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/website/docs/r/rds_cluster.html.markdown b/website/docs/r/rds_cluster.html.markdown index 262954e97ff..1b5dfd797fa 100644 --- a/website/docs/r/rds_cluster.html.markdown +++ b/website/docs/r/rds_cluster.html.markdown @@ -145,6 +145,36 @@ resource "aws_rds_cluster_instance" "example" { } ``` +### Global Cluster Restored From Snapshot + +```terraform +data "aws_db_cluster_snapshot" "example" { + db_cluster_identifier = "example-original-cluster" + most_recent = true +} + +resource "aws_rds_cluster" "example" { + # Because the global cluster is sourced from this cluster, the initial + # engine and engine_version values are defined here and automatically + # inherited by the global cluster. + engine = "aurora" + engine_version = "5.6.mysql_aurora.1.22.4" + + cluster_identifier = "example" + snapshot_identifier = data.aws_db_cluster_snapshot.example.id + + lifecycle { + ignore_changes = [snapshot_identifier, global_cluster_identifier] + } +} + +resource "aws_rds_global_cluster" "example" { + global_cluster_identifier = "example" + source_db_cluster_identifier = aws_rds_cluster.example.arn + force_destroy = true +} +``` + ## Argument Reference For more detailed documentation about each argument, refer to @@ -191,7 +221,7 @@ The following arguments are supported: * `scaling_configuration` - (Optional) Nested attribute with scaling properties. Only valid when `engine_mode` is set to `serverless`. More details below. * `serverlessv2_scaling_configuration`- (Optional) Nested attribute with scaling properties for ServerlessV2. Only valid when `engine_mode` is set to `provisioned`. More details below. * `skip_final_snapshot` - (Optional) Determines whether a final DB snapshot is created before the DB cluster is deleted. If true is specified, no DB snapshot is created. If false is specified, a DB snapshot is created before the DB cluster is deleted, using the value from `final_snapshot_identifier`. Default is `false`. -* `snapshot_identifier` - (Optional) Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot. Conflicts with `global_cluster_identifier`. Clusters cannot be restored from snapshot **and** joined to an existing global cluster in a single operation. See the [AWS documentation](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-getting-started.html#aurora-global-database.use-snapshot) or this [`aws_rds_global_cluster` example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_global_cluster#new-global-cluster-from-existing-db-cluster) for instructions on building a global cluster starting from a snapshot. +* `snapshot_identifier` - (Optional) Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot. Conflicts with `global_cluster_identifier`. Clusters cannot be restored from snapshot **and** joined to an existing global cluster in a single operation. See the [AWS documentation](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-getting-started.html#aurora-global-database.use-snapshot) or the [Global Cluster Restored From Snapshot example](#global-cluster-restored-from-snapshot) for instructions on building a global cluster starting with a snapshot. * `source_region` - (Optional) The source region for an encrypted replica DB cluster. * `allocated_storage` - (Optional) The amount of storage in gibibytes (GiB) to allocate to each DB instance in the Multi-AZ DB cluster. (This setting is required to create a Multi-AZ DB cluster). * `storage_type` - (Optional) Specifies the storage type to be associated with the DB cluster. (This setting is required to create a Multi-AZ DB cluster). Valid values: `io1`, Default: `io1`.