From f48b17738c46b7c8199f0d7386353e9c1103c996 Mon Sep 17 00:00:00 2001 From: Anthony Wat Date: Mon, 13 Nov 2023 02:33:18 -0500 Subject: [PATCH 1/3] feat: Add enable_local_write_forwarding arg to aws_rds_cluster --- .changelog/34370.txt | 3 ++ internal/service/rds/cluster.go | 23 ++++++++++--- internal/service/rds/cluster_test.go | 42 ++++++++++++++++++++++++ website/docs/r/rds_cluster.html.markdown | 3 +- 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .changelog/34370.txt diff --git a/.changelog/34370.txt b/.changelog/34370.txt new file mode 100644 index 00000000000..492d8f60887 --- /dev/null +++ b/.changelog/34370.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_rds_cluster: Add the `enable_local_write_forwarding` argument to support Aurora MySQL local write forwarding +``` \ No newline at end of file diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index 9f2e8f4cea8..960ce702f8b 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -180,6 +180,16 @@ func ResourceCluster() *schema.Resource { Optional: true, Default: false, }, + "enable_http_endpoint": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "enable_local_write_forwarding": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "enabled_cloudwatch_logs_exports": { Type: schema.TypeSet, Optional: true, @@ -188,11 +198,6 @@ func ResourceCluster() *schema.Resource { ValidateFunc: validation.StringInSlice(ClusterExportableLogType_Values(), false), }, }, - "enable_http_endpoint": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, "endpoint": { Type: schema.TypeString, Computed: true, @@ -974,6 +979,10 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int input.EnableHttpEndpoint = aws.Bool(v.(bool)) } + if v, ok := d.GetOk("enable_local_write_forwarding"); ok { + input.EnableLocalWriteForwarding = aws.Bool(v.(bool)) + } + if v, ok := d.GetOk("enabled_cloudwatch_logs_exports"); ok && v.(*schema.Set).Len() > 0 { input.EnableCloudwatchLogsExports = flex.ExpandStringSet(v.(*schema.Set)) } @@ -1294,6 +1303,10 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int input.EnableHttpEndpoint = aws.Bool(d.Get("enable_http_endpoint").(bool)) } + if d.HasChange("enable_local_write_forwarding") { + input.EnableLocalWriteForwarding = aws.Bool(d.Get("enable_local_write_forwarding").(bool)) + } + if d.HasChange("enabled_cloudwatch_logs_exports") { oraw, nraw := d.GetChange("enabled_cloudwatch_logs_exports") o := oraw.(*schema.Set) diff --git a/internal/service/rds/cluster_test.go b/internal/service/rds/cluster_test.go index ab6c427f671..5da28b83812 100644 --- a/internal/service/rds/cluster_test.go +++ b/internal/service/rds/cluster_test.go @@ -38,6 +38,7 @@ func testAccClusterImportStep(n string) resource.TestStep { "apply_immediately", "db_instance_parameter_group_name", "enable_global_write_forwarding", + "enable_local_write_forwarding", "manage_master_user_password", "master_password", "master_user_secret_kms_key_id", @@ -430,6 +431,7 @@ func TestAccRDSCluster_onlyMajorVersion(t *testing.T) { "cluster_identifier_prefix", "db_instance_parameter_group_name", "enable_global_write_forwarding", + "enable_local_write_forwarding", "engine_version", "master_password", "skip_final_snapshot", @@ -2676,6 +2678,31 @@ func testAccCheckClusterNotRecreated(i, j *rds.DBCluster) resource.TestCheckFunc } } +func TestAccRDSCluster_localWriteForwarding(t *testing.T) { + ctx := acctest.Context(t) + var dbCluster rds.DBCluster + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_rds_cluster.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckClusterDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccClusterConfig_localWriteForwarding(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckClusterExists(ctx, resourceName, &dbCluster), + acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "rds", fmt.Sprintf("cluster:%s", rName)), + resource.TestCheckResourceAttr(resourceName, "enable_local_write_forwarding", "true"), + ), + }, + testAccClusterImportStep(resourceName), + }, + }) +} + func testAccClusterConfig_basic(rName string) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { @@ -4812,3 +4839,18 @@ resource "aws_rds_cluster" "test" { } `, rName, preferredBackupWindow) } + +func testAccClusterConfig_localWriteForwarding(rName string) string { + return fmt.Sprintf(` +resource "aws_rds_cluster" "test" { + cluster_identifier = %[1]q + database_name = "test" + engine = "aurora-mysql" + engine_version = "8.0.mysql_aurora.3.04.0" + enable_local_write_forwarding = true + master_username = "tfacctest" + master_password = "avoid-plaintext-passwords" + skip_final_snapshot = true +} +`, rName) +} diff --git a/website/docs/r/rds_cluster.html.markdown b/website/docs/r/rds_cluster.html.markdown index 635aedea00c..76f3e09462c 100644 --- a/website/docs/r/rds_cluster.html.markdown +++ b/website/docs/r/rds_cluster.html.markdown @@ -243,8 +243,9 @@ This argument supports the following arguments: * `deletion_protection` - (Optional) If the DB cluster should have deletion protection enabled. The database can't be deleted when this value is set to `true`. The default is `false`. -* `enable_global_write_forwarding` - (Optional) Whether cluster should forward writes to an associated global cluster. Applied to secondary clusters to enable them to forward writes to an [`aws_rds_global_cluster`](/docs/providers/aws/r/rds_global_cluster.html)'s primary cluster. See the [Aurora Userguide documentation](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-write-forwarding.html) for more information. +* `enable_global_write_forwarding` - (Optional) Whether cluster should forward writes to an associated global cluster. Applied to secondary clusters to enable them to forward writes to an [`aws_rds_global_cluster`](/docs/providers/aws/r/rds_global_cluster.html)'s primary cluster. See the [User Guide for Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-write-forwarding.html) for more information. * `enable_http_endpoint` - (Optional) Enable HTTP endpoint (data API). Only valid when `engine_mode` is set to `serverless`. +* `enable_local_write_forwarding` - (Optional) Whether read replicas can forward write operations to the writer DB instance in the DB cluster. By default, write operations aren't allowed on reader DB instances.. See the [User Guide for Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-mysql-write-forwarding.html) for more information. **NOTE:** Local write forwarding requires Aurora MySQL version 3.04 or higher. * `enabled_cloudwatch_logs_exports` - (Optional) Set of log types to export to cloudwatch. If omitted, no logs will be exported. The following log types are supported: `audit`, `error`, `general`, `slowquery`, `postgresql` (PostgreSQL). * `engine_mode` - (Optional) Database engine mode. Valid values: `global` (only valid for Aurora MySQL 1.21 and earlier), `multimaster`, `parallelquery`, `provisioned`, `serverless`. Defaults to: `provisioned`. See the [RDS User Guide](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/aurora-serverless.html) for limitations when using `serverless`. * `engine_version` - (Optional) Database engine version. Updating this argument results in an outage. See the [Aurora MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Updates.html) and [Aurora Postgres](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Updates.html) documentation for your configured engine to determine this value, or by running `aws rds describe-db-engine-versions`. For example with Aurora MySQL 2, a potential value for this argument is `5.7.mysql_aurora.2.03.2`. The value can contain a partial version where supported by the API. The actual engine version used is returned in the attribute `engine_version_actual`, , see [Attribute Reference](#attribute-reference) below. From 97fe886c8a45fe6d9a262b3be3e835ba7aca503b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 20 Mar 2024 08:22:12 -0400 Subject: [PATCH 2/3] Update 34370.txt --- .changelog/34370.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changelog/34370.txt b/.changelog/34370.txt index 492d8f60887..58a5bb8630c 100644 --- a/.changelog/34370.txt +++ b/.changelog/34370.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_rds_cluster: Add the `enable_local_write_forwarding` argument to support Aurora MySQL local write forwarding -``` \ No newline at end of file +resource/aws_rds_cluster: Add `enable_local_write_forwarding` argument to support Aurora MySQL local write forwarding +``` From 9a6941d00655ee0b0fd42e6aa55d1754ede490d7 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 20 Mar 2024 08:35:59 -0400 Subject: [PATCH 3/3] Fix semgrep 'ci.semgrep.migrate.error-check-service-id'. --- internal/service/rds/cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/rds/cluster_test.go b/internal/service/rds/cluster_test.go index cb7575ba2ee..aa23a7c62d4 100644 --- a/internal/service/rds/cluster_test.go +++ b/internal/service/rds/cluster_test.go @@ -2718,7 +2718,7 @@ func TestAccRDSCluster_localWriteForwarding(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckClusterDestroy(ctx), Steps: []resource.TestStep{