diff --git a/.changelog/6840.txt b/.changelog/6840.txt new file mode 100644 index 0000000000..c1528035ec --- /dev/null +++ b/.changelog/6840.txt @@ -0,0 +1,3 @@ +```release-note:enhancement + sql: added 'deny_maintenance_period' field for 'google_sql_database_instance' within which 'end_date', 'start_date' and 'time' fields are present. +``` diff --git a/google/resource_sql_database_instance.go b/google/resource_sql_database_instance.go index 722de1ab2f..152659ad9f 100644 --- a/google/resource_sql_database_instance.go +++ b/google/resource_sql_database_instance.go @@ -159,6 +159,30 @@ func resourceSqlDatabaseInstance() *schema.Resource { }, }, }, + "deny_maintenance_period": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "end_date": { + Type: schema.TypeString, + Required: true, + Description: `End date before which maintenance will not take place. The date is in format yyyy-mm-dd i.e., 2020-11-01, or mm-dd, i.e., 11-01`, + }, + "start_date": { + Type: schema.TypeString, + Required: true, + Description: `Start date after which maintenance will not take place. The date is in format yyyy-mm-dd i.e., 2020-11-01, or mm-dd, i.e., 11-01`, + }, + "time": { + Type: schema.TypeString, + Required: true, + Description: `Time in UTC when the "deny maintenance period" starts on start_date and ends on end_date. The time is in format: HH:mm:SS, i.e., 00:00:00`, + }, + }, + }, + }, "sql_server_audit_config": { Type: schema.TypeList, Optional: true, @@ -1066,6 +1090,7 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}) *sqladmin.Setti ForceSendFields: []string{"StorageAutoResize"}, ActivationPolicy: _settings["activation_policy"].(string), ActiveDirectoryConfig: expandActiveDirectoryConfig(_settings["active_directory_config"].([]interface{})), + DenyMaintenancePeriods: expandDenyMaintenancePeriod(_settings["deny_maintenance_period"].([]interface{})), SqlServerAuditConfig: expandSqlServerAuditConfig(_settings["sql_server_audit_config"].([]interface{})), TimeZone: _settings["time_zone"].(string), AvailabilityType: _settings["availability_type"].(string), @@ -1245,6 +1270,25 @@ func expandActiveDirectoryConfig(configured interface{}) *sqladmin.SqlActiveDire } } +func expandDenyMaintenancePeriod(configured []interface{}) []*sqladmin.DenyMaintenancePeriod { + denyMaintenancePeriod := make([]*sqladmin.DenyMaintenancePeriod, 0, len(configured)) + + for _, _flag := range configured { + if _flag == nil { + continue + } + _entry := _flag.(map[string]interface{}) + + denyMaintenancePeriod = append(denyMaintenancePeriod, &sqladmin.DenyMaintenancePeriod{ + EndDate: _entry["end_date"].(string), + StartDate: _entry["start_date"].(string), + Time: _entry["time"].(string), + }) + } + return denyMaintenancePeriod + +} + func expandSqlServerAuditConfig(configured interface{}) *sqladmin.SqlServerAuditConfig { l := configured.([]interface{}) if len(l) == 0 { @@ -1597,6 +1641,10 @@ func flattenSettings(settings *sqladmin.Settings) []map[string]interface{} { data["active_directory_config"] = flattenActiveDirectoryConfig(settings.ActiveDirectoryConfig) } + if settings.DenyMaintenancePeriods != nil { + data["deny_maintenance_period"] = flattenDenyMaintenancePeriod(settings.DenyMaintenancePeriods) + } + if settings.SqlServerAuditConfig != nil { data["sql_server_audit_config"] = flattenSqlServerAuditConfig(settings.SqlServerAuditConfig) } @@ -1676,6 +1724,22 @@ func flattenActiveDirectoryConfig(sqlActiveDirectoryConfig *sqladmin.SqlActiveDi } } +func flattenDenyMaintenancePeriod(denyMaintenancePeriod []*sqladmin.DenyMaintenancePeriod) []map[string]interface{} { + flags := make([]map[string]interface{}, 0, len(denyMaintenancePeriod)) + + for _, flag := range denyMaintenancePeriod { + data := map[string]interface{}{ + "end_date": flag.EndDate, + "start_date": flag.StartDate, + "time": flag.Time, + } + + flags = append(flags, data) + } + + return flags +} + func flattenSqlServerAuditConfig(sqlServerAuditConfig *sqladmin.SqlServerAuditConfig) []map[string]interface{} { if sqlServerAuditConfig == nil { return nil diff --git a/google/resource_sql_database_instance_test.go b/google/resource_sql_database_instance_test.go index f8587a6ed7..8f4c3ce3ed 100644 --- a/google/resource_sql_database_instance_test.go +++ b/google/resource_sql_database_instance_test.go @@ -1239,6 +1239,30 @@ func TestAccSqlDatabaseInstance_ActiveDirectory(t *testing.T) { }) } +func TestAccSQLDatabaseInstance_DenyMaintenancePeriod(t *testing.T) { + t.Parallel() + databaseName := "tf-test-" + randString(t, 10) + endDate := "2022-12-5" + startDate := "2022-10-5" + time := "00:00:00" + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testGoogleSqlDatabaseInstance_DenyMaintenancePeriodConfig(databaseName, endDate, startDate, time), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + }, + }) +} + func TestAccSqlDatabaseInstance_SqlServerAuditConfig(t *testing.T) { // Service Networking skipIfVcr(t) @@ -1494,6 +1518,25 @@ resource "google_sql_database_instance" "instance-with-ad" { }`, networkName, addressRangeName, databaseName, rootPassword, adDomainName) } +func testGoogleSqlDatabaseInstance_DenyMaintenancePeriodConfig(databaseName, endDate, startDate, time string) string { + return fmt.Sprintf(` + +resource "google_sql_database_instance" "instance" { + name = "%s" + region = "us-central1" + database_version = "MYSQL_5_7" + deletion_protection = false + settings { + tier = "db-custom-4-26624" + deny_maintenance_period { + end_date = "%s" + start_date = "%s" + time = "%s" + } + } +}`, databaseName, endDate, startDate, time) +} + func testGoogleSqlDatabaseInstance_SqlServerAuditConfig(networkName, addressName, databaseName, rootPassword, bucketName, uploadInterval, retentionInterval string) string { return fmt.Sprintf(` resource "google_storage_bucket" "gs-bucket" { diff --git a/website/docs/r/sql_database_instance.html.markdown b/website/docs/r/sql_database_instance.html.markdown index 084250bcf4..915e246b56 100644 --- a/website/docs/r/sql_database_instance.html.markdown +++ b/website/docs/r/sql_database_instance.html.markdown @@ -263,6 +263,14 @@ The optional `settings.active_directory_config` subblock supports: * `domain` - (Required) The domain name for the active directory (e.g., mydomain.com). Can only be used with SQL Server. +The optional `settings.deny_maintenance_period` subblock supports: + +* `end_date` - (Required) "deny maintenance period" end date. If the year of the end date is empty, the year of the start date also must be empty. In this case, it means the no maintenance interval recurs every year. The date is in format yyyy-mm-dd i.e., 2020-11-01, or mm-dd, i.e., 11-01 + +* `start_date` - (Required) "deny maintenance period" start date. If the year of the start date is empty, the year of the end date also must be empty. In this case, it means the deny maintenance period recurs every year. The date is in format yyyy-mm-dd i.e., 2020-11-01, or mm-dd, i.e., 11-01 + +* `time` - (Required) Time in UTC when the "deny maintenance period" starts on startDate and ends on endDate. The time is in format: HH:mm:SS, i.e., 00:00:00 + The optional `settings.sql_server_audit_config` subblock supports: * `bucket` - (Required) The name of the destination bucket (e.g., gs://mybucket).