Skip to content

Commit

Permalink
feat: Add enable_local_write_forwarding arg to aws_rds_cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
acwwat committed Nov 13, 2023
1 parent 1afa91e commit f48b177
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .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
```
23 changes: 18 additions & 5 deletions internal/service/rds/cluster.go
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions internal/service/rds/cluster_test.go
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion website/docs/r/rds_cluster.html.markdown
Expand Up @@ -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.
Expand Down

0 comments on commit f48b177

Please sign in to comment.