diff --git a/.goreleaser.yml b/.goreleaser.yml index 72bce2ed2..74d16c2dd 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -28,6 +28,8 @@ builds: ignore: - goos: darwin goarch: '386' + - goos: windows + goarch: arm64 binary: '{{ .ProjectName }}_v{{ .Version }}' archives: - format: zip @@ -38,7 +40,7 @@ checksum: signs: - artifacts: checksum args: - # if you are using this is a GitHub action or some other automated pipeline, you + # if you are using this is a GitHub action or some other automated pipeline, you # need to pass the batch flag to indicate its not interactive. - "--batch" - "--local-user" diff --git a/CHANGELOG.md b/CHANGELOG.md index b14ab957f..241508145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,13 @@ -## 0.77.0 (Unreleased) +## 0.78.0 (Unreleased) +BUG FIXES: +* cdn: fixed wrong documentation example + +FEATURES: +* greenplum: add `maintenance_window` attribute to resource and data source +* greenplum: support for changing the user's password +* greenplum: support for changing segment and master resources + +## 0.77.0 (July 27, 2022) BUG FIXES: * iam: fix access bindings deletion * ydb: fixed panic if database was removed outside of terraform @@ -10,6 +19,7 @@ BUG FIXES: ENHANCEMENTS: * mdb: add `sqlcollation` attribute to `yandex_mdb_sqlserver_cluster` resource and data source * serverless: increase operation timeouts in `yandex_function` resource +* cdn: added the ability to set custom `folder_id` attribute for resources `yandex_cdn_origin_group` and `yandex_cdn_resource` FEATURES: * k8s: add `instance_template.name` attribute to `node group` resource and data source diff --git a/website/docs/d/datasource_cdn_origin_group.html.markdown b/website/docs/d/datasource_cdn_origin_group.html.markdown index 3e672711d..a0f5804a4 100644 --- a/website/docs/d/datasource_cdn_origin_group.html.markdown +++ b/website/docs/d/datasource_cdn_origin_group.html.markdown @@ -33,8 +33,8 @@ The following arguments are supported: * `name` - (Optional) Name of the origin group. * `folder_id` - (Optional) Folder that the resource belongs to. If value is omitted, the default provider folder is used. * `origins` -A set of available origins, an origins group must contain at least one enabled origin with fields: - - source (Required) - IP address or Domain name of your origin and the port; - - enabled (Optional) - the origin is enabled and used as a source for the CDN. Default is enabled. - - backup (Optional) - specifies whether the origin is used in its origin group as backup. A backup origin is used when one of active origins becomes unavailable. + * `source` (Required) - IP address or Domain name of your origin and the port; + * `enabled` (Optional) - the origin is enabled and used as a source for the CDN. Default is enabled. + * `backup` (Optional) - specifies whether the origin is used in its origin group as backup. A backup origin is used when one of active origins becomes unavailable. ~> **NOTE:** One of `origin_group_id` or `name` should be specified. diff --git a/website/docs/d/datasource_cdn_resource.html.markdown b/website/docs/d/datasource_cdn_resource.html.markdown index 4b73a5041..4ea689bca 100644 --- a/website/docs/d/datasource_cdn_resource.html.markdown +++ b/website/docs/d/datasource_cdn_resource.html.markdown @@ -31,6 +31,8 @@ The following arguments are supported: * `cname` (Required) - CDN endpoint CNAME, must be unique among resources. +* `folder_id` (Optional) - Folder that the resource belongs to. If value is omitted, the default provider folder is used. + * `active` (Optional) - Flag to create Resource either in active or disabled state. True - the content from CDN is available to clients. * `options` (Optional) - CDN Resource settings and options to tune CDN edge behavior. diff --git a/website/docs/d/datasource_mdb_greenplum_cluster.html.markdown b/website/docs/d/datasource_mdb_greenplum_cluster.html.markdown index 4ad3d86c6..4b5581d6c 100644 --- a/website/docs/d/datasource_mdb_greenplum_cluster.html.markdown +++ b/website/docs/d/datasource_mdb_greenplum_cluster.html.markdown @@ -64,6 +64,7 @@ exported: * `segment_hosts` - Info about hosts in segment subcluster. The structure is documented below. * `access` - Access policy to the Greenplum cluster. The structure is documented below. +* `maintenance_window` - Maintenance window settings of the Greenplum cluster. The structure is documented below. * `backup_window_start` - Time to start the daily backup, in the UTC timezone. The structure is documented below. * `pooler_config` - Configuration of the connection pooler. The structure is documented below. @@ -102,6 +103,11 @@ The `access` block supports: * `data_lens` - Allow access for [Yandex DataLens](https://cloud.yandex.com/services/datalens). * `web_sql` - Allows access for SQL queries in the management console. +The `maintenance_window` block supports: + +* `type` - Type of maintenance window. Can be either `ANYTIME` or `WEEKLY`. +* `day` - Day of the week (in `DDD` format). Value is one of: "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" +* `hour` - Hour of the day in UTC (in `HH` format). Value is between 1 and 24. The `pooler_config` block supports: diff --git a/website/docs/r/cdn_resource.html.markdown b/website/docs/r/cdn_resource.html.markdown index 1e3afd18d..59e72e979 100644 --- a/website/docs/r/cdn_resource.html.markdown +++ b/website/docs/r/cdn_resource.html.markdown @@ -26,7 +26,7 @@ resource "yandex_cdn_resource" "my_resource" { origin_group_id = yandex_cdn_origin_group.foo_cdn_group_by_id.id - options = { + options { edge_cache_settings = 345600 ignore_cookie = true } diff --git a/website/docs/r/mdb_greenplum_cluster.html.markdown b/website/docs/r/mdb_greenplum_cluster.html.markdown index ca076f631..0d0d0266d 100644 --- a/website/docs/r/mdb_greenplum_cluster.html.markdown +++ b/website/docs/r/mdb_greenplum_cluster.html.markdown @@ -122,6 +122,8 @@ The following arguments are supported: * `access` - (Optional) Access policy to the Greenplum cluster. The structure is documented below. +* `maintenance_window` - (Optional) Maintenance policy of the Greenplum cluster. The structure is documented below. + * `backup_window_start` - (Optional) Time to start the daily backup, in the UTC timezone. The structure is documented below. * `pooler_config` - (Optional) Configuration of the connection pooler. The structure is documented below. @@ -166,6 +168,14 @@ The `access` block supports: * `web_sql` - Allows access for SQL queries in the management console +The `maintenance_window` block supports: + +* `type` - (Required) Type of maintenance window. Can be either `ANYTIME` or `WEEKLY`. A day and hour of window need to be specified with weekly window. + +* `day` - (Optional) Day of the week (in `DDD` format). Allowed values: "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" + +* `hour` - (Optional) Hour of the day in UTC (in `HH` format). Allowed value is between 0 and 23. + The `pooler_config` block supports: * `pooling_mode` - (Optional) Mode that the connection pooler is working in. See descriptions of all modes in the [documentation for Odyssey](https://github.com/yandex/odyssey/blob/master/documentation/configuration.md#pool-string. diff --git a/yandex/data_source_yandex_mdb_greenplum_cluster.go b/yandex/data_source_yandex_mdb_greenplum_cluster.go index 006f4c61e..d105bf329 100644 --- a/yandex/data_source_yandex_mdb_greenplum_cluster.go +++ b/yandex/data_source_yandex_mdb_greenplum_cluster.go @@ -185,6 +185,26 @@ func dataSourceYandexMDBGreenplumCluster() *schema.Resource { Set: schema.HashString, Computed: true, }, + "maintenance_window": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Computed: true, + }, + "day": { + Type: schema.TypeString, + Computed: true, + }, + "hour": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, "deletion_protection": { Type: schema.TypeBool, Computed: true, diff --git a/yandex/data_source_yandex_mdb_mysql_cluster.go b/yandex/data_source_yandex_mdb_mysql_cluster.go index 76ae1ca17..fc9dc13cc 100644 --- a/yandex/data_source_yandex_mdb_mysql_cluster.go +++ b/yandex/data_source_yandex_mdb_mysql_cluster.go @@ -410,10 +410,7 @@ func dataSourceYandexMDBMySQLClusterRead(d *schema.ResourceData, meta interface{ return err } - backupWindowStart, err := flattenMysqlBackupWindowStart(cluster.GetConfig().GetBackupWindowStart()) - if err != nil { - return err - } + backupWindowStart := flattenMDBBackupWindowStart(cluster.GetConfig().GetBackupWindowStart()) if err := d.Set("backup_window_start", backupWindowStart); err != nil { return err } diff --git a/yandex/data_source_yandex_mdb_sqlserver_cluster.go b/yandex/data_source_yandex_mdb_sqlserver_cluster.go index 881631890..e45830443 100644 --- a/yandex/data_source_yandex_mdb_sqlserver_cluster.go +++ b/yandex/data_source_yandex_mdb_sqlserver_cluster.go @@ -299,10 +299,7 @@ func dataSourceYandexMDBSQLServerClusterRead(d *schema.ResourceData, meta interf return err } - backupWindowStart, err := flattenSQLServerBackupWindowStart(cluster.GetConfig().GetBackupWindowStart()) - if err != nil { - return err - } + backupWindowStart := flattenMDBBackupWindowStart(cluster.GetConfig().GetBackupWindowStart()) if err = d.Set("backup_window_start", backupWindowStart); err != nil { return err } diff --git a/yandex/mdb_greenplum_structures.go b/yandex/mdb_greenplum_structures.go index 4278ecd23..5d0460918 100644 --- a/yandex/mdb_greenplum_structures.go +++ b/yandex/mdb_greenplum_structures.go @@ -69,13 +69,62 @@ func flattenGreenplumAccess(c *greenplum.GreenplumConfig) []map[string]interface return []map[string]interface{}{out} } -func flattenBackupWindowsStart(c *greenplum.GreenplumConfig) []map[string]interface{} { - out := map[string]interface{}{} - if c != nil && c.BackupWindowStart != nil { - out["hours"] = c.BackupWindowStart.Hours - out["minutes"] = c.BackupWindowStart.Minutes +func flattenGreenplumMaintenanceWindow(mw *greenplum.MaintenanceWindow) ([]interface{}, error) { + maintenanceWindow := map[string]interface{}{} + if mw != nil { + switch p := mw.GetPolicy().(type) { + case *greenplum.MaintenanceWindow_Anytime: + maintenanceWindow["type"] = "ANYTIME" + // do nothing + case *greenplum.MaintenanceWindow_WeeklyMaintenanceWindow: + maintenanceWindow["type"] = "WEEKLY" + maintenanceWindow["hour"] = p.WeeklyMaintenanceWindow.Hour + maintenanceWindow["day"] = greenplum.WeeklyMaintenanceWindow_WeekDay_name[int32(p.WeeklyMaintenanceWindow.GetDay())] + default: + return nil, fmt.Errorf("unsupported greenplum maintenance policy type") + } } - return []map[string]interface{}{out} + + return []interface{}{maintenanceWindow}, nil +} + +func expandGreenplumMaintenanceWindow(d *schema.ResourceData) (*greenplum.MaintenanceWindow, error) { + if _, ok := d.GetOkExists("maintenance_window"); !ok { + return nil, nil + } + + out := &greenplum.MaintenanceWindow{} + typeMW, _ := d.GetOk("maintenance_window.0.type") + if typeMW == "ANYTIME" { + if hour, ok := d.GetOk("maintenance_window.0.hour"); ok && hour != "" { + return nil, fmt.Errorf("hour should be not set, when using ANYTIME") + } + if day, ok := d.GetOk("maintenance_window.0.day"); ok && day != "" { + return nil, fmt.Errorf("day should be not set, when using ANYTIME") + } + out.Policy = &greenplum.MaintenanceWindow_Anytime{ + Anytime: &greenplum.AnytimeMaintenanceWindow{}, + } + } else if typeMW == "WEEKLY" { + hour := d.Get("maintenance_window.0.hour").(int) + dayString := d.Get("maintenance_window.0.day").(string) + + day, ok := greenplum.WeeklyMaintenanceWindow_WeekDay_value[dayString] + if !ok || day == 0 { + return nil, fmt.Errorf(`day value should be one of ("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN")`) + } + + out.Policy = &greenplum.MaintenanceWindow_WeeklyMaintenanceWindow{ + WeeklyMaintenanceWindow: &greenplum.WeeklyMaintenanceWindow{ + Hour: int64(hour), + Day: greenplum.WeeklyMaintenanceWindow_WeekDay(day), + }, + } + } else { + return nil, fmt.Errorf("maintenance_window.0.type should be ANYTIME or WEEKLY") + } + + return out, nil } func flattenGreenplumClusterConfig(c *greenplum.ClusterConfigSet) (map[string]string, error) { @@ -144,17 +193,28 @@ func expandGreenplumAccess(d *schema.ResourceData) *greenplum.Access { func expandGreenplumUpdatePath(d *schema.ResourceData, settingNames []string) []string { mdbGreenplumUpdateFieldsMap := map[string]string{ - "name": "name", - "description": "description", - "labels": "labels", - "access.0.data_lens": "config.access.data_lens", - "access.0.web_sql": "config.access.web_sql", - "backup_window_start": "config.backup_window_start", - "deletion_protection": "deletion_protection", - "security_group_ids": "security_group_ids", - "pooler_config.0.pooling_mode": "config_spec.pool.mode", - "pooler_config.0.pool_size": "config_spec.pool.size", + "name": "name", + "description": "description", + "user_password": "user_password", + "labels": "labels", + "access.0.data_lens": "config.access.data_lens", + "access.0.web_sql": "config.access.web_sql", + "backup_window_start": "config.backup_window_start", + "maintenance_window": "maintenance_window", + "deletion_protection": "deletion_protection", + "security_group_ids": "security_group_ids", + + "pooler_config.0.pooling_mode": "config_spec.pool.mode", + "pooler_config.0.pool_size": "config_spec.pool.size", "pooler_config.0.pool_client_idle_timeout": "config_spec.pool.client_idle_timeout", + + "master_subcluster.0.resources.0.resource_preset_id": "master_config.resources.resource_preset_id", + "master_subcluster.0.resources.0.disk_type_id": "master_config.resources.disk_type_id", + "master_subcluster.0.resources.0.disk_size": "master_config.resources.disk_size", + + "segment_subcluster.0.resources.0.resource_preset_id": "segment_config.resources.resource_preset_id", + "segment_subcluster.0.resources.0.disk_type_id": "segment_config.resources.disk_type_id", + "segment_subcluster.0.resources.0.disk_size": "segment_config.resources.disk_size", } updatePath := []string{} diff --git a/yandex/mdb_mysql_structures.go b/yandex/mdb_mysql_structures.go index 219eacbb5..3271de758 100644 --- a/yandex/mdb_mysql_structures.go +++ b/yandex/mdb_mysql_structures.go @@ -16,7 +16,6 @@ import ( "github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/mysql/v1" config "github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/mysql/v1/config" "github.com/yandex-cloud/terraform-provider-yandex/yandex/internal/hashcode" - "google.golang.org/genproto/googleapis/type/timeofday" ) func parseMysqlEnv(e string) (mysql.Cluster_Environment, error) { @@ -273,29 +272,6 @@ func flattenMysqlResources(r *mysql.Resources) ([]map[string]interface{}, error) return []map[string]interface{}{res}, nil } -func flattenMysqlBackupWindowStart(t *timeofday.TimeOfDay) ([]interface{}, error) { - out := map[string]interface{}{} - - out["hours"] = int(t.Hours) - out["minutes"] = int(t.Minutes) - - return []interface{}{out}, nil -} - -func expandMysqlBackupWindowStart(d *schema.ResourceData) *timeofday.TimeOfDay { - out := &timeofday.TimeOfDay{} - - if v, ok := d.GetOk("backup_window_start.0.hours"); ok { - out.Hours = int32(v.(int)) - } - - if v, ok := d.GetOk("backup_window_start.0.minutes"); ok { - out.Minutes = int32(v.(int)) - } - - return out -} - type compareMySQLHostsInfoResult struct { hostsInfo map[string]*myHostInfo // fqdn -> *myHostInfo createHostsInfo []*myHostInfo // hosts to be created @@ -1345,17 +1321,6 @@ func expandMySQLMaintenanceWindow(d *schema.ResourceData) (*mysql.MaintenanceWin return out, nil } -func mysqlMaintenanceWindowSchemaValidateFunc(v interface{}, k string) (s []string, es []error) { - dayString := v.(string) - day, ok := mysql.WeeklyMaintenanceWindow_WeekDay_value[dayString] - if !ok || day == 0 { - es = append(es, fmt.Errorf(`expected %s value should be one of ("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"). Current value is %v`, k, v)) - return - } - - return -} - func convertSQLModes57ToInt32(sqlModes []config.MysqlConfig5_7_SQLMode) []int32 { modes := make([]int32, 0) for _, v := range sqlModes { @@ -1421,7 +1386,7 @@ func expandMySQLConfigSpec(d *schema.ResourceData) (*mysql.ConfigSpec, error) { configSpec := &mysql.ConfigSpec{ Version: d.Get("version").(string), Resources: expandMysqlResources(d), - BackupWindowStart: expandMysqlBackupWindowStart(d), + BackupWindowStart: expandMDBBackupWindowStart(d, "backup_window_start.0"), Access: expandMySQLAccess(d), PerformanceDiagnostics: expandMyPerformanceDiagnostics(d), } diff --git a/yandex/mdb_postgresql_structures.go b/yandex/mdb_postgresql_structures.go index 73b24b7ed..1369a8405 100644 --- a/yandex/mdb_postgresql_structures.go +++ b/yandex/mdb_postgresql_structures.go @@ -14,7 +14,6 @@ import ( wrappers "github.com/golang/protobuf/ptypes/wrappers" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - timeofday "google.golang.org/genproto/googleapis/type/timeofday" "github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/postgresql/v1" config "github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/postgresql/v1/config" @@ -36,11 +35,6 @@ func flattenPGClusterConfig(c *postgresql.ClusterConfig, d *schema.ResourceData) return nil, err } - backupWindowStart, err := flattenPGBackupWindowStart(c.BackupWindowStart) - if err != nil { - return nil, err - } - performanceDiagnostics, err := flattenPGPerformanceDiagnostics(c.PerformanceDiagnostics) if err != nil { return nil, err @@ -61,7 +55,7 @@ func flattenPGClusterConfig(c *postgresql.ClusterConfig, d *schema.ResourceData) out["version"] = c.Version out["pooler_config"] = poolerConf out["resources"] = resources - out["backup_window_start"] = backupWindowStart + out["backup_window_start"] = flattenMDBBackupWindowStart(c.BackupWindowStart) out["backup_retain_period_days"] = c.BackupRetainPeriodDays.GetValue() out["performance_diagnostics"] = performanceDiagnostics out["access"] = access @@ -835,7 +829,7 @@ func expandPGConfigSpec(d *schema.ResourceData) (cs *postgresql.ConfigSpec, upda } cs.Resources = resources - cs.BackupWindowStart = expandPGBackupWindowStart(d) + cs.BackupWindowStart = expandMDBBackupWindowStart(d, "config.0.backup_window_start.0") cs.Access = expandPGAccess(d) cs.PerformanceDiagnostics = expandPGPerformanceDiagnostics(d) @@ -1122,20 +1116,6 @@ func expandPGExtensions(es []interface{}) []*postgresql.Extension { return out } -func expandPGBackupWindowStart(d *schema.ResourceData) *timeofday.TimeOfDay { - out := &timeofday.TimeOfDay{} - - if v, ok := d.GetOk("config.0.backup_window_start.0.hours"); ok { - out.Hours = int32(v.(int)) - } - - if v, ok := d.GetOk("config.0.backup_window_start.0.minutes"); ok { - out.Minutes = int32(v.(int)) - } - - return out -} - func expandPGPerformanceDiagnostics(d *schema.ResourceData) *postgresql.PerformanceDiagnostics { if _, ok := d.GetOkExists("config.0.performance_diagnostics"); !ok { @@ -1235,17 +1215,6 @@ func expandPGMaintenanceWindow(d *schema.ResourceData) (*postgresql.MaintenanceW return out, nil } -func pgMaintenanceWindowSchemaValidateFunc(v interface{}, k string) (s []string, es []error) { - dayString := v.(string) - day, ok := postgresql.WeeklyMaintenanceWindow_WeekDay_value[dayString] - if !ok || day == 0 { - es = append(es, fmt.Errorf(`expected %s value should be one of ("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"). Current value is %v`, k, v)) - return - } - - return -} - func expandPGConfigSpecSettings(d *schema.ResourceData, configSpec *postgresql.ConfigSpec) (updateFieldConfigName string, err error) { version := configSpec.Version diff --git a/yandex/mdb_sqlserver_structures.go b/yandex/mdb_sqlserver_structures.go index d92af01f2..b9fd25e33 100644 --- a/yandex/mdb_sqlserver_structures.go +++ b/yandex/mdb_sqlserver_structures.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/sqlserver/v1" - "google.golang.org/genproto/googleapis/type/timeofday" config "github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/sqlserver/v1/config" ) @@ -53,29 +52,6 @@ func flattenSQLServerResources(r *sqlserver.Resources) []map[string]interface{} return []map[string]interface{}{res} } -func expandSQLServerBackupWindowStart(d *schema.ResourceData) *timeofday.TimeOfDay { - out := &timeofday.TimeOfDay{} - - if v, ok := d.GetOk("backup_window_start.0.hours"); ok { - out.Hours = int32(v.(int)) - } - - if v, ok := d.GetOk("backup_window_start.0.minutes"); ok { - out.Minutes = int32(v.(int)) - } - - return out -} - -func flattenSQLServerBackupWindowStart(t *timeofday.TimeOfDay) ([]interface{}, error) { - out := map[string]interface{}{} - - out["hours"] = int(t.Hours) - out["minutes"] = int(t.Minutes) - - return []interface{}{out}, nil -} - func expandSQLServerHost(config map[string]interface{}) (*sqlserver.HostSpec, error) { hostSpec := &sqlserver.HostSpec{} if v, ok := config["zone"]; ok { diff --git a/yandex/mdb_structures.go b/yandex/mdb_structures.go index 107edb87f..33499d275 100644 --- a/yandex/mdb_structures.go +++ b/yandex/mdb_structures.go @@ -1,18 +1,37 @@ package yandex import ( + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "google.golang.org/genproto/googleapis/type/timeofday" - "google.golang.org/protobuf/types/known/wrapperspb" ) -type MdbConnectionPoolerConfig interface { - GetPoolingMode() int32 - GetPoolDiscard() *wrapperspb.BoolValue +var weeklyMaintenanceWindow_WeekDay_value = map[string]int32{ + "WEEK_DAY_UNSPECIFIED": 0, + "MON": 1, + "TUE": 2, + "WED": 3, + "THU": 4, + "FRI": 5, + "SAT": 6, + "SUN": 7, +} + +func mdbMaintenanceWindowSchemaValidateFunc(v interface{}, k string) (s []string, es []error) { + dayString := v.(string) + day, ok := weeklyMaintenanceWindow_WeekDay_value[dayString] + if !ok || day == 0 { + es = append(es, fmt.Errorf(`expected %s value should be one of ("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"). Current value is %v`, k, v)) + return + } + + return } -func flattenPGBackupWindowStart(t *timeofday.TimeOfDay) ([]interface{}, error) { +func flattenMDBBackupWindowStart(t *timeofday.TimeOfDay) []interface{} { if t == nil { - return nil, nil + return nil } out := map[string]interface{}{} @@ -20,5 +39,21 @@ func flattenPGBackupWindowStart(t *timeofday.TimeOfDay) ([]interface{}, error) { out["hours"] = int(t.Hours) out["minutes"] = int(t.Minutes) - return []interface{}{out}, nil + return []interface{}{out} +} + +func expandMDBBackupWindowStart(d *schema.ResourceData, path string) *timeofday.TimeOfDay { + out := &timeofday.TimeOfDay{} + hours := fmt.Sprintf(path + ".hours") + minutes := fmt.Sprintf(path + ".minutes") + + if v, ok := d.GetOk(hours); ok { + out.Hours = int32(v.(int)) + } + + if v, ok := d.GetOk(minutes); ok { + out.Minutes = int32(v.(int)) + } + + return out } diff --git a/yandex/resource_yandex_cdn_origin_group.go b/yandex/resource_yandex_cdn_origin_group.go index af93e1b34..a42583127 100644 --- a/yandex/resource_yandex_cdn_origin_group.go +++ b/yandex/resource_yandex_cdn_origin_group.go @@ -40,6 +40,8 @@ func resourceYandexCDNOriginGroup() *schema.Resource { "folder_id": { Type: schema.TypeString, Computed: true, + Optional: true, + ForceNew: true, }, "name": { Type: schema.TypeString, diff --git a/yandex/resource_yandex_cdn_origin_group_test.go b/yandex/resource_yandex_cdn_origin_group_test.go index 41384754c..6dd6c04cc 100644 --- a/yandex/resource_yandex_cdn_origin_group_test.go +++ b/yandex/resource_yandex_cdn_origin_group_test.go @@ -26,7 +26,7 @@ func init() { } func testAccCDNOriginsContainsSources(originGroup *cdn.OriginGroup, sources ...string) resource.TestCheckFunc { - return func(s *terraform.State) error { + return func(_ *terraform.State) error { if originGroup == nil { return fmt.Errorf("CDN Origin Group must exist") } @@ -96,6 +96,49 @@ func TestAccCDNOriginGroup_basic(t *testing.T) { }) } +func TestAccCDNOriginGroup_basicWithFolderID(t *testing.T) { + groupName := fmt.Sprintf("tf-test-cdn-origin-group-basic-%s", acctest.RandString(10)) + var originGroup cdn.OriginGroup + + folderID := getExampleFolderID() + + extractStringGroupID := func() string { + return strconv.FormatInt(originGroup.Id, 10) + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCDNOriginGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCDNOriginGroup_basicWithFolderID(groupName, folderID), + Check: resource.ComposeTestCheckFunc( + testOriginGroupExists("yandex_cdn_origin_group.test_cdn_group", &originGroup), + resource.TestCheckResourceAttr("yandex_cdn_origin_group.test_cdn_group", "name", groupName), + resource.TestCheckResourceAttr("yandex_cdn_origin_group.test_cdn_group", "folder_id", folderID), + resource.TestCheckResourceAttr("yandex_cdn_origin_group.test_cdn_group", "use_next", "true"), + testAccCDNOriginsContainsSources(&originGroup, + "ya.ru", + "yandex.ru", + "goo.gl", + "amazon.com", + ), + ), + }, + { + ResourceName: "yandex_cdn_origin_group.test_cdn_group", + ImportStateIdFunc: func(*terraform.State) (string, error) { + return extractStringGroupID(), nil + }, + ImportState: true, + ImportStateVerifyIgnore: []string{"origin"}, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccCDNOriginGroup_update(t *testing.T) { groupName := fmt.Sprintf("tf-test-cdn-origin-group-source-%s", acctest.RandString(10)) groupNameUpdated := fmt.Sprintf("tf-test-cdn-origin-group-target-%s", acctest.RandString(10)) @@ -262,6 +305,32 @@ resource "yandex_cdn_origin_group" "test_cdn_group" { `, groupName) } +func testAccCDNOriginGroup_basicWithFolderID(groupName, folderID string) string { + return fmt.Sprintf(` +resource "yandex_cdn_origin_group" "test_cdn_group" { + name = "%s" + folder_id = "%s" + + origin { + source = "ya.ru" + } + + origin { + source = "yandex.ru" + } + + origin { + source = "goo.gl" + } + + origin { + source = "amazon.com" + } +} + +`, groupName, folderID) +} + func testAccCDNOriginGroup_update(groupName string) string { return fmt.Sprintf(` resource "yandex_cdn_origin_group" "test_cdn_group" { diff --git a/yandex/resource_yandex_cdn_resource.go b/yandex/resource_yandex_cdn_resource.go index 66d4fbbdc..ccb0fe567 100644 --- a/yandex/resource_yandex_cdn_resource.go +++ b/yandex/resource_yandex_cdn_resource.go @@ -44,6 +44,8 @@ func defineYandexCDNResourceBaseSchema() *schema.Resource { "folder_id": { Type: schema.TypeString, Computed: true, + Optional: true, + ForceNew: true, }, "active": { Type: schema.TypeBool, diff --git a/yandex/resource_yandex_cdn_resource_test.go b/yandex/resource_yandex_cdn_resource_test.go index 895b981ac..4822ea589 100644 --- a/yandex/resource_yandex_cdn_resource_test.go +++ b/yandex/resource_yandex_cdn_resource_test.go @@ -94,6 +94,38 @@ func TestAccCDNResource_basicByName(t *testing.T) { }) } +func TestAccCDNResource_basicByNameWithFolderID(t *testing.T) { + t.Parallel() + + folderID := getExampleFolderID() + + groupName := fmt.Sprintf("tf-test-cdn-resource-%s", acctest.RandString(10)) + resourceCName := fmt.Sprintf("cdn-tf-test-%s.yandex.net", acctest.RandString(4)) + + var cdnResource cdn.Resource + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCDNResourceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCDNResource_basicByNameWithFolderID(groupName, resourceCName, folderID), + Check: resource.ComposeTestCheckFunc( + testCDNResourceExists("yandex_cdn_resource.foobar_resource", &cdnResource), + resource.TestCheckResourceAttr("yandex_cdn_resource.foobar_resource", "cname", resourceCName), + resource.TestCheckResourceAttr("yandex_cdn_resource.foobar_resource", "folder_id", folderID), + resource.TestCheckResourceAttr("yandex_cdn_resource.foobar_resource", "origin_protocol", "http"), + resource.TestCheckResourceAttr("yandex_cdn_resource.foobar_resource", "active", "true"), + resource.TestCheckResourceAttr("yandex_cdn_resource.foobar_resource", "secondary_hostnames.#", "0"), + resource.TestCheckResourceAttr("yandex_cdn_resource.foobar_resource", "ssl_certificate.0.type", "not_used"), + testAccCheckCreatedAtAttr("yandex_cdn_resource.foobar_resource"), + ), + }, + }, + }) +} + func TestAccCDNResource_basicUpdate(t *testing.T) { folderID := getExampleFolderID() @@ -676,6 +708,26 @@ resource "yandex_cdn_resource" "foobar_resource" { `, groupName, resourceCNAME) } +func testAccCDNResource_basicByNameWithFolderID(groupName, resourceCNAME, folderID string) string { + return fmt.Sprintf(` +resource "yandex_cdn_origin_group" "foo_cdn_group_by_name" { + name = "%s" + folder_id = "%s" + + origin { + source = "ya.ru" + } +} + +resource "yandex_cdn_resource" "foobar_resource" { + cname = "%s" + + origin_group_name = yandex_cdn_origin_group.foo_cdn_group_by_name.name +} + +`, groupName, folderID, resourceCNAME) +} + func testAccCDNResource_basicByID(groupName, resourceCNAME string) string { return fmt.Sprintf(` resource "yandex_cdn_origin_group" "foo_cdn_group_by_id" { diff --git a/yandex/resource_yandex_mdb_greenplum_cluster.go b/yandex/resource_yandex_mdb_greenplum_cluster.go index 41dbe5822..3dffffdfa 100644 --- a/yandex/resource_yandex_mdb_greenplum_cluster.go +++ b/yandex/resource_yandex_mdb_greenplum_cluster.go @@ -214,6 +214,31 @@ func resourceYandexMDBGreenplumCluster() *schema.Resource { Set: schema.HashString, Optional: true, }, + "maintenance_window": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"ANYTIME", "WEEKLY"}, false), + Required: true, + }, + "day": { + Type: schema.TypeString, + ValidateFunc: mdbMaintenanceWindowSchemaValidateFunc, + Optional: true, + }, + "hour": { + Type: schema.TypeInt, + ValidateFunc: validation.IntBetween(1, 24), + Optional: true, + }, + }, + }, + }, "deletion_protection": { Type: schema.TypeBool, Optional: true, @@ -356,14 +381,21 @@ func prepareCreateGreenplumClusterRequest(d *schema.ResourceData, meta *Config) return nil, fmt.Errorf("error while expanding config spec on Greenplum Cluster create: %s", err) } + maintenanceWindow, err := expandGreenplumMaintenanceWindow(d) + if err != nil { + return nil, fmt.Errorf("error while expanding maintenance_window on Greenplum Cluster create: %s", err) + } + return &greenplum.CreateClusterRequest{ - FolderId: folderID, - Name: d.Get("name").(string), - Description: d.Get("description").(string), - NetworkId: networkID, - Environment: env, - Labels: labels, - SecurityGroupIds: expandSecurityGroupIds(d.Get("security_group_ids")), + FolderId: folderID, + Name: d.Get("name").(string), + Description: d.Get("description").(string), + NetworkId: networkID, + Environment: env, + Labels: labels, + SecurityGroupIds: expandSecurityGroupIds(d.Get("security_group_ids")), + DeletionProtection: d.Get("deletion_protection").(bool), + MaintenanceWindow: maintenanceWindow, MasterHostCount: int64(d.Get("master_host_count").(int)), SegmentInHost: int64(d.Get("segment_in_host").(int)), @@ -480,7 +512,16 @@ func resourceYandexMDBGreenplumClusterRead(d *schema.ResourceData, meta interfac return err } - if err := d.Set("backup_window_start", flattenBackupWindowsStart(cluster.Config)); err != nil { + maintenanceWindow, err := flattenGreenplumMaintenanceWindow(cluster.MaintenanceWindow) + if err != nil { + return err + } + + if err := d.Set("maintenance_window", maintenanceWindow); err != nil { + return err + } + + if err := d.Set("backup_window_start", flattenMDBBackupWindowStart(cluster.Config.BackupWindowStart)); err != nil { return err } @@ -577,28 +618,51 @@ func prepareUpdateGreenplumClusterRequest(d *schema.ResourceData) (*greenplum.Up } labels, err := expandLabels(d.Get("labels")) if err != nil { - return nil, fmt.Errorf("error expanding labels while updating Greenplum cluster: %s", err) + return nil, fmt.Errorf("error while expanding labels on Greenplum cluster update: %s", err) } configSpec, settingNames, err := expandGreenplumConfigSpec(d) if err != nil { - return nil, fmt.Errorf("error while expanding config spec on Greenplum Cluster create: %s", err) + return nil, fmt.Errorf("error while expanding config spec on Greenplum Cluster update: %s", err) + } + + maintenanceWindow, err := expandGreenplumMaintenanceWindow(d) + if err != nil { + return nil, fmt.Errorf("error while expanding maintenance_window on Greenplum Cluster update: %s", err) } return &greenplum.UpdateClusterRequest{ ClusterId: d.Id(), Name: d.Get("name").(string), + UserPassword: d.Get("user_password").(string), Description: d.Get("description").(string), Labels: labels, + SecurityGroupIds: expandSecurityGroupIds(d.Get("security_group_ids")), DeletionProtection: d.Get("deletion_protection").(bool), + MaintenanceWindow: maintenanceWindow, + Config: &greenplum.GreenplumConfig{ Version: d.Get("version").(string), BackupWindowStart: expandGreenplumBackupWindowStart(d), Access: expandGreenplumAccess(d), }, - SecurityGroupIds: expandSecurityGroupIds(d.Get("security_group_ids")), - UpdateMask: &field_mask.FieldMask{Paths: expandGreenplumUpdatePath(d, settingNames)}, - ConfigSpec: configSpec, + MasterConfig: &greenplum.MasterSubclusterConfigSpec{ + Resources: &greenplum.Resources{ + ResourcePresetId: d.Get("master_subcluster.0.resources.0.resource_preset_id").(string), + DiskTypeId: d.Get("master_subcluster.0.resources.0.disk_type_id").(string), + DiskSize: toBytes(d.Get("master_subcluster.0.resources.0.disk_size").(int)), + }, + }, + SegmentConfig: &greenplum.SegmentSubclusterConfigSpec{ + Resources: &greenplum.Resources{ + ResourcePresetId: d.Get("segment_subcluster.0.resources.0.resource_preset_id").(string), + DiskTypeId: d.Get("segment_subcluster.0.resources.0.disk_type_id").(string), + DiskSize: toBytes(d.Get("segment_subcluster.0.resources.0.disk_size").(int)), + }, + }, + + UpdateMask: &field_mask.FieldMask{Paths: expandGreenplumUpdatePath(d, settingNames)}, + ConfigSpec: configSpec, }, nil } diff --git a/yandex/resource_yandex_mdb_greenplum_cluster_test.go b/yandex/resource_yandex_mdb_greenplum_cluster_test.go index e81b48605..7845a988d 100644 --- a/yandex/resource_yandex_mdb_greenplum_cluster_test.go +++ b/yandex/resource_yandex_mdb_greenplum_cluster_test.go @@ -122,12 +122,28 @@ func TestAccMDBGreenplumCluster_full(t *testing.T) { resource.TestCheckResourceAttr(greenplumResource, "greenplum_config.gp_workfile_limit_files_per_query", "100000"), resource.TestCheckResourceAttr(greenplumResource, "greenplum_config.max_prepared_transactions", "500"), resource.TestCheckResourceAttr(greenplumResource, "greenplum_config.gp_workfile_compression", "false"), + + resource.TestCheckResourceAttr(greenplumResource, "master_subcluster.0.resources.0.resource_preset_id", "s2.micro"), + resource.TestCheckResourceAttr(greenplumResource, "master_subcluster.0.resources.0.disk_size", "24"), + resource.TestCheckResourceAttr(greenplumResource, "master_subcluster.0.resources.0.disk_type_id", "network-ssd"), + resource.TestCheckResourceAttr(greenplumResource, "segment_subcluster.0.resources.0.resource_preset_id", "s2.micro"), + resource.TestCheckResourceAttr(greenplumResource, "segment_subcluster.0.resources.0.disk_size", "24"), + resource.TestCheckResourceAttr(greenplumResource, "segment_subcluster.0.resources.0.disk_type_id", "network-ssd"), + ), + }, + // Changing resource_preset_id + { + Config: testAccMDBGreenplumClusterConfigStep2(clusterName, clusterDescription), + Check: resource.ComposeTestCheckFunc( + testAccCheckMDBGreenplumClusterExists(greenplumResource, 2, 5), + resource.TestCheckResourceAttr(greenplumResource, "master_subcluster.0.resources.0.resource_preset_id", "s2.small"), + resource.TestCheckResourceAttr(greenplumResource, "segment_subcluster.0.resources.0.resource_preset_id", "s2.micro"), ), }, mdbGreenplumClusterImportStep(greenplumResource), // Update name and description of the cluster { - Config: testAccMDBGreenplumClusterConfigStep2(clusterNameUpdated, clusterDescriptionUpdated), + Config: testAccMDBGreenplumClusterConfigStep3(clusterNameUpdated, clusterDescriptionUpdated), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(greenplumResource, "name", clusterNameUpdated), resource.TestCheckResourceAttr(greenplumResource, "description", clusterDescriptionUpdated), @@ -136,7 +152,7 @@ func TestAccMDBGreenplumCluster_full(t *testing.T) { mdbGreenplumClusterImportStep(greenplumResource), // Update pooler_config and greenplum_config { - Config: testAccMDBGreenplumClusterConfigStep3(clusterNameUpdated, clusterDescriptionUpdated), + Config: testAccMDBGreenplumClusterConfigStep4(clusterNameUpdated, clusterDescriptionUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckMDBGreenplumClusterExists(greenplumResource, 2, 5), resource.TestCheckResourceAttr(greenplumResource, "greenplum_config.max_connections", "400"), @@ -149,7 +165,7 @@ func TestAccMDBGreenplumCluster_full(t *testing.T) { mdbGreenplumClusterImportStep(greenplumResource), // Update deletion_protection { - Config: testAccMDBGreenplumClusterConfigStep4(clusterNameUpdated, clusterDescriptionUpdated), + Config: testAccMDBGreenplumClusterConfigStep5(clusterNameUpdated, clusterDescriptionUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckMDBGreenplumClusterExists(greenplumResource, 2, 5), testAccCheckCreatedAtAttr(greenplumResource), @@ -159,12 +175,14 @@ func TestAccMDBGreenplumCluster_full(t *testing.T) { mdbGreenplumClusterImportStep(greenplumResource), // Add access and backup_window_start fields { - Config: testAccMDBGreenplumClusterConfigStep5(clusterNameUpdated, clusterDescriptionUpdated), + Config: testAccMDBGreenplumClusterConfigStep6(clusterNameUpdated, clusterDescriptionUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckMDBGreenplumClusterExists(greenplumResource, 2, 5), resource.TestCheckResourceAttr(greenplumResource, "access.0.data_lens", "true"), resource.TestCheckResourceAttr(greenplumResource, "backup_window_start.0.minutes", "15"), + resource.TestCheckResourceAttr(greenplumResource, "maintenance_window.0.day", "SAT"), + resource.TestCheckResourceAttr(greenplumResource, "maintenance_window.0.hour", "12"), resource.TestCheckResourceAttr(greenplumResource, "deletion_protection", "false"), ), }, @@ -273,7 +291,7 @@ resource "yandex_vpc_security_group" "mdb-greenplum-test-sg-x" { } ` -func testAccMDBGreenplumClusterConfigStep0(name string, description string) string { +func testAccMDBGreenplumClusterConfigStep0(name, description, resourcePresetId string) string { return fmt.Sprintf(greenplumVPCDependencies+` resource "yandex_mdb_greenplum_cluster" "foo" { name = "%s" @@ -293,7 +311,7 @@ resource "yandex_mdb_greenplum_cluster" "foo" { master_subcluster { resources { - resource_preset_id = "s2.micro" + resource_preset_id = "%s" disk_size = 24 disk_type_id = "network-ssd" } @@ -310,91 +328,112 @@ resource "yandex_mdb_greenplum_cluster" "foo" { user_password = "mysecurepassword" security_group_ids = [yandex_vpc_security_group.mdb-greenplum-test-sg-x.id] -`, name, description) +`, name, description, resourcePresetId) } func testAccMDBGreenplumClusterConfigStep1(name string, description string) string { - return testAccMDBGreenplumClusterConfigStep0(name, description) + ` + return testAccMDBGreenplumClusterConfigStep0(name, description, "s2.micro") + ` pooler_config { - pooling_mode = "TRANSACTION" - pool_size = 10 - pool_client_idle_timeout = 0 + pooling_mode = "TRANSACTION" + pool_size = 10 + pool_client_idle_timeout = 0 } greenplum_config = { - max_connections = 395 - max_slot_wal_keep_size = 1048576 - gp_workfile_limit_per_segment = 0 - gp_workfile_limit_per_query = 0 - gp_workfile_limit_files_per_query = 100000 - max_prepared_transactions = 500 - gp_workfile_compression = "false" + max_connections = 395 + max_slot_wal_keep_size = 1048576 + gp_workfile_limit_per_segment = 0 + gp_workfile_limit_per_query = 0 + gp_workfile_limit_files_per_query = 100000 + max_prepared_transactions = 500 + gp_workfile_compression = "false" } }` + } func testAccMDBGreenplumClusterConfigStep2(name string, description string) string { - return testAccMDBGreenplumClusterConfigStep1(name, description) + return testAccMDBGreenplumClusterConfigStep0(name, description, "s2.small") + ` + pooler_config { + pooling_mode = "TRANSACTION" + pool_size = 10 + pool_client_idle_timeout = 0 + } + + greenplum_config = { + max_connections = 395 + max_slot_wal_keep_size = 1048576 + gp_workfile_limit_per_segment = 0 + gp_workfile_limit_per_query = 0 + gp_workfile_limit_files_per_query = 100000 + max_prepared_transactions = 500 + gp_workfile_compression = "false" + } +}` } func testAccMDBGreenplumClusterConfigStep3(name string, description string) string { - return testAccMDBGreenplumClusterConfigStep0(name, description) + ` + return testAccMDBGreenplumClusterConfigStep2(name, description) +} + +func testAccMDBGreenplumClusterConfigStep4(name string, description string) string { + return testAccMDBGreenplumClusterConfigStep0(name, description, "s2.small") + ` pooler_config { - pooling_mode = "SESSION" - pool_size = 10 - pool_client_idle_timeout = 0 + pooling_mode = "SESSION" + pool_size = 10 + pool_client_idle_timeout = 0 } greenplum_config = { - max_connections = 400 - max_slot_wal_keep_size = 1048576 - gp_workfile_limit_per_segment = 0 - gp_workfile_limit_per_query = 0 - gp_workfile_limit_files_per_query = 100000 - max_prepared_transactions = 500 - gp_workfile_compression = "true" + max_connections = 400 + max_slot_wal_keep_size = 1048576 + gp_workfile_limit_per_segment = 0 + gp_workfile_limit_per_query = 0 + gp_workfile_limit_files_per_query = 100000 + max_prepared_transactions = 500 + gp_workfile_compression = "true" } }` } -func testAccMDBGreenplumClusterConfigStep4(name string, description string) string { - return testAccMDBGreenplumClusterConfigStep0(name, description) + ` +func testAccMDBGreenplumClusterConfigStep5(name string, description string) string { + return testAccMDBGreenplumClusterConfigStep0(name, description, "s2.small") + ` pooler_config { - pooling_mode = "SESSION" - pool_size = 10 - pool_client_idle_timeout = 0 + pooling_mode = "SESSION" + pool_size = 10 + pool_client_idle_timeout = 0 } greenplum_config = { - max_connections = 400 - max_slot_wal_keep_size = 1048576 - gp_workfile_limit_per_segment = 0 - gp_workfile_limit_per_query = 0 - gp_workfile_limit_files_per_query = 100000 - max_prepared_transactions = 500 - gp_workfile_compression = "true" + max_connections = 400 + max_slot_wal_keep_size = 1048576 + gp_workfile_limit_per_segment = 0 + gp_workfile_limit_per_query = 0 + gp_workfile_limit_files_per_query = 100000 + max_prepared_transactions = 500 + gp_workfile_compression = "true" } deletion_protection = true }` } -func testAccMDBGreenplumClusterConfigStep5(name string, description string) string { - return testAccMDBGreenplumClusterConfigStep0(name, description) + ` +func testAccMDBGreenplumClusterConfigStep6(name string, description string) string { + return testAccMDBGreenplumClusterConfigStep0(name, description, "s2.small") + ` pooler_config { - pooling_mode = "SESSION" - pool_size = 10 - pool_client_idle_timeout = 0 + pooling_mode = "SESSION" + pool_size = 10 + pool_client_idle_timeout = 0 } greenplum_config = { - max_connections = 400 - max_slot_wal_keep_size = 1048576 - gp_workfile_limit_per_segment = 0 - gp_workfile_limit_per_query = 0 - gp_workfile_limit_files_per_query = 100000 - max_prepared_transactions = 500 - gp_workfile_compression = "true" + max_connections = 400 + max_slot_wal_keep_size = 1048576 + gp_workfile_limit_per_segment = 0 + gp_workfile_limit_per_query = 0 + gp_workfile_limit_files_per_query = 100000 + max_prepared_transactions = 500 + gp_workfile_compression = "true" } deletion_protection = false @@ -407,5 +446,11 @@ func testAccMDBGreenplumClusterConfigStep5(name string, description string) stri hours = 22 minutes = 15 } + + maintenance_window { + type = "WEEKLY" + day = "SAT" + hour = 12 + } }` } diff --git a/yandex/resource_yandex_mdb_mysql_cluster.go b/yandex/resource_yandex_mdb_mysql_cluster.go index a6d9e9742..4a4a47b95 100644 --- a/yandex/resource_yandex_mdb_mysql_cluster.go +++ b/yandex/resource_yandex_mdb_mysql_cluster.go @@ -348,7 +348,7 @@ func resourceYandexMDBMySQLCluster() *schema.Resource { }, "day": { Type: schema.TypeString, - ValidateFunc: mysqlMaintenanceWindowSchemaValidateFunc, + ValidateFunc: mdbMaintenanceWindowSchemaValidateFunc, Optional: true, }, "hour": { @@ -680,10 +680,7 @@ func resourceYandexMDBMySQLClusterRead(d *schema.ResourceData, meta interface{}) return err } - backupWindowStart, err := flattenMysqlBackupWindowStart(cluster.GetConfig().GetBackupWindowStart()) - if err != nil { - return err - } + backupWindowStart := flattenMDBBackupWindowStart(cluster.GetConfig().GetBackupWindowStart()) if err := d.Set("backup_window_start", backupWindowStart); err != nil { return err } diff --git a/yandex/resource_yandex_mdb_postgresql_cluster.go b/yandex/resource_yandex_mdb_postgresql_cluster.go index 21850138b..0c188bda1 100644 --- a/yandex/resource_yandex_mdb_postgresql_cluster.go +++ b/yandex/resource_yandex_mdb_postgresql_cluster.go @@ -467,7 +467,7 @@ func resourceYandexMDBPostgreSQLClusterMaintenanceWindow() *schema.Resource { }, "day": { Type: schema.TypeString, - ValidateFunc: pgMaintenanceWindowSchemaValidateFunc, + ValidateFunc: mdbMaintenanceWindowSchemaValidateFunc, Optional: true, }, "hour": { diff --git a/yandex/resource_yandex_mdb_sqlserver_cluster.go b/yandex/resource_yandex_mdb_sqlserver_cluster.go index ddc9fb359..cb989b768 100644 --- a/yandex/resource_yandex_mdb_sqlserver_cluster.go +++ b/yandex/resource_yandex_mdb_sqlserver_cluster.go @@ -295,7 +295,7 @@ func prepareCreateSQLServerRequest(d *schema.ResourceData, meta *Config) (*sqlse return nil, fmt.Errorf("Error resolving environment while creating SQLServer Cluster: %s", err) } - backupWindowStart := expandSQLServerBackupWindowStart(d) + backupWindowStart := expandMDBBackupWindowStart(d, "backup_window_start.0") resources := expandSQLServerResources(d) @@ -425,10 +425,7 @@ func resourceYandexMDBSQLServerClusterRead(d *schema.ResourceData, meta interfac return err } - backupWindowStart, err := flattenSQLServerBackupWindowStart(cluster.GetConfig().GetBackupWindowStart()) - if err != nil { - return err - } + backupWindowStart := flattenMDBBackupWindowStart(cluster.GetConfig().GetBackupWindowStart()) if err = d.Set("backup_window_start", backupWindowStart); err != nil { return err } @@ -588,14 +585,11 @@ func sqlserverClusterUpdate(ctx context.Context, config *Config, d *schema.Resou Labels: labels, SecurityGroupIds: securityGroupIds, DeletionProtection: d.Get("deletion_protection").(bool), - } - - resources := expandSQLServerResources(d) - backupWindowStart := expandSQLServerBackupWindowStart(d) - req.ConfigSpec = &sqlserver.ConfigSpec{ - Resources: resources, - Version: d.Get("version").(string), - BackupWindowStart: backupWindowStart, + ConfigSpec: &sqlserver.ConfigSpec{ + Resources: expandSQLServerResources(d), + Version: d.Get("version").(string), + BackupWindowStart: expandMDBBackupWindowStart(d, "backup_window_start.0"), + }, } updateFieldConfigName, fields, err := expandSQLServerConfigSpecSettings(d, req.ConfigSpec)