Skip to content

Commit

Permalink
feat: Add scaling_configuration.seconds_before_timeout arg for aws_db…
Browse files Browse the repository at this point in the history
…_cluster
  • Loading branch information
acwwat committed Jul 21, 2024
1 parent cc6a0f5 commit ae33369
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/38451.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_db_cluster: Add `scaling_configuration.seconds_before_timeout` argument
```
6 changes: 6 additions & 0 deletions internal/service/rds/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,12 @@ func ResourceCluster() *schema.Resource {
Optional: true,
Default: clusterScalingConfiguration_DefaultMinCapacity,
},
"seconds_before_timeout": {
Type: schema.TypeInt,
Optional: true,
Default: 300,
ValidateFunc: validation.IntBetween(60, 600),
},
"seconds_until_auto_pause": {
Type: schema.TypeInt,
Optional: true,
Expand Down
15 changes: 9 additions & 6 deletions internal/service/rds/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1841,25 +1841,27 @@ func TestAccRDSCluster_scaling(t *testing.T) {
CheckDestroy: testAccCheckClusterDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccClusterConfig_scalingConfiguration(rName, false, 128, 4, 301, "RollbackCapacityChange"),
Config: testAccClusterConfig_scalingConfiguration(rName, false, 128, 4, 301, 301, "RollbackCapacityChange"),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.auto_pause", acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.max_capacity", "128"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.min_capacity", acctest.Ct4),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.seconds_before_timeout", "301"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.seconds_until_auto_pause", "301"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.timeout_action", "RollbackCapacityChange"),
),
},
{
Config: testAccClusterConfig_scalingConfiguration(rName, true, 256, 8, 86400, "ForceApplyCapacityChange"),
Config: testAccClusterConfig_scalingConfiguration(rName, true, 256, 8, 600, 86400, "ForceApplyCapacityChange"),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.auto_pause", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.max_capacity", "256"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.min_capacity", "8"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.seconds_before_timeout", "600"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.seconds_until_auto_pause", "86400"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.timeout_action", "ForceApplyCapacityChange"),
),
Expand Down Expand Up @@ -4582,7 +4584,7 @@ resource "aws_rds_cluster_instance" "secondary" {
`, tfrds.ClusterEngineAuroraPostgreSQL, mainInstanceClasses, rName))
}

func testAccClusterConfig_scalingConfiguration(rName string, autoPause bool, maxCapacity, minCapacity, secondsUntilAutoPause int, timeoutAction string) string {
func testAccClusterConfig_scalingConfiguration(rName string, autoPause bool, maxCapacity, minCapacity, secondsBeforeTimeout, secondsUntilAutoPause int, timeoutAction string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "test" {
cluster_identifier = %[1]q
Expand All @@ -4596,11 +4598,12 @@ resource "aws_rds_cluster" "test" {
auto_pause = %[3]t
max_capacity = %[4]d
min_capacity = %[5]d
seconds_until_auto_pause = %[6]d
timeout_action = %[7]q
seconds_before_timeout = %[6]d
seconds_until_auto_pause = %[7]d
timeout_action = %[8]q
}
}
`, rName, tfrds.ClusterEngineAuroraMySQL, autoPause, maxCapacity, minCapacity, secondsUntilAutoPause, timeoutAction)
`, rName, tfrds.ClusterEngineAuroraMySQL, autoPause, maxCapacity, minCapacity, secondsBeforeTimeout, secondsUntilAutoPause, timeoutAction)
}

func testAccClusterConfig_serverlessV2ScalingConfiguration(rName string, maxCapacity, minCapacity float64) string {
Expand Down
8 changes: 8 additions & 0 deletions internal/service/rds/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func expandScalingConfiguration(tfMap map[string]interface{}) *rds.ScalingConfig
apiObject.MinCapacity = aws.Int64(int64(v))
}

if v, ok := tfMap["seconds_before_timeout"].(int); ok {
apiObject.SecondsBeforeTimeout = aws.Int64(int64(v))
}

if v, ok := tfMap["seconds_until_auto_pause"].(int); ok {
apiObject.SecondsUntilAutoPause = aws.Int64(int64(v))
}
Expand Down Expand Up @@ -85,6 +89,10 @@ func flattenScalingConfigurationInfo(apiObject *rds.ScalingConfigurationInfo) ma
tfMap["min_capacity"] = aws.Int64Value(v)
}

if v := apiObject.SecondsBeforeTimeout; v != nil {
tfMap["seconds_before_timeout"] = aws.Int64Value(v)
}

if v := apiObject.SecondsUntilAutoPause; v != nil {
tfMap["seconds_until_auto_pause"] = aws.Int64Value(v)
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/rds_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ resource "aws_rds_cluster" "example" {
auto_pause = true
max_capacity = 256
min_capacity = 2
seconds_before_timeout = 360
seconds_until_auto_pause = 300
timeout_action = "ForceApplyCapacityChange"
}
Expand All @@ -338,6 +339,7 @@ resource "aws_rds_cluster" "example" {
* `auto_pause` - (Optional) Whether to enable automatic pause. A DB cluster can be paused only when it's idle (it has no connections). If a DB cluster is paused for more than seven days, the DB cluster might be backed up with a snapshot. In this case, the DB cluster is restored when there is a request to connect to it. Defaults to `true`.
* `max_capacity` - (Optional) Maximum capacity for an Aurora DB cluster in `serverless` DB engine mode. The maximum capacity must be greater than or equal to the minimum capacity. Valid Aurora MySQL capacity values are `1`, `2`, `4`, `8`, `16`, `32`, `64`, `128`, `256`. Valid Aurora PostgreSQL capacity values are (`2`, `4`, `8`, `16`, `32`, `64`, `192`, and `384`). Defaults to `16`.
* `min_capacity` - (Optional) Minimum capacity for an Aurora DB cluster in `serverless` DB engine mode. The minimum capacity must be lesser than or equal to the maximum capacity. Valid Aurora MySQL capacity values are `1`, `2`, `4`, `8`, `16`, `32`, `64`, `128`, `256`. Valid Aurora PostgreSQL capacity values are (`2`, `4`, `8`, `16`, `32`, `64`, `192`, and `384`). Defaults to `1`.
* `seconds_before_timeout` - (Optional) Amount of time, in seconds, that Aurora Serverless v1 tries to find a scaling point to perform seamless scaling before enforcing the timeout action. Valid values are `60` through `600`. Defaults to `300`.
* `seconds_until_auto_pause` - (Optional) Time, in seconds, before an Aurora DB cluster in serverless mode is paused. Valid values are `300` through `86400`. Defaults to `300`.
* `timeout_action` - (Optional) Action to take when the timeout is reached. Valid values: `ForceApplyCapacityChange`, `RollbackCapacityChange`. Defaults to `RollbackCapacityChange`. See [documentation](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless-v1.how-it-works.html#aurora-serverless.how-it-works.timeout-action).

Expand Down

0 comments on commit ae33369

Please sign in to comment.