Skip to content

Commit

Permalink
Merge pull request #36503 from askreet/f-aws_db_instance-dedicated_lo…
Browse files Browse the repository at this point in the history
…g_volume

Add `dedicated_log_volume` argument to `aws_db_instance` resource.
  • Loading branch information
gdavison authored Apr 25, 2024
2 parents b075fdf + 65c51e2 commit 8dac9c4
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/36503.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_db_instance: Add `dedicated_log_volume` argument
```
31 changes: 31 additions & 0 deletions internal/service/rds/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ func ResourceInstance() *schema.Resource {
Optional: true,
Computed: true,
},
"dedicated_log_volume": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"delete_automated_backups": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -769,6 +774,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.DBSubnetGroupName = aws.String(v.(string))
}

if v, ok := d.GetOk("dedicated_log_volume"); ok {
input.DedicatedLogVolume = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("enabled_cloudwatch_logs_exports"); ok && v.(*schema.Set).Len() > 0 {
input.EnableCloudwatchLogsExports = flex.ExpandStringSet(v.(*schema.Set))
}
Expand Down Expand Up @@ -981,6 +990,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.DBSubnetGroupName = aws.String(v.(string))
}

if v, ok := d.GetOk("dedicated_log_volume"); ok {
input.DedicatedLogVolume = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("iam_database_authentication_enabled"); ok {
input.EnableIAMDatabaseAuthentication = aws.Bool(v.(bool))
}
Expand Down Expand Up @@ -1160,6 +1173,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.DBSubnetGroupName = aws.String(v.(string))
}

if v, ok := d.GetOk("dedicated_log_volume"); ok {
input.DedicatedLogVolume = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("domain"); ok {
input.Domain = aws.String(v.(string))
}
Expand Down Expand Up @@ -1401,6 +1418,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.DBSubnetGroupName = aws.String(v.(string))
}

if v, ok := d.GetOk("dedicated_log_volume"); ok {
input.DedicatedLogVolume = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("domain"); ok {
input.Domain = aws.String(v.(string))
}
Expand Down Expand Up @@ -1585,6 +1606,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.DBSubnetGroupName = aws.String(v.(string))
}

if v, ok := d.GetOk("dedicated_log_volume"); ok {
input.DedicatedLogVolume = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("domain"); ok {
input.Domain = aws.String(v.(string))
}
Expand Down Expand Up @@ -1824,6 +1849,7 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte
if v.DBSubnetGroup != nil {
d.Set("db_subnet_group_name", v.DBSubnetGroup.DBSubnetGroupName)
}
d.Set("dedicated_log_volume", v.DedicatedLogVolume)
d.Set("deletion_protection", v.DeletionProtection)
if len(v.DomainMemberships) > 0 && v.DomainMemberships[0] != nil {
v := v.DomainMemberships[0]
Expand Down Expand Up @@ -2209,6 +2235,11 @@ func dbInstancePopulateModify(input *rds_sdkv2.ModifyDBInstanceInput, d *schema.
input.DBSubnetGroupName = aws.String(d.Get("db_subnet_group_name").(string))
}

if d.HasChange("dedicated_log_volume") {
needsModify = true
input.DedicatedLogVolume = aws.Bool(d.Get("dedicated_log_volume").(bool))
}

if d.HasChange("deletion_protection") {
needsModify = true
}
Expand Down
121 changes: 121 additions & 0 deletions internal/service/rds/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestAccRDSInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "copy_tags_to_snapshot", "false"),
resource.TestCheckResourceAttr(resourceName, "db_name", "test"),
resource.TestCheckResourceAttr(resourceName, "db_subnet_group_name", "default"),
resource.TestCheckResourceAttr(resourceName, "dedicated_log_volume", "false"),
resource.TestCheckResourceAttr(resourceName, "deletion_protection", "false"),
resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "endpoint"),
Expand Down Expand Up @@ -1043,6 +1044,7 @@ func TestAccRDSInstance_ReplicateSourceDB_basic(t *testing.T) {
testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance),
resource.TestCheckResourceAttrPair(resourceName, "replicate_source_db", sourceResourceName, "identifier"),
resource.TestCheckResourceAttrPair(resourceName, "db_name", sourceResourceName, "db_name"),
resource.TestCheckResourceAttr(resourceName, "dedicated_log_volume", "false"),
resource.TestCheckResourceAttrPair(resourceName, "username", sourceResourceName, "username"),

resource.TestCheckResourceAttr(sourceResourceName, "replicas.#", "0"), // Before refreshing source, it will not be aware of replicas
Expand Down Expand Up @@ -2375,6 +2377,7 @@ func TestAccRDSInstance_SnapshotIdentifier_basic(t *testing.T) {
testAccCheckInstanceExists(ctx, resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "identifier", rName),
resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""),
resource.TestCheckResourceAttr(resourceName, "dedicated_log_volume", "false"),
resource.TestCheckResourceAttrPair(resourceName, "instance_class", sourceDbResourceName, "instance_class"),
resource.TestCheckResourceAttrPair(resourceName, "allocated_storage", sourceDbResourceName, "allocated_storage"),
resource.TestCheckResourceAttrPair(resourceName, "engine", sourceDbResourceName, "engine"),
Expand Down Expand Up @@ -4229,6 +4232,101 @@ func TestAccRDSInstance_CloudWatchLogsExport_postgresql(t *testing.T) {
})
}

func TestAccRDSInstance_dedicatedLogVolume_enableOnCreate(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var dbInstance rds.DBInstance
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_db_instance.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckInstanceDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInstanceConfig_dedicatedLogVolumeEnabled(rName, true),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "dedicated_log_volume", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"password",
},
},
},
})
}

func TestAccRDSInstance_dedicatedLogVolume_enableOnUpdate(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var dbInstance rds.DBInstance
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_db_instance.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckInstanceDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInstanceConfig_dedicatedLogVolumeEnabled(rName, false),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "dedicated_log_volume", "false"),
),
},
{
Config: testAccInstanceConfig_dedicatedLogVolumeEnabled(rName, true),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "dedicated_log_volume", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"password",
},
},
{
Config: testAccInstanceConfig_dedicatedLogVolumeEnabled(rName, false),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "dedicated_log_volume", "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"password",
},
},
},
})
}

func TestAccRDSInstance_noDeleteAutomatedBackups(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
Expand Down Expand Up @@ -11386,6 +11484,29 @@ resource "aws_db_instance" "test" {
`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName)
}

func testAccInstanceConfig_dedicatedLogVolumeEnabled(rName string, enabled bool) string {
return acctest.ConfigCompose(testAccInstanceConfig_orderableClassPostgres(), fmt.Sprintf(`
resource "aws_db_instance" "test" {
# Dedicated log volumes do not support PG 16 instances.
engine = "postgres"
engine_version = "15.6"
identifier = %[1]q
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
password = "avoid-plaintext-passwords"
username = "tfacctest"
skip_final_snapshot = true
apply_immediately = true
# Minimum amounts required to qualify for IOPS / DedicatedLogVolume
allocated_storage = 100
storage_type = "io1"
iops = 1000
dedicated_log_volume = %[2]t
}
`, rName, enabled))
}

func testAccInstanceConfig_noDeleteAutomatedBackups(rName string) string {
return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMariadb(), fmt.Sprintf(`
resource "aws_db_instance" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/db_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ with read replicas, it should be specified only if the source database
specifies an instance in another AWS Region. See [DBSubnetGroupName in API
action CreateDBInstanceReadReplica](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstanceReadReplica.html)
for additional read replica constraints.
* `dedicated_log_volume` - (Optional, boolean) Use a dedicated log volume (DLV) for the DB instance. Requires Provisioned IOPS. See the [AWS documentation](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.dlv) for more details.
* `delete_automated_backups` - (Optional) Specifies whether to remove automated backups immediately after the DB instance is deleted. Default is `true`.
* `deletion_protection` - (Optional) If the DB instance should have deletion protection enabled. The database can't be deleted when this value is set to `true`. The default is `false`.
* `domain` - (Optional) The ID of the Directory Service Active Directory domain to create the instance in. Conflicts with `domain_fqdn`, `domain_ou`, `domain_auth_secret_arn` and a `domain_dns_ips`.
Expand Down

0 comments on commit 8dac9c4

Please sign in to comment.