Skip to content

Commit

Permalink
Merge pull request #35626 from acwwat/f-aws_db_instance-cw_log_export…
Browse files Browse the repository at this point in the history
…s_db_values

feat: Support Db2 CloudWatch log exports for aws_db_instance
  • Loading branch information
ewbankkit authored Feb 5, 2024
2 parents bdb787a + 89d74d7 commit 98ef8a6
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/35626.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_db_instance: Add `diag.log` and `notify.log` as valid values for `enabled_cloudwatch_logs_exports`
```
4 changes: 4 additions & 0 deletions internal/service/rds/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ const (
ExportableLogTypeAgent = "agent"
ExportableLogTypeAlert = "alert"
ExportableLogTypeAudit = "audit"
ExportableLogTypeDiagLog = "diag.log"
ExportableLogTypeError = "error"
ExportableLogTypeGeneral = "general"
ExportableLogTypeListener = "listener"
ExportableLogTypeNotifyLog = "notify.log"
ExportableLogTypeOEMAgent = "oemagent"
ExportableLogTypePostgreSQL = "postgresql"
ExportableLogTypeSlowQuery = "slowquery"
Expand All @@ -211,9 +213,11 @@ func InstanceExportableLogType_Values() []string {
ExportableLogTypeAgent,
ExportableLogTypeAlert,
ExportableLogTypeAudit,
ExportableLogTypeDiagLog,
ExportableLogTypeError,
ExportableLogTypeGeneral,
ExportableLogTypeListener,
ExportableLogTypeNotifyLog,
ExportableLogTypeOEMAgent,
ExportableLogTypePostgreSQL,
ExportableLogTypeSlowQuery,
Expand Down
78 changes: 78 additions & 0 deletions internal/service/rds/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3820,6 +3820,48 @@ func TestAccRDSInstance_cloudWatchLogsExport(t *testing.T) {
})
}

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

var v rds.DBInstance
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_db_instance.test"
// Requires an IBM Db2 License set as environmental variable.
// Licensing pre-requisite: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/db2-licensing.html.
customerID := acctest.SkipIfEnvVarNotSet(t, "RDS_DB2_CUSTOMER_ID")
siteID := acctest.SkipIfEnvVarNotSet(t, "RDS_DB2_SITE_ID")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckInstanceDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInstanceConfig_EnabledCloudWatchLogsExports_db2(rName, customerID, siteID),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"final_snapshot_identifier",
"password",
"skip_final_snapshot",
},
},
},
})
}

func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
Expand Down Expand Up @@ -7860,6 +7902,42 @@ resource "aws_db_instance" "test" {
`, deletionProtection, rName))
}

func testAccInstanceConfig_EnabledCloudWatchLogsExports_db2(rName, customerId, siteId string) string {
return acctest.ConfigCompose(
testAccInstanceConfig_orderableClassDB2(),
fmt.Sprintf(`
resource "aws_db_parameter_group" "test" {
name = "tf-db2-pg-%[1]s"
family = data.aws_rds_engine_version.default.parameter_group_family
parameter {
name = "rds.ibm_customer_id"
value = %[2]s
apply_method = "immediate"
}
parameter {
name = "rds.ibm_site_id"
value = %[3]s
apply_method = "immediate"
}
}
resource "aws_db_instance" "test" {
allocated_storage = 100
db_name = "test"
enabled_cloudwatch_logs_exports = ["diag.log", "notify.log"]
engine = data.aws_rds_orderable_db_instance.test.engine
engine_version = data.aws_rds_orderable_db_instance.test.engine_version
identifier = %[1]q
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
parameter_group_name = aws_db_parameter_group.test.name
password = "avoid-plaintext-passwords"
username = "tfacctest"
skip_final_snapshot = true
}
`, rName, customerId, siteId))
}

func testAccInstanceConfig_EnabledCloudWatchLogsExports_oracle(rName string) string {
return fmt.Sprintf(`
data "aws_rds_orderable_db_instance" "test" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/db_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ for additional read replica constraints.
* `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.
* `domain_iam_role_name` - (Optional, but required if domain is provided) The name of the IAM role to be used when making API calls to the Directory Service.
* `enabled_cloudwatch_logs_exports` - (Optional) Set of log types to enable for exporting to CloudWatch logs. If omitted, no logs will be exported. Valid values (depending on `engine`). MySQL and MariaDB: `audit`, `error`, `general`, `slowquery`. PostgreSQL: `postgresql`, `upgrade`. MSSQL: `agent` , `error`. Oracle: `alert`, `audit`, `listener`, `trace`.
* `enabled_cloudwatch_logs_exports` - (Optional) Set of log types to enable for exporting to CloudWatch logs. If omitted, no logs will be exported. For supported values, see the EnableCloudwatchLogsExports.member.N parameter in [API action CreateDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html).
* `engine` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) The database engine to use. For supported values, see the Engine parameter in [API action CreateDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html). Note that for Amazon Aurora instances the engine must match the [DB cluster](/docs/providers/aws/r/rds_cluster.html)'s engine'. For information on the difference between the available Aurora MySQL engines see [Comparison between Aurora MySQL 1 and Aurora MySQL 2](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraMySQL.Updates.20180206.html) in the Amazon RDS User Guide.
* `engine_version` - (Optional) The engine version to use. If `auto_minor_version_upgrade` is enabled, you can provide a prefix of the version such as `5.7` (for `5.7.10`). The actual engine version used is returned in the attribute `engine_version_actual`, see [Attribute Reference](#attribute-reference) below. For supported values, see the EngineVersion parameter in [API action CreateDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html). Note that for Amazon Aurora instances the engine version must match the [DB cluster](/docs/providers/aws/r/rds_cluster.html)'s engine version'.
* `final_snapshot_identifier` - (Optional) The name of your final DB snapshot
Expand Down

0 comments on commit 98ef8a6

Please sign in to comment.