Skip to content

Commit

Permalink
Cloud SQL - Change bucket field to optional in sql_server_audit_config (
Browse files Browse the repository at this point in the history
#6923) (#13252)

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Dec 15, 2022
1 parent 05c31d3 commit f486fd5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .changelog/6923.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
sql: made `settings.sql_server_audit_config.bucket` field in `google_sql_database_instance` to be optional.
```
27 changes: 18 additions & 9 deletions google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ var (
"settings.0.insights_config.0.record_client_address",
"settings.0.insights_config.0.query_plans_per_minute",
}

sqlServerAuditConfigurationKeys = []string{
"settings.0.sql_server_audit_config.0.bucket",
"settings.0.sql_server_audit_config.0.retention_interval",
"settings.0.sql_server_audit_config.0.upload_interval",
}
)

func resourceSqlDatabaseInstance() *schema.Resource {
Expand Down Expand Up @@ -190,19 +196,22 @@ func resourceSqlDatabaseInstance() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bucket": {
Type: schema.TypeString,
Required: true,
Description: `The name of the destination bucket (e.g., gs://mybucket).`,
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: sqlServerAuditConfigurationKeys,
Description: `The name of the destination bucket (e.g., gs://mybucket).`,
},
"retention_interval": {
Type: schema.TypeString,
Optional: true,
Description: `How long to keep generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"..`,
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: sqlServerAuditConfigurationKeys,
Description: `How long to keep generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"..`,
},
"upload_interval": {
Type: schema.TypeString,
Optional: true,
Description: `How often to upload generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".`,
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: sqlServerAuditConfigurationKeys,
Description: `How often to upload generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".`,
},
},
},
Expand Down
44 changes: 44 additions & 0 deletions google/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,31 @@ func TestAccSqlDatabaseInstance_SqlServerAuditConfig(t *testing.T) {
})
}

func TestAccSqlDatabaseInstance_SqlServerAuditOptionalBucket(t *testing.T) {
t.Parallel()
databaseName := "tf-test-" + randString(t, 10)
rootPassword := randString(t, 15)
uploadInterval := "900s"
retentionInterval := "86400s"

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testGoogleSqlDatabaseInstance_SqlServerAuditOptionalBucket(databaseName, rootPassword, uploadInterval, retentionInterval),
},
{
ResourceName: "google_sql_database_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"root_password", "deletion_protection"},
},
},
})
}

func TestAccSqlDatabaseInstance_Timezone(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1500,6 +1525,25 @@ resource "google_sql_database_instance" "instance" {
`, bucketName, networkName, addressName, databaseName, rootPassword, bucketName, retentionInterval, uploadInterval)
}

func testGoogleSqlDatabaseInstance_SqlServerAuditOptionalBucket(databaseName, rootPassword, uploadInterval, retentionInterval string) string {
return fmt.Sprintf(`
resource "google_sql_database_instance" "instance" {
name = "%s"
region = "us-central1"
database_version = "SQLSERVER_2017_STANDARD"
root_password = "%s"
deletion_protection = false
settings {
tier = "db-custom-1-3840"
sql_server_audit_config {
retention_interval = "%s"
upload_interval = "%s"
}
}
}
`, databaseName, rootPassword, retentionInterval, uploadInterval)
}

func testGoogleSqlDatabaseInstance_Timezone(networkName, addressName, databaseName, rootPassword, timezone string) string {
return fmt.Sprintf(`
data "google_compute_network" "servicenet" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/sql_database_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ The optional `settings.deny_maintenance_period` subblock supports:

The optional `settings.sql_server_audit_config` subblock supports:

* `bucket` - (Required) The name of the destination bucket (e.g., gs://mybucket).
* `bucket` - (Optional) The name of the destination bucket (e.g., gs://mybucket).

* `upload_interval` - (Optional) How often to upload generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".

Expand Down

0 comments on commit f486fd5

Please sign in to comment.