-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Performance Insights configuration for aws_db_instance #6453
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,6 +424,25 @@ func resourceAwsDbInstance() *schema.Resource { | |
Optional: true, | ||
}, | ||
|
||
"performance_insights_enabled": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
}, | ||
|
||
"performance_insights_kms_key_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
bflad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ValidateFunc: validateArn, | ||
}, | ||
|
||
"performance_insights_retention_period": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
bflad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
|
||
"tags": tagsSchema(), | ||
}, | ||
} | ||
|
@@ -573,6 +592,18 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error | |
requiresModifyDbInstance = true | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_enabled"); ok { | ||
opts.EnablePerformanceInsights = aws.Bool(attr.(bool)) | ||
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 should have an acceptance test added to ensure its functionality and prevent regressions, e.g. something similar to: func TestAccAWSDBInstance_ReplicateSourceDb_PerformanceInsightsEnabled(t *testing.T) {
var dbInstance, sourceDbInstance rds.DBInstance
rName := acctest.RandomWithPrefix("tf-acc-test")
kmsKeyResourceName := "aws_kms_key.test"
sourceResourceName := "aws_db_instance.source"
resourceName := "aws_db_instance.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDBInstanceConfig_ReplicateSourceDb_PerformanceInsightsEnabled(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists(sourceResourceName, &sourceDbInstance),
testAccCheckAWSDBInstanceExists(resourceName, &dbInstance),
testAccCheckAWSDBInstanceReplicaAttributes(&sourceDbInstance, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "performance_insights_enabled", "true"),
resource.TestCheckResourceAttrPair(resourceName, "performance_insights_kms_key_id", kmsKeyResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "performance_insights_retention_period", "7"),
),
},
},
})
}
func testAccAWSDBInstanceConfig_ReplicateSourceDb_PerformanceInsightsEnabled(rName string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "test" {
description = "Terraform acc test"
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "kms-tf-1",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "kms:*",
"Resource": "*"
}
]
}
POLICY
}
resource "aws_db_instance" "source" {
allocated_storage = 5
backup_retention_period = 1
engine = "mysql"
engine_version = "5.6.41"
identifier = "%s-source"
instance_class = "db.m3.medium"
password = "avoid-plaintext-passwords"
username = "tfacctest"
skip_final_snapshot = true
}
resource "aws_db_instance" "test" {
identifier = %q
instance_class = "${aws_db_instance.source.instance_class}"
performance_insights_enabled = true
performance_insights_kms_key_id = "${aws_kms_key.test.arn}"
performance_insights_retention_period = 7
replicate_source_db = "${aws_db_instance.source.id}"
skip_final_snapshot = true
}
`, rName, rName)
} |
||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_kms_key_id"); ok { | ||
opts.PerformanceInsightsKMSKeyId = aws.String(attr.(string)) | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_retention_period"); ok { | ||
opts.PerformanceInsightsRetentionPeriod = aws.Int64(int64(attr.(int))) | ||
} | ||
|
||
log.Printf("[DEBUG] DB Instance Replica create configuration: %#v", opts) | ||
_, err := conn.CreateDBInstanceReadReplica(&opts) | ||
if err != nil { | ||
|
@@ -701,6 +732,18 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error | |
opts.EnableIAMDatabaseAuthentication = aws.Bool(attr.(bool)) | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_enabled"); ok { | ||
opts.EnablePerformanceInsights = aws.Bool(attr.(bool)) | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_kms_key_id"); ok { | ||
opts.PerformanceInsightsKMSKeyId = aws.String(attr.(string)) | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_retention_period"); ok { | ||
opts.PerformanceInsightsRetentionPeriod = aws.Int64(int64(attr.(int))) | ||
} | ||
|
||
log.Printf("[DEBUG] DB Instance S3 Restore configuration: %#v", opts) | ||
var err error | ||
// Retry for IAM eventual consistency | ||
|
@@ -897,6 +940,19 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error | |
requiresModifyDbInstance = true | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_enabled"); ok { | ||
modifyDbInstanceInput.EnablePerformanceInsights = aws.Bool(attr.(bool)) | ||
requiresModifyDbInstance = true | ||
|
||
if attr, ok := d.GetOk("performance_insights_kms_key_id"); ok { | ||
modifyDbInstanceInput.PerformanceInsightsKMSKeyId = aws.String(attr.(string)) | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_retention_period"); ok { | ||
modifyDbInstanceInput.PerformanceInsightsRetentionPeriod = aws.Int64(int64(attr.(int))) | ||
} | ||
} | ||
|
||
log.Printf("[DEBUG] DB Instance restore from snapshot configuration: %s", opts) | ||
_, err := conn.RestoreDBInstanceFromDBSnapshot(&opts) | ||
|
||
|
@@ -1045,6 +1101,18 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error | |
opts.DomainIAMRoleName = aws.String(attr.(string)) | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_enabled"); ok { | ||
opts.EnablePerformanceInsights = aws.Bool(attr.(bool)) | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_kms_key_id"); ok { | ||
opts.PerformanceInsightsKMSKeyId = aws.String(attr.(string)) | ||
} | ||
|
||
if attr, ok := d.GetOk("performance_insights_retention_period"); ok { | ||
opts.PerformanceInsightsRetentionPeriod = aws.Int64(int64(attr.(int))) | ||
} | ||
|
||
log.Printf("[DEBUG] DB Instance create configuration: %#v", opts) | ||
var err error | ||
err = resource.Retry(5*time.Minute, func() *resource.RetryError { | ||
|
@@ -1154,6 +1222,9 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error { | |
d.Set("kms_key_id", v.KmsKeyId) | ||
d.Set("port", v.DbInstancePort) | ||
d.Set("iam_database_authentication_enabled", v.IAMDatabaseAuthenticationEnabled) | ||
d.Set("performance_insights_enabled", v.PerformanceInsightsEnabled) | ||
d.Set("performance_insights_kms_key_id", v.PerformanceInsightsKMSKeyId) | ||
d.Set("performance_insights_retention_period", v.PerformanceInsightsRetentionPeriod) | ||
if v.DBSubnetGroup != nil { | ||
d.Set("db_subnet_group_name", v.DBSubnetGroup.DBSubnetGroupName) | ||
} | ||
|
@@ -1475,6 +1546,18 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error | |
requestUpdate = true | ||
} | ||
|
||
if d.HasChange("performance_insights_enabled") || d.HasChange("performance_insights_kms_key_id") || d.HasChange("performance_insights_retention_period") { | ||
d.SetPartial("performance_insights_enabled") | ||
req.EnablePerformanceInsights = aws.Bool(d.Get("performance_insights_enabled").(bool)) | ||
|
||
d.SetPartial("performance_insights_kms_key_id") | ||
req.PerformanceInsightsKMSKeyId = aws.String(d.Get("performance_insights_kms_key_id").(string)) | ||
|
||
d.SetPartial("performance_insights_retention_period") | ||
req.PerformanceInsightsRetentionPeriod = aws.Int64(int64(d.Get("performance_insights_retention_period").(int))) | ||
requestUpdate = true | ||
} | ||
|
||
log.Printf("[DEBUG] Send DB Instance Modification request: %t", requestUpdate) | ||
if requestUpdate { | ||
log.Printf("[DEBUG] DB Instance Modification request: %s", req) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This attribute (along with the other
performance_insights_*
attributes) are not currently handled during theRestoreDBInstanceFromDBSnapshot
creation flow so attempting to creating a configuration with PI enabled andsnapshot_identifier
will require two applies of the configuration to converge.While
RestoreDBInstanceFromDBSnapshot
does not directly support settingEnablePerformanceInsights
,PerformanceInsightsKmsKeyId
, andPerformanceInsightsRetentionPeriod
, we have a framework in place to handle this situation by callingModifyDBInstance
immediately after restore, e.g.This should have an acceptance test added to ensure its functionality and prevent regressions, e.g. something similar to: