Skip to content

Commit f486fd5

Browse files
Cloud SQL - Change bucket field to optional in sql_server_audit_config (#6923) (#13252)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 05c31d3 commit f486fd5

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

.changelog/6923.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
sql: made `settings.sql_server_audit_config.bucket` field in `google_sql_database_instance` to be optional.
3+
```

google/resource_sql_database_instance.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ var (
8383
"settings.0.insights_config.0.record_client_address",
8484
"settings.0.insights_config.0.query_plans_per_minute",
8585
}
86+
87+
sqlServerAuditConfigurationKeys = []string{
88+
"settings.0.sql_server_audit_config.0.bucket",
89+
"settings.0.sql_server_audit_config.0.retention_interval",
90+
"settings.0.sql_server_audit_config.0.upload_interval",
91+
}
8692
)
8793

8894
func resourceSqlDatabaseInstance() *schema.Resource {
@@ -190,19 +196,22 @@ func resourceSqlDatabaseInstance() *schema.Resource {
190196
Elem: &schema.Resource{
191197
Schema: map[string]*schema.Schema{
192198
"bucket": {
193-
Type: schema.TypeString,
194-
Required: true,
195-
Description: `The name of the destination bucket (e.g., gs://mybucket).`,
199+
Type: schema.TypeString,
200+
Optional: true,
201+
AtLeastOneOf: sqlServerAuditConfigurationKeys,
202+
Description: `The name of the destination bucket (e.g., gs://mybucket).`,
196203
},
197204
"retention_interval": {
198-
Type: schema.TypeString,
199-
Optional: true,
200-
Description: `How long to keep generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"..`,
205+
Type: schema.TypeString,
206+
Optional: true,
207+
AtLeastOneOf: sqlServerAuditConfigurationKeys,
208+
Description: `How long to keep generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"..`,
201209
},
202210
"upload_interval": {
203-
Type: schema.TypeString,
204-
Optional: true,
205-
Description: `How often to upload generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".`,
211+
Type: schema.TypeString,
212+
Optional: true,
213+
AtLeastOneOf: sqlServerAuditConfigurationKeys,
214+
Description: `How often to upload generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".`,
206215
},
207216
},
208217
},

google/resource_sql_database_instance_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,31 @@ func TestAccSqlDatabaseInstance_SqlServerAuditConfig(t *testing.T) {
12191219
})
12201220
}
12211221

1222+
func TestAccSqlDatabaseInstance_SqlServerAuditOptionalBucket(t *testing.T) {
1223+
t.Parallel()
1224+
databaseName := "tf-test-" + randString(t, 10)
1225+
rootPassword := randString(t, 15)
1226+
uploadInterval := "900s"
1227+
retentionInterval := "86400s"
1228+
1229+
vcrTest(t, resource.TestCase{
1230+
PreCheck: func() { testAccPreCheck(t) },
1231+
Providers: testAccProviders,
1232+
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
1233+
Steps: []resource.TestStep{
1234+
{
1235+
Config: testGoogleSqlDatabaseInstance_SqlServerAuditOptionalBucket(databaseName, rootPassword, uploadInterval, retentionInterval),
1236+
},
1237+
{
1238+
ResourceName: "google_sql_database_instance.instance",
1239+
ImportState: true,
1240+
ImportStateVerify: true,
1241+
ImportStateVerifyIgnore: []string{"root_password", "deletion_protection"},
1242+
},
1243+
},
1244+
})
1245+
}
1246+
12221247
func TestAccSqlDatabaseInstance_Timezone(t *testing.T) {
12231248
t.Parallel()
12241249

@@ -1500,6 +1525,25 @@ resource "google_sql_database_instance" "instance" {
15001525
`, bucketName, networkName, addressName, databaseName, rootPassword, bucketName, retentionInterval, uploadInterval)
15011526
}
15021527

1528+
func testGoogleSqlDatabaseInstance_SqlServerAuditOptionalBucket(databaseName, rootPassword, uploadInterval, retentionInterval string) string {
1529+
return fmt.Sprintf(`
1530+
resource "google_sql_database_instance" "instance" {
1531+
name = "%s"
1532+
region = "us-central1"
1533+
database_version = "SQLSERVER_2017_STANDARD"
1534+
root_password = "%s"
1535+
deletion_protection = false
1536+
settings {
1537+
tier = "db-custom-1-3840"
1538+
sql_server_audit_config {
1539+
retention_interval = "%s"
1540+
upload_interval = "%s"
1541+
}
1542+
}
1543+
}
1544+
`, databaseName, rootPassword, retentionInterval, uploadInterval)
1545+
}
1546+
15031547
func testGoogleSqlDatabaseInstance_Timezone(networkName, addressName, databaseName, rootPassword, timezone string) string {
15041548
return fmt.Sprintf(`
15051549
data "google_compute_network" "servicenet" {

website/docs/r/sql_database_instance.html.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ The optional `settings.deny_maintenance_period` subblock supports:
277277

278278
The optional `settings.sql_server_audit_config` subblock supports:
279279

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

282282
* `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".
283283

0 commit comments

Comments
 (0)