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/aws_rds_cluster: Various enhancements, bug fixes #17111

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
19 changes: 19 additions & 0 deletions .changelog/17111.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```release-notes:bug
resource/aws_rds_cluster_instance: Remove force new resource on the `engine_version` parameter to allow upgrade without remove instances
```

```release-notes:enhancement
resource/aws_rds_cluster: Add `db_instance_parameter_group_name` attribute to allow major version upgrade using custom parameter groups
```

```release-note:enhancement
resource/rds_cluster_instance: Add `performance_insights_retention_period` attribute
```

```release-notes:bug
resource/aws_rds_cluster: Add possible pending states for cluster update
```

```release-note:enhancement
resource/aws_rds_cluster: Add `enable_global_write_forwarding` attribute
```
27 changes: 27 additions & 0 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func resourceAwsRDSCluster() *schema.Resource {
Computed: true,
},

"db_instance_parameter_group_name": {
Type: schema.TypeString,
Optional: true,
},

"deletion_protection": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -132,6 +137,12 @@ func resourceAwsRDSCluster() *schema.Resource {
Optional: true,
},

"enable_global_write_forwarding": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"reader_endpoint": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -863,6 +874,10 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
createOpts.GlobalClusterIdentifier = aws.String(attr.(string))
}

if attr, ok := d.GetOk("enable_global_write_forwarding"); ok {
createOpts.EnableGlobalWriteForwarding = aws.Bool(attr.(bool))
}

if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
createOpts.VpcSecurityGroupIds = expandStringSet(attr)
}
Expand Down Expand Up @@ -1153,6 +1168,11 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}

if d.HasChange("db_instance_parameter_group_name") {
req.DBInstanceParameterGroupName = aws.String(d.Get("db_instance_parameter_group_name").(string))
requestUpdate = true
}

if d.HasChange("master_password") {
req.MasterUserPassword = aws.String(d.Get("master_password").(string))
requestUpdate = true
Expand Down Expand Up @@ -1232,6 +1252,11 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}

if d.HasChange("enable_global_write_forwarding") {
req.EnableGlobalWriteForwarding = aws.Bool(d.Get("enable_global_write_forwarding").(bool))
requestUpdate = true
}

if requestUpdate {
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.ModifyDBCluster(req)
Expand Down Expand Up @@ -1470,7 +1495,9 @@ var resourceAwsRdsClusterDeletePendingStates = []string{

var resourceAwsRdsClusterUpdatePendingStates = []string{
"backing-up",
"configuring-iam-database-auth",
"modifying",
"renaming",
"resetting-master-credentials",
"upgrading",
}
Expand Down
20 changes: 18 additions & 2 deletions aws/resource_aws_rds_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
iamwaiter "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/iam/waiter"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/rds/finder"
Expand Down Expand Up @@ -106,7 +107,6 @@ func resourceAwsRDSClusterInstance() *schema.Resource {
"engine_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

Expand Down Expand Up @@ -210,6 +210,13 @@ func resourceAwsRDSClusterInstance() *schema.Resource {
ValidateFunc: validateArn,
},

"performance_insights_retention_period": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntInSlice([]int{7, 731}),
},

"copy_tags_to_snapshot": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -283,6 +290,10 @@ func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{
createOpts.PerformanceInsightsKMSKeyId = aws.String(attr.(string))
}

if attr, ok := d.GetOk("performance_insights_retention_period"); ok {
createOpts.PerformanceInsightsRetentionPeriod = aws.Int64(int64(attr.(int)))
}

if attr, ok := d.GetOk("preferred_backup_window"); ok {
createOpts.PreferredBackupWindow = aws.String(attr.(string))
}
Expand Down Expand Up @@ -459,6 +470,7 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{})
d.Set("monitoring_role_arn", db.MonitoringRoleArn)
d.Set("performance_insights_enabled", db.PerformanceInsightsEnabled)
d.Set("performance_insights_kms_key_id", db.PerformanceInsightsKMSKeyId)
d.Set("performance_insights_retention_period", db.PerformanceInsightsRetentionPeriod)
d.Set("preferred_backup_window", db.PreferredBackupWindow)
d.Set("preferred_maintenance_window", db.PreferredMaintenanceWindow)
d.Set("promotion_tier", db.PromotionTier)
Expand Down Expand Up @@ -514,13 +526,17 @@ func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{
requestUpdate = true
}

if d.HasChanges("performance_insights_enabled", "performance_insights_kms_key_id") {
if d.HasChanges("performance_insights_enabled", "performance_insights_kms_key_id", "performance_insights_retention_period") {
req.EnablePerformanceInsights = aws.Bool(d.Get("performance_insights_enabled").(bool))

if v, ok := d.GetOk("performance_insights_kms_key_id"); ok {
req.PerformanceInsightsKMSKeyId = aws.String(v.(string))
}

if v, ok := d.GetOk("performance_insights_retention_period"); ok {
req.PerformanceInsightsRetentionPeriod = aws.Int64(int64(v.(int)))
}

requestUpdate = true
}

Expand Down
69 changes: 69 additions & 0 deletions aws/resource_aws_rds_cluster_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,46 @@ func TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraMysql2_Defau
})
}

func TestAccAWSRDSClusterInstance_PerformanceInsightsRetentionPeriod(t *testing.T) {
var dbInstance rds.DBInstance
resourceName := "aws_rds_cluster_instance.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccRDSPerformanceInsightsDefaultVersionPreCheck(t, "aurora") },
ErrorCheck: testAccErrorCheck(t, rds.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterInstanceConfigPerformanceInsightsRetentionPeriod(rName, 731),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "performance_insights_retention_period", "731"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"identifier_prefix",
},
},
{
Config: testAccAWSClusterInstanceConfigPerformanceInsightsRetentionPeriod(rName, 7),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "performance_insights_retention_period", "7"),
),
},
},
})
}

func TestAccAWSRDSClusterInstance_PerformanceInsightsKmsKeyId_AuroraPostgresql(t *testing.T) {
var dbInstance rds.DBInstance
kmsKeyResourceName := "aws_kms_key.test"
Expand Down Expand Up @@ -1596,6 +1636,35 @@ resource "aws_rds_cluster_instance" "test" {
`, rName, engine)
}

func testAccAWSClusterInstanceConfigPerformanceInsightsRetentionPeriod(rName string, performanceInsightsRetentionPeriod int) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "test" {
cluster_identifier = %[1]q
database_name = "mydb"
engine = "aurora"
master_password = "mustbeeightcharacters"
master_username = "foo"
skip_final_snapshot = true
}

data "aws_rds_orderable_db_instance" "test" {
engine = aws_rds_cluster.test.engine
engine_version = aws_rds_cluster.test.engine_version
supports_performance_insights = true
preferred_instance_classes = ["db.t3.medium", "db.r5.large", "db.r4.large"]
}

resource "aws_rds_cluster_instance" "test" {
cluster_identifier = aws_rds_cluster.test.id
engine = aws_rds_cluster.test.engine
identifier = %[1]q
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
performance_insights_enabled = true
performance_insights_retention_period = %[2]d
}
`, rName, performanceInsightsRetentionPeriod)
}

func testAccAWSRDSClusterInstanceConfig_PubliclyAccessible(rName string, publiclyAccessible bool) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "test" {
Expand Down
Loading