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/rds_cluster: update default value for min_capacity in scaling_configuration block #14268

Merged
merged 1 commit into from
Jul 21, 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
10 changes: 5 additions & 5 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const (
rdsClusterScalingConfiguration_DefaultMinCapacity = 2
rdsClusterScalingConfiguration_DefaultMinCapacity = 1
rdsClusterScalingConfiguration_DefaultMaxCapacity = 16
)

Expand Down Expand Up @@ -452,7 +452,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)),
Engine: aws.String(d.Get("engine").(string)),
EngineMode: aws.String(d.Get("engine_mode").(string)),
ScalingConfiguration: expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{}), d.Get("engine_mode").(string)),
ScalingConfiguration: expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{})),
SnapshotIdentifier: aws.String(d.Get("snapshot_identifier").(string)),
Tags: tags,
}
Expand Down Expand Up @@ -548,7 +548,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
Engine: aws.String(d.Get("engine").(string)),
EngineMode: aws.String(d.Get("engine_mode").(string)),
ReplicationSourceIdentifier: aws.String(d.Get("replication_source_identifier").(string)),
ScalingConfiguration: expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{}), d.Get("engine_mode").(string)),
ScalingConfiguration: expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{})),
Tags: tags,
}

Expand Down Expand Up @@ -767,7 +767,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
DeletionProtection: aws.Bool(d.Get("deletion_protection").(bool)),
Engine: aws.String(d.Get("engine").(string)),
EngineMode: aws.String(d.Get("engine_mode").(string)),
ScalingConfiguration: expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{}), d.Get("engine_mode").(string)),
ScalingConfiguration: expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{})),
Tags: tags,
}

Expand Down Expand Up @@ -1140,7 +1140,7 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
}

if d.HasChange("scaling_configuration") {
req.ScalingConfiguration = expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{}), d.Get("engine_mode").(string))
req.ScalingConfiguration = expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{}))
requestUpdate = true
}

Expand Down
59 changes: 59 additions & 0 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,46 @@ func TestAccAWSRDSCluster_ScalingConfiguration(t *testing.T) {
})
}

// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/11698
func TestAccAWSRDSCluster_ScalingConfiguration_DefaultMinCapacity(t *testing.T) {
var dbCluster rds.DBCluster

rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_rds_cluster.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRDSClusterConfig_ScalingConfiguration_DefaultMinCapacity(rName, false, 128, 301, "RollbackCapacityChange"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.auto_pause", "false"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.max_capacity", "128"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.min_capacity", "1"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.seconds_until_auto_pause", "301"),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.timeout_action", "RollbackCapacityChange"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"cluster_identifier_prefix",
"master_password",
"skip_final_snapshot",
"snapshot_identifier",
},
},
},
})
}

func TestAccAWSRDSCluster_SnapshotIdentifier(t *testing.T) {
var dbCluster, sourceDbCluster rds.DBCluster
var dbClusterSnapshot rds.DBClusterSnapshot
Expand Down Expand Up @@ -3120,6 +3160,25 @@ resource "aws_rds_cluster" "test" {
`, rName, autoPause, maxCapacity, minCapacity, secondsUntilAutoPause, timeoutAction)
}

func testAccAWSRDSClusterConfig_ScalingConfiguration_DefaultMinCapacity(rName string, autoPause bool, maxCapacity, secondsUntilAutoPause int, timeoutAction string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "test" {
cluster_identifier = %q
engine_mode = "serverless"
master_password = "barbarbarbar"
master_username = "foo"
skip_final_snapshot = true

scaling_configuration {
auto_pause = %t
max_capacity = %d
seconds_until_auto_pause = %d
timeout_action = "%s"
}
}
`, rName, autoPause, maxCapacity, secondsUntilAutoPause, timeoutAction)
}

func testAccAWSRDSClusterConfig_SnapshotIdentifier(rName string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "source" {
Expand Down
12 changes: 2 additions & 10 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -4532,17 +4532,9 @@ func flattenDaxEncryptAtRestOptions(options *dax.SSEDescription) []map[string]in
return []map[string]interface{}{m}
}

func expandRdsClusterScalingConfiguration(l []interface{}, engineMode string) *rds.ScalingConfiguration {
func expandRdsClusterScalingConfiguration(l []interface{}) *rds.ScalingConfiguration {
if len(l) == 0 || l[0] == nil {
// Our default value for MinCapacity is different from AWS's.
// We need to override it here to avoid a non-empty plan with an empty ScalingConfiguration.
if engineMode == "serverless" {
return &rds.ScalingConfiguration{
MinCapacity: aws.Int64(int64(rdsClusterScalingConfiguration_DefaultMinCapacity)),
}
} else {
return nil
}
return nil
}

m := l[0].(map[string]interface{})
Expand Down
59 changes: 6 additions & 53 deletions aws/structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1611,57 +1611,10 @@ const testExampleXML_from_msdn_flawed = `
</purchaseOrder>
`

func TestExpandRdsClusterScalingConfiguration_serverless(t *testing.T) {
type testCase struct {
EngineMode string
Input []interface{}
Expected *rds.ScalingConfiguration
}
cases := []testCase{
{
EngineMode: "serverless",
Input: []interface{}{
map[string]interface{}{
"auto_pause": false,
"max_capacity": 32,
"min_capacity": 4,
"seconds_until_auto_pause": 600,
"timeout_action": "ForceApplyCapacityChange",
},
},
Expected: &rds.ScalingConfiguration{
AutoPause: aws.Bool(false),
MaxCapacity: aws.Int64(32),
MinCapacity: aws.Int64(4),
SecondsUntilAutoPause: aws.Int64(600),
TimeoutAction: aws.String("ForceApplyCapacityChange"),
},
},
{
EngineMode: "serverless",
Input: []interface{}{},
Expected: &rds.ScalingConfiguration{
MinCapacity: aws.Int64(2),
},
},
{
EngineMode: "serverless",
Input: []interface{}{
nil,
},
Expected: &rds.ScalingConfiguration{
MinCapacity: aws.Int64(2),
},
},
}

for _, tc := range cases {
output := expandRdsClusterScalingConfiguration(tc.Input, tc.EngineMode)
if !reflect.DeepEqual(output, tc.Expected) {
t.Errorf("EngineMode: %s\nExpected: %v,\nGot: %v", tc.EngineMode, tc.Expected, output)
}
}
}
// TestExpandRdsClusterScalingConfiguration_serverless removed in v3.0.0
// as all engine_modes are treated equal when expanding scaling_configuration
// and an override of min_capacity is no longer needed
// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/11698

func TestExpandRdsClusterScalingConfiguration_basic(t *testing.T) {
type testCase struct {
Expand All @@ -1673,7 +1626,7 @@ func TestExpandRdsClusterScalingConfiguration_basic(t *testing.T) {

// RDS Cluster Scaling Configuration is only valid for serverless, but we're relying on AWS errors.
// If Terraform adds whole-resource validation, we can do our own validation at plan time.
for _, engineMode := range []string{"global", "multimaster", "parallelquery", "provisioned"} {
for _, engineMode := range []string{"global", "multimaster", "parallelquery", "provisioned", "serverless"} {
cases = append(cases, []testCase{
{
EngineMode: engineMode,
Expand Down Expand Up @@ -1703,7 +1656,7 @@ func TestExpandRdsClusterScalingConfiguration_basic(t *testing.T) {
}

for _, tc := range cases {
output := expandRdsClusterScalingConfiguration(tc.Input, tc.EngineMode)
output := expandRdsClusterScalingConfiguration(tc.Input)
if tc.ExpectNil != (output == nil) {
t.Errorf("EngineMode %q: Expected nil: %t, Got: %v", tc.EngineMode, tc.ExpectNil, output)
}
Expand Down
7 changes: 7 additions & 0 deletions website/docs/guides/version-3-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Upgrade topics:
- [Resource: aws_launch_template](#resource-aws_launch_template)
- [Resource: aws_lb_listener_rule](#resource-aws_lb_listener_rule)
- [Resource: aws_msk_cluster](#resource-aws_msk_cluster)
- [Resource: aws_rds_cluster](#resource-aws_rds_cluster)
- [Resource: aws_s3_bucket](#resource-aws_s3_bucket)
- [Resource: aws_security_group](#resource-aws_security_group)
- [Resource: aws_sns_platform_application](#resource-aws_sns_platform_application)
Expand Down Expand Up @@ -475,6 +476,12 @@ resource "aws_msk_cluster" "example" {
}
```

## Resource: aws_rds_cluster

### scaling_configuration.min_capacity Now Defaults to 1

Previously when the `min_capacity` argument in a `scaling_configuration` block was not configured, the resource would default to 2. This behavior has been updated to align with the AWS RDS Cluster API default of 1.

## Resource: aws_s3_bucket

### Removal of Automatic aws_s3_bucket_policy Import
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/rds_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,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) The maximum capacity. The maximum capacity must be greater than or equal to the minimum capacity. Valid capacity values are `1`, `2`, `4`, `8`, `16`, `32`, `64`, `128`, and `256`. Defaults to `16`.
* `min_capacity` - (Optional) The minimum capacity. The minimum capacity must be lesser than or equal to the maximum capacity. Valid capacity values are `1`, `2`, `4`, `8`, `16`, `32`, `64`, `128`, and `256`. Defaults to `2`.
* `min_capacity` - (Optional) The minimum capacity. The minimum capacity must be lesser than or equal to the maximum capacity. Valid capacity values are `1`, `2`, `4`, `8`, `16`, `32`, `64`, `128`, and `256`. Defaults to `1`.
* `seconds_until_auto_pause` - (Optional) The 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) The 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.how-it-works.html#aurora-serverless.how-it-works.timeout-action).

Expand Down