-
Notifications
You must be signed in to change notification settings - Fork 9k
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
[WIP] Adding support for cluster engine upgrade #5010
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,7 @@ func resourceAwsRDSCluster() *schema.Resource { | |
"engine_version": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ForceNew: false, | ||
Computed: true, | ||
}, | ||
|
||
|
@@ -163,7 +163,7 @@ func resourceAwsRDSCluster() *schema.Resource { | |
"source_engine_version": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ForceNew: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This attribute does not relate to the changes in this pull request -- will revert on merge. |
||
}, | ||
}, | ||
}, | ||
|
@@ -901,6 +901,11 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error | |
requestUpdate = true | ||
} | ||
|
||
if d.HasChange("engine_version") { | ||
req.EngineVersion = aws.String(d.Get("engine_version").(string)) | ||
requestUpdate = true | ||
} | ||
|
||
if d.HasChange("vpc_security_group_ids") { | ||
if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 { | ||
req.VpcSecurityGroupIds = expandStringList(attr.List()) | ||
|
@@ -949,6 +954,11 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error | |
if isAWSErr(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") { | ||
return resource.RetryableError(err) | ||
} | ||
|
||
if isAWSErr(err, rds.ErrCodeInvalidDBClusterStateFault, "Cannot modify engine version without a primary instance in DB cluster") { | ||
return resource.NonRetryableError(err) | ||
} | ||
|
||
if isAWSErr(err, rds.ErrCodeInvalidDBClusterStateFault, "") { | ||
return resource.RetryableError(err) | ||
} | ||
|
@@ -1162,4 +1172,5 @@ var resourceAwsRdsClusterUpdatePendingStates = []string{ | |
"backing-up", | ||
"modifying", | ||
"resetting-master-credentials", | ||
"upgrading", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ func resourceAwsRDSClusterInstance() *schema.Resource { | |
"engine_version": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ForceNew: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this change was necessary to get the test configuration ( The challenge here is that the resource itself cannot be configured to support updates of the func TestAccAWSRDSClusterInstance_EngineVersion(t *testing.T) {
var dbInstance rds.DBInstance
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_rds_cluster_instance.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRDSClusterInstanceConfig_EngineVersion(rName, "9.6.3"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.3"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately"},
},
{
Config: testAccAWSRDSClusterInstanceConfig_EngineVersion(rName, "9.6.6"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.6"),
),
},
},
})
}
func testAccAWSRDSClusterInstanceConfig_EngineVersion(rName, engineVersion string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "test" {
cluster_identifier = %q
engine = "aurora-postgresql"
engine_version = "9.6.3"
master_username = "foo"
master_password = "mustbeeightcharaters"
skip_final_snapshot = true
lifecycle {
ignore_changes = ["engine_version"]
}
}
resource "aws_rds_cluster_instance" "test" {
apply_immediately = true
cluster_identifier = "${aws_rds_cluster.test.id}"
engine = "${aws_rds_cluster.test.engine}"
engine_version = %q
identifier = %q
instance_class = "db.r4.large"
}
`, rName, engineVersion, rName)
} In this setup without code changes to this pull request, it will create a perpetual difference of trying to perform
If we add the following code within the Update function of resource: func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
// ...
if d.HasChange("engine_version") {
req.EngineVersion = aws.String(d.Get("engine_version").(string))
requestUpdate = true
} We then receive an error attempting the update:
To verify that the func TestAccAWSRDSClusterInstance_EngineVersion(t *testing.T) {
var dbInstance rds.DBInstance
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_rds_cluster_instance.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRDSClusterInstanceConfig_EngineVersion(rName, "9.6.6"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.6"),
),
},
},
})
} This also returns an error:
I will agree that I think we should perform deprecation for configuring both |
||
Computed: true, | ||
}, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -420,7 +420,41 @@ func TestAccAWSRDSCluster_EngineVersion(t *testing.T) { | |
CheckDestroy: testAccCheckAWSClusterDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSClusterConfig_EngineVersion(rInt, "aurora-postgresql", "9.6.6"), | ||
Config: testAccAWSClusterConfig_EngineVersion(rInt, "aurora-postgresql", "9.6.3"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSClusterExists(resourceName, &dbCluster), | ||
resource.TestCheckResourceAttr(resourceName, "engine", "aurora-postgresql"), | ||
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.3"), | ||
), | ||
}, | ||
{ | ||
Config: testAccAWSClusterConfig_EngineVersion(rInt, "aurora-postgresql", "9.6.6"), | ||
ExpectError: regexp.MustCompile(`Cannot modify engine version without a primary instance in DB cluster`), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSRDSCluster_EngineVersionWithPrimaryInstance(t *testing.T) { | ||
var dbCluster rds.DBCluster | ||
rInt := acctest.RandInt() | ||
resourceName := "aws_rds_cluster.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSClusterDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt, "aurora-postgresql", "9.6.3"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSClusterExists(resourceName, &dbCluster), | ||
resource.TestCheckResourceAttr(resourceName, "engine", "aurora-postgresql"), | ||
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.3"), | ||
), | ||
}, | ||
{ | ||
Config: testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt, "aurora-postgresql", "9.6.6"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSClusterExists(resourceName, &dbCluster), | ||
resource.TestCheckResourceAttr(resourceName, "engine", "aurora-postgresql"), | ||
|
@@ -995,8 +1029,48 @@ resource "aws_rds_cluster" "test" { | |
engine = "%s" | ||
engine_version = "%s" | ||
master_password = "mustbeeightcharaters" | ||
master_username = "foo" | ||
skip_final_snapshot = true | ||
apply_immediately = true | ||
}`, rInt, engine, engineVersion) | ||
} | ||
|
||
func testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt int, engine, engineVersion string) string { | ||
return fmt.Sprintf(` | ||
|
||
data "aws_availability_zones" "available" {} | ||
|
||
variable "cluster_identifier" { | ||
default = "tf-acc-test-%d" | ||
} | ||
|
||
variable "engine" { | ||
default = "%s" | ||
} | ||
|
||
variable "engine_version" { | ||
default = "%s" | ||
} | ||
|
||
resource "aws_rds_cluster" "test" { | ||
availability_zones = ["${data.aws_availability_zones.available.names}"] | ||
cluster_identifier = "${var.cluster_identifier}" | ||
database_name = "mydb" | ||
db_cluster_parameter_group_name = "default.aurora-postgresql9.6" | ||
engine = "${var.engine}" | ||
engine_version = "${var.engine_version}" | ||
master_password = "mustbeeightcharaters" | ||
master_username = "foo" | ||
skip_final_snapshot = true | ||
apply_immediately = true | ||
} | ||
|
||
resource "aws_rds_cluster_instance" "test" { | ||
identifier = "${var.cluster_identifier}" | ||
cluster_identifier = "${aws_rds_cluster.test.cluster_identifier}" | ||
engine = "${var.engine}" | ||
engine_version = "${var.engine_version}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As noted above, configuring |
||
instance_class = "db.r4.large" | ||
}`, rInt, engine, engineVersion) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:
ForceNew: false
is the default and can be omitted from the schema