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

add ca_cert_identifier to rds instance #10490

Merged
merged 2 commits into from
Nov 15, 2019
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
25 changes: 19 additions & 6 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func resourceAwsDbInstance() *schema.Resource {
DiffSuppressFunc: suppressAwsDbEngineVersionDiffs,
},

"ca_cert_identifier": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"character_set_name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -422,11 +428,6 @@ func resourceAwsDbInstance() *schema.Resource {
Computed: true,
},

"ca_cert_identifier": {
Type: schema.TypeString,
Computed: true,
},

"enabled_cloudwatch_logs_exports": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1043,6 +1044,7 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
if _, ok := d.GetOk("username"); !ok {
return fmt.Errorf(`provider.aws: aws_db_instance: %s: "username": required field is not set`, d.Get("name").(string))
}

opts := rds.CreateDBInstanceInput{
AllocatedStorage: aws.Int64(int64(d.Get("allocated_storage").(int))),
DBName: aws.String(d.Get("name").(string)),
Expand Down Expand Up @@ -1176,8 +1178,9 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error

log.Printf("[DEBUG] DB Instance create configuration: %#v", opts)
var err error
var createdDBInstanceOutput *rds.CreateDBInstanceOutput
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err = conn.CreateDBInstance(&opts)
createdDBInstanceOutput, err = conn.CreateDBInstance(&opts)
if err != nil {
if isAWSErr(err, "InvalidParameterValue", "ENHANCED_MONITORING") {
return resource.RetryableError(err)
Expand All @@ -1196,6 +1199,11 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
}
return fmt.Errorf("Error creating DB Instance: %s", err)
}
// This is added here to avoid unnecessary modification when ca_cert_identifier is the default one
if attr, ok := d.GetOk("ca_cert_identifier"); ok && attr.(string) != aws.StringValue(createdDBInstanceOutput.DBInstance.CACertificateIdentifier) {
modifyDbInstanceInput.CACertificateIdentifier = aws.String(attr.(string))
requiresModifyDbInstance = true
}
}

d.SetId(d.Get("identifier").(string))
Expand Down Expand Up @@ -1484,6 +1492,11 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
req.CopyTagsToSnapshot = aws.Bool(d.Get("copy_tags_to_snapshot").(bool))
requestUpdate = true
}
if d.HasChange("ca_cert_identifier") {
d.SetPartial("ca_cert_identifier")
req.CACertificateIdentifier = aws.String(d.Get("ca_cert_identifier").(string))
requestUpdate = true
}
if d.HasChange("deletion_protection") {
d.SetPartial("deletion_protection")
req.DeletionProtection = aws.Bool(d.Get("deletion_protection").(bool))
Expand Down
45 changes: 45 additions & 0 deletions aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2583,6 +2583,35 @@ func TestAccAWSDBInstance_SnapshotIdentifier_PerformanceInsightsEnabled(t *testi
})
}

func TestAccAWSDBInstance_CACertificateIdentifier(t *testing.T) {
var dbInstance rds.DBInstance

resourceName := "aws_db_instance.bar"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccAWSDBInstanceConfigWithCACertificateIdentifier, "rds-ca-2015"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "ca_cert_identifier", "rds-ca-2015"),
),
},
// Ensure we are able to modify the CACertIdentifier
{
Config: fmt.Sprintf(testAccAWSDBInstanceConfigWithCACertificateIdentifier, "rds-ca-2019"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "ca_cert_identifier", "rds-ca-2019"),
),
},
},
})
}

// Database names cannot collide, and deletion takes so long, that making the
// name a bit random helps so able we can kill a test that's just waiting for a
// delete and not be blocked on kicking off another one.
Expand Down Expand Up @@ -2690,6 +2719,22 @@ resource "aws_db_instance" "bar" {
}
`

const testAccAWSDBInstanceConfigWithCACertificateIdentifier = `
resource "aws_db_instance" "bar" {
allocated_storage = 10
engine = "MySQL"
instance_class = "db.t2.micro"
name = "baz"
password = "barbarbarbar"
username = "foo"
ca_cert_identifier = "%s"
apply_immediately = true
skip_final_snapshot = true
timeouts {
create = "30m"
}
}`

func testAccAWSDBInstanceConfigWithOptionGroup(rName string) string {
return fmt.Sprintf(`
resource "aws_db_option_group" "bar" {
Expand Down
Loading