diff --git a/common/common_volcengine_version.go b/common/common_volcengine_version.go index 2a6ac8f9..18733be1 100644 --- a/common/common_volcengine_version.go +++ b/common/common_volcengine_version.go @@ -2,5 +2,5 @@ package common const ( TerraformProviderName = "terraform-provider-volcengine" - TerraformProviderVersion = "0.0.137" + TerraformProviderVersion = "0.0.138" ) diff --git a/docgen/main.go b/docgen/main.go index 4fb5dfe7..6c1e4cfa 100644 --- a/docgen/main.go +++ b/docgen/main.go @@ -153,6 +153,7 @@ var resourceKeys = map[string]string{ "alb": "ALB", "bandwidth_package": "BANDWIDTH_PACKAGE", "cloud_monitor": "CLOUD_MONITOR", + "rds_mssql": "RDS_MSSQL", } type Products struct { diff --git a/example/dataRdsMssqlBackups/main.tf b/example/dataRdsMssqlBackups/main.tf new file mode 100644 index 00000000..28e416b1 --- /dev/null +++ b/example/dataRdsMssqlBackups/main.tf @@ -0,0 +1,3 @@ +data "volcengine_rds_mssql_backups" "foo" { + instance_id = "mssql-40914121fd22" +} \ No newline at end of file diff --git a/example/dataRdsMssqlInstances/main.tf b/example/dataRdsMssqlInstances/main.tf new file mode 100644 index 00000000..1af3a953 --- /dev/null +++ b/example/dataRdsMssqlInstances/main.tf @@ -0,0 +1,3 @@ +data "volcengine_rds_mssql_instances" "foo" { + instance_id = "mssql-d2fc5abe****" +} diff --git a/example/dataRdsMssqlRegions/main.tf b/example/dataRdsMssqlRegions/main.tf new file mode 100644 index 00000000..14749163 --- /dev/null +++ b/example/dataRdsMssqlRegions/main.tf @@ -0,0 +1,2 @@ +data "volcengine_rds_mssql_regions" "foo"{ +} diff --git a/example/dataRdsMssqlZones/main.tf b/example/dataRdsMssqlZones/main.tf new file mode 100644 index 00000000..787acd7b --- /dev/null +++ b/example/dataRdsMssqlZones/main.tf @@ -0,0 +1,3 @@ +data "volcengine_rds_mssql_zones" "foo"{ + +} diff --git a/example/rdsMssqlBackup/main.tf b/example/rdsMssqlBackup/main.tf new file mode 100644 index 00000000..e77c02f9 --- /dev/null +++ b/example/rdsMssqlBackup/main.tf @@ -0,0 +1,3 @@ +resource "volcengine_rds_mssql_backup" "foo" { + instance_id = "mssql-40914121fd22" +} \ No newline at end of file diff --git a/example/rdsMssqlInstance/main.tf b/example/rdsMssqlInstance/main.tf new file mode 100644 index 00000000..3bb49008 --- /dev/null +++ b/example/rdsMssqlInstance/main.tf @@ -0,0 +1,36 @@ +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mssql_instance" "foo" { + db_engine_version = "SQLServer_2019_Std" + instance_type = "HA" + node_spec = "rds.mssql.se.ha.d2.2c4g" + storage_space = 20 + subnet_id = [volcengine_subnet.foo.id] + super_account_password = "Tftest110" + instance_name = "acc-test-mssql" + project_name = "default" + charge_info { + charge_type = "PostPaid" + } + tags { + key = "k1" + value = "v1" + } + + backup_time = "18:00Z-19:00Z" + full_backup_period = ["Monday", "Tuesday"] + backup_retention_period = 14 +} diff --git a/volcengine/provider.go b/volcengine/provider.go index 9d5181bf..a3393787 100644 --- a/volcengine/provider.go +++ b/volcengine/provider.go @@ -7,6 +7,9 @@ import ( "github.com/volcengine/terraform-provider-volcengine/volcengine/alb/alb_server_group" "github.com/volcengine/terraform-provider-volcengine/volcengine/alb/alb_server_group_server" "github.com/volcengine/terraform-provider-volcengine/volcengine/alb/alb_zone" + mssqlBackup "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mssql/rds_mssql_backup" + mssqlInstance "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mssql/rds_mssql_instance" + "github.com/volcengine/terraform-provider-volcengine/volcengine/cen/cen_service_route_entry" "github.com/volcengine/terraform-provider-volcengine/volcengine/cloud_monitor/cloud_monitor_contact" "github.com/volcengine/terraform-provider-volcengine/volcengine/cloud_monitor/cloud_monitor_contact_group" @@ -23,6 +26,8 @@ import ( "github.com/volcengine/terraform-provider-volcengine/volcengine/nas/nas_region" "github.com/volcengine/terraform-provider-volcengine/volcengine/nas/nas_snapshot" "github.com/volcengine/terraform-provider-volcengine/volcengine/nas/nas_zone" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mssql/rds_mssql_region" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mssql/rds_mssql_zone" trEntry "github.com/volcengine/terraform-provider-volcengine/volcengine/transit_router/route_entry" trTable "github.com/volcengine/terraform-provider-volcengine/volcengine/transit_router/route_table" "github.com/volcengine/terraform-provider-volcengine/volcengine/transit_router/route_table_association" @@ -525,6 +530,12 @@ func Provider() terraform.ResourceProvider { "volcengine_cloud_monitor_contact_groups": cloud_monitor_contact_group.DataSourceVolcengineCloudMonitorContactGroups(), "volcengine_cloud_monitor_event_rules": cloud_monitor_event_rule.DataSourceVolcengineCloudMonitorEventRules(), "volcengine_cloud_monitor_rules": cloud_monitor_rule.DataSourceVolcengineCloudMonitorRules(), + + // ================ RdsMssql ================ + "volcengine_rds_mssql_regions": rds_mssql_region.DataSourceVolcengineRdsMssqlRegions(), + "volcengine_rds_mssql_zones": rds_mssql_zone.DataSourceVolcengineRdsMssqlZones(), + "volcengine_rds_mssql_instances": mssqlInstance.DataSourceVolcengineRdsMssqlInstances(), + "volcengine_rds_mssql_backups": mssqlBackup.DataSourceVolcengineRdsMssqlBackups(), }, ResourcesMap: map[string]*schema.Resource{ "volcengine_vpc": vpc.ResourceVolcengineVpc(), @@ -767,6 +778,10 @@ func Provider() terraform.ResourceProvider { "volcengine_cloud_monitor_contact_group": cloud_monitor_contact_group.ResourceVolcengineCloudMonitorContactGroup(), "volcengine_cloud_monitor_event_rule": cloud_monitor_event_rule.ResourceVolcengineCloudMonitorEventRule(), "volcengine_cloud_monitor_rule": cloud_monitor_rule.ResourceVolcengineCloudMonitorRule(), + + // ================ RdsMssql ================ + "volcengine_rds_mssql_instance": mssqlInstance.ResourceVolcengineRdsMssqlInstance(), + "volcengine_rds_mssql_backup": mssqlBackup.ResourceVolcengineRdsMssqlBackup(), }, ConfigureFunc: ProviderConfigure, } diff --git a/volcengine/rds_mssql/rds_mssql_backup/data_source_volcengine_rds_mssql_backups.go b/volcengine/rds_mssql/rds_mssql_backup/data_source_volcengine_rds_mssql_backups.go new file mode 100644 index 00000000..4893b55a --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_backup/data_source_volcengine_rds_mssql_backups.go @@ -0,0 +1,172 @@ +package sqlserver_backup + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" +) + +func DataSourceVolcengineRdsMssqlBackups() *schema.Resource { + return &schema.Resource{ + Read: dataSourceVolcengineMssqlBackupsRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + Description: "The id of the instance.", + }, + "backup_id": { + Type: schema.TypeString, + Optional: true, + Description: "The id of the backup.", + }, + "backup_start_time": { + Type: schema.TypeString, + Optional: true, + Description: "The start time of the backup.", + }, + "backup_end_time": { + Type: schema.TypeString, + Optional: true, + Description: "The end time of the backup.", + }, + "backup_type": { + Type: schema.TypeString, + Optional: true, + Description: "The type of the backup.", + }, + "output_file": { + Type: schema.TypeString, + Optional: true, + Description: "File name where to save data source results.", + }, + "total_count": { + Type: schema.TypeInt, + Computed: true, + Description: "The total count of query.", + }, + "backups": { + Description: "The collection of query.", + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + Description: "The id of the backup.", + }, + "backup_id": { + Type: schema.TypeString, + Computed: true, + Description: "The id of the backup.", + }, + "backup_start_time": { + Type: schema.TypeString, + Computed: true, + Description: "The start time of the backup.", + }, + "backup_end_time": { + Type: schema.TypeString, + Computed: true, + Description: "The end time of the backup.", + }, + "backup_type": { + Type: schema.TypeString, + Computed: true, + Description: "The type of the backup.", + }, + "backup_file_size": { + Type: schema.TypeInt, + Computed: true, + Description: "The size of the backup file.", + }, + "backup_method": { + Type: schema.TypeString, + Computed: true, + Description: "The name of the backup method.", + }, + "backup_status": { + Type: schema.TypeString, + Computed: true, + Description: "The status of the backup.", + }, + "create_type": { + Type: schema.TypeString, + Computed: true, + Description: "The type of the backup create.", + }, + "backup_database_detail": { + Type: schema.TypeList, + Computed: true, + Description: "The detail of the database.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backup_start_time": { + Type: schema.TypeString, + Computed: true, + Description: "The start time of the backup.", + }, + "backup_end_time": { + Type: schema.TypeString, + Computed: true, + Description: "The end time of the backup.", + }, + "backup_type": { + Type: schema.TypeString, + Computed: true, + Description: "The type of the backup.", + }, + "backup_file_size": { + Type: schema.TypeInt, + Computed: true, + Description: "The size of the backup file.", + }, + "backup_file_name": { + Type: schema.TypeString, + Computed: true, + Description: "The name of the backup file.", + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + Description: "The name of the database.", + }, + "backup_download_link_inner": { + Type: schema.TypeString, + Computed: true, + Description: "Intranet backup download link.", + }, + "backup_download_link_eip": { + Type: schema.TypeString, + Computed: true, + Description: "External backup download link.", + }, + "link_expired_time": { + Type: schema.TypeString, + Computed: true, + Description: "Download link expiration time.", + }, + "download_progress": { + Type: schema.TypeInt, + Computed: true, + Description: "Backup file preparation progress, unit: %.", + }, + "download_status": { + Type: schema.TypeString, + Computed: true, + Description: "Download status.", + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func dataSourceVolcengineMssqlBackupsRead(d *schema.ResourceData, meta interface{}) error { + service := NewRdsMssqlBackupService(meta.(*ve.SdkClient)) + return service.Dispatcher.Data(service, d, DataSourceVolcengineRdsMssqlBackups()) +} diff --git a/volcengine/rds_mssql/rds_mssql_backup/resource_volcengine_rds_mssql_backup.go b/volcengine/rds_mssql/rds_mssql_backup/resource_volcengine_rds_mssql_backup.go new file mode 100644 index 00000000..c36501dd --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_backup/resource_volcengine_rds_mssql_backup.go @@ -0,0 +1,111 @@ +package sqlserver_backup + +import ( + "fmt" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" +) + +/* + +Import +Rds Mssql Backup can be imported using the id, e.g. +``` +$ terraform import volcengine_rds_mssql_backup.default instanceId:backupId +``` + +*/ + +func ResourceVolcengineRdsMssqlBackup() *schema.Resource { + resource := &schema.Resource{ + Create: resourceVolcengineRdsMssqlBackupCreate, + Read: resourceVolcengineRdsMssqlBackupRead, + Delete: resourceVolcengineRdsMssqlBackupDelete, + Importer: &schema.ResourceImporter{ + State: func(data *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) { + items := strings.Split(data.Id(), ":") + if len(items) != 2 { + return []*schema.ResourceData{data}, fmt.Errorf("import id must split with ':'") + } + if err := data.Set("instance_id", items[0]); err != nil { + return []*schema.ResourceData{data}, err + } + if err := data.Set("backup_id", items[1]); err != nil { + return []*schema.ResourceData{data}, err + } + return []*schema.ResourceData{data}, nil + }, + }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(60 * time.Minute), + Delete: schema.DefaultTimeout(60 * time.Minute), + }, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The id of the instance.", + }, + "backup_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + Description: "Backup type. Currently only supports full backup, with a value of Full (default).", + }, + "backup_meta": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Description: "Backup repository information. When importing resources, this attribute will not be imported. If this attribute is set, please use lifecycle and ignore_changes ignore changes in fields.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "db_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The name of the database.", + }, + }, + }, + }, + "backup_id": { + Type: schema.TypeString, + Computed: true, + Description: "The ID of the backup.", + }, + }, + } + return resource +} + +func resourceVolcengineRdsMssqlBackupCreate(d *schema.ResourceData, meta interface{}) (err error) { + service := NewRdsMssqlBackupService(meta.(*ve.SdkClient)) + err = service.Dispatcher.Create(service, d, ResourceVolcengineRdsMssqlBackup()) + if err != nil { + return fmt.Errorf("error on creating rds_mssql_backup %q, %s", d.Id(), err) + } + return resourceVolcengineRdsMssqlBackupRead(d, meta) +} + +func resourceVolcengineRdsMssqlBackupRead(d *schema.ResourceData, meta interface{}) (err error) { + service := NewRdsMssqlBackupService(meta.(*ve.SdkClient)) + err = service.Dispatcher.Read(service, d, ResourceVolcengineRdsMssqlBackup()) + if err != nil { + return fmt.Errorf("error on reading rds_mssql_backup %q, %s", d.Id(), err) + } + return err +} + +func resourceVolcengineRdsMssqlBackupDelete(d *schema.ResourceData, meta interface{}) (err error) { + service := NewRdsMssqlBackupService(meta.(*ve.SdkClient)) + err = service.Dispatcher.Delete(service, d, ResourceVolcengineRdsMssqlBackup()) + if err != nil { + return fmt.Errorf("error on deleting rds_mssql_backup %q, %s", d.Id(), err) + } + return err +} diff --git a/volcengine/rds_mssql/rds_mssql_backup/service_volcengine_rds_mssql_backup.go b/volcengine/rds_mssql/rds_mssql_backup/service_volcengine_rds_mssql_backup.go new file mode 100644 index 00000000..b35d7ba1 --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_backup/service_volcengine_rds_mssql_backup.go @@ -0,0 +1,259 @@ +package sqlserver_backup + +import ( + "encoding/json" + "errors" + "fmt" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/logger" + + sqlserver "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mssql/rds_mssql_instance" +) + +type VolcengineRdsMssqlBackupService struct { + Client *ve.SdkClient + Dispatcher *ve.Dispatcher +} + +func NewRdsMssqlBackupService(c *ve.SdkClient) *VolcengineRdsMssqlBackupService { + return &VolcengineRdsMssqlBackupService{ + Client: c, + Dispatcher: &ve.Dispatcher{}, + } +} + +func (s *VolcengineRdsMssqlBackupService) GetClient() *ve.SdkClient { + return s.Client +} + +func (s *VolcengineRdsMssqlBackupService) ReadResources(m map[string]interface{}) (data []interface{}, err error) { + var ( + resp *map[string]interface{} + results interface{} + ok bool + ) + return ve.WithPageNumberQuery(m, "PageSize", "PageNumber", 100, 1, func(condition map[string]interface{}) ([]interface{}, error) { + action := "DescribeBackups" + + bytes, _ := json.Marshal(condition) + logger.Debug(logger.ReqFormat, action, string(bytes)) + if condition == nil { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), nil) + if err != nil { + return data, err + } + } else { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), &condition) + if err != nil { + return data, err + } + } + respBytes, _ := json.Marshal(resp) + logger.Debug(logger.RespFormat, action, condition, string(respBytes)) + results, err = ve.ObtainSdkValue("Result.BackupsInfo", *resp) + if err != nil { + return data, err + } + if results == nil { + results = []interface{}{} + } + if data, ok = results.([]interface{}); !ok { + return data, errors.New("Result.BackupsInfo is not Slice") + } + return data, err + }) +} + +func (s *VolcengineRdsMssqlBackupService) ReadResource(resourceData *schema.ResourceData, id string) (data map[string]interface{}, err error) { + var ( + results []interface{} + ok bool + ) + if id == "" { + id = s.ReadResourceId(resourceData.Id()) + } + ids := strings.Split(id, ":") + req := map[string]interface{}{ + "InstanceId": ids[0], + "BackupId": ids[1], + } + results, err = s.ReadResources(req) + if err != nil { + return data, err + } + for _, v := range results { + if data, ok = v.(map[string]interface{}); !ok { + return data, errors.New("Value is not map ") + } + } + if len(data) == 0 { + return data, fmt.Errorf("rds_mssql_backup %s not exist ", id) + } + return data, err +} + +func (s *VolcengineRdsMssqlBackupService) RefreshResourceState(resourceData *schema.ResourceData, target []string, timeout time.Duration, id string) *resource.StateChangeConf { + return &resource.StateChangeConf{ + Pending: []string{}, + Delay: 1 * time.Second, + MinTimeout: 1 * time.Second, + Target: target, + Timeout: timeout, + Refresh: func() (result interface{}, state string, err error) { + var ( + demo map[string]interface{} + status interface{} + failStates []string + ) + failStates = append(failStates, "Error", "Failed") + + // 可能查询不到 + if err = resource.Retry(20*time.Minute, func() *resource.RetryError { + demo, err = s.ReadResource(resourceData, id) + if err != nil { + if ve.ResourceNotFoundError(err) { + return resource.RetryableError(err) + } else { + return resource.NonRetryableError(err) + } + } + return nil + }); err != nil { + return nil, "", err + } + + demo, err = s.ReadResource(resourceData, id) + if err != nil { + return nil, "", err + } + status, err = ve.ObtainSdkValue("BackupStatus", demo) + if err != nil { + return nil, "", err + } + for _, v := range failStates { + if v == status.(string) { + return nil, "", fmt.Errorf("Backup status error, status:%s ", status.(string)) + } + } + //注意 返回的第一个参数不能为空 否则会一直等下去 + return demo, status.(string), err + }, + } +} + +func (s *VolcengineRdsMssqlBackupService) CreateResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { + callback := ve.Callback{ + Call: ve.SdkCall{ + Action: "CreateBackup", + ConvertMode: ve.RequestConvertAll, + ContentType: ve.ContentTypeJson, + Convert: map[string]ve.RequestConvert{ + "backup_meta": { + TargetField: "BackupMeta", + ConvertType: ve.ConvertJsonObjectArray, + NextLevelConvert: map[string]ve.RequestConvert{ + "db_name": { + TargetField: "DBName", + }, + }, + }, + }, + ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.RespFormat, call.Action, call.SdkParam) + resp, err := s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + logger.Debug(logger.RespFormat, call.Action, resp, err) + return resp, err + }, + AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error { + instanceId := (*call.SdkParam)["InstanceId"] + backupId, _ := ve.ObtainSdkValue("Result.BackupId", *resp) + d.SetId(fmt.Sprintf("%s:%s", instanceId, backupId)) + return nil + }, + Refresh: &ve.StateRefresh{ + Target: []string{"Success"}, + Timeout: resourceData.Timeout(schema.TimeoutCreate), + }, + LockId: func(d *schema.ResourceData) string { + return d.Get("instance_id").(string) + }, + ExtraRefresh: map[ve.ResourceService]*ve.StateRefresh{ + sqlserver.NewRdsMssqlInstanceService(s.Client): { + Target: []string{"Running"}, + Timeout: resourceData.Timeout(schema.TimeoutCreate), + ResourceId: resourceData.Get("instance_id").(string), + }, + }, + }, + } + return []ve.Callback{callback} +} + +func (VolcengineRdsMssqlBackupService) WithResourceResponseHandlers(d map[string]interface{}) []ve.ResourceResponseHandler { + handler := func() (map[string]interface{}, map[string]ve.ResponseConvert, error) { + return d, nil, nil + } + return []ve.ResourceResponseHandler{handler} +} + +func (s *VolcengineRdsMssqlBackupService) ModifyResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { + return []ve.Callback{} +} + +func (s *VolcengineRdsMssqlBackupService) RemoveResource(resourceData *schema.ResourceData, r *schema.Resource) []ve.Callback { + ids := strings.Split(resourceData.Id(), ":") + callback := ve.Callback{ + Call: ve.SdkCall{ + Action: "DeleteBackup", + ConvertMode: ve.RequestConvertIgnore, + ContentType: ve.ContentTypeJson, + SdkParam: &map[string]interface{}{ + "InstanceId": ids[0], + "BackupId": ids[1], + }, + ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.RespFormat, call.Action, call.SdkParam) + return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + }, + AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error { + return ve.CheckResourceUtilRemoved(d, s.ReadResource, 5*time.Minute) + }, + }, + } + return []ve.Callback{callback} +} + +func (s *VolcengineRdsMssqlBackupService) DatasourceResources(*schema.ResourceData, *schema.Resource) ve.DataSourceInfo { + return ve.DataSourceInfo{ + IdField: "BackupId", + CollectField: "backups", + ResponseConverts: map[string]ve.ResponseConvert{ + "BackupId": { + TargetField: "id", + KeepDefault: true, + }, + "BackupDownloadLinkEIP": { + TargetField: "backup_download_link_eip", + }, + }, + } +} + +func (s *VolcengineRdsMssqlBackupService) ReadResourceId(id string) string { + return id +} + +func getUniversalInfo(actionName string) ve.UniversalInfo { + return ve.UniversalInfo{ + ServiceName: "rds_mssql", + Version: "2022-01-01", + HttpMethod: ve.POST, + ContentType: ve.ApplicationJSON, + Action: actionName, + } +} diff --git a/volcengine/rds_mssql/rds_mssql_instance/data_source_volcengine_rds_mssql_instances.go b/volcengine/rds_mssql/rds_mssql_instance/data_source_volcengine_rds_mssql_instances.go new file mode 100644 index 00000000..3dd9aa33 --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_instance/data_source_volcengine_rds_mssql_instances.go @@ -0,0 +1,487 @@ +package sqlserver_instance + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + ve "github.com/volcengine/terraform-provider-volcengine/common" +) + +func DataSourceVolcengineRdsMssqlInstances() *schema.Resource { + return &schema.Resource{ + Read: dataSourceVolcengineSqlserverInstancesRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Optional: true, + Description: "Id of the instance.", + }, + "instance_name": { + Type: schema.TypeString, + Optional: true, + Description: "Name of the instance.", + }, + "instance_status": { + Type: schema.TypeString, + Optional: true, + Description: "Status of the instance.", + }, + "db_engine_version": { + Type: schema.TypeString, + Optional: true, + Description: "Compatible version. Valid values: `SQLServer_2019_Std`, `SQLServer_2019_Web`, `SQLServer_2019_Ent`.", + }, + "instance_type": { + Type: schema.TypeString, + Optional: true, + Description: "Instance type. Valid values: `HA`, `Basic`, `Cluster`.", + }, + "create_time_start": { + Type: schema.TypeString, + Optional: true, + Description: "The start time of creating the instance, using UTC time format.", + }, + "create_time_end": { + Type: schema.TypeString, + Optional: true, + Description: "The end time of creating the instance, using UTC time format.", + }, + "zone_id": { + Type: schema.TypeString, + Optional: true, + Description: "The id of the zone.", + }, + "charge_type": { + Type: schema.TypeString, + Optional: true, + Description: "The charge type. Valid values: `PostPaid`, `PrePaid`.", + }, + "tags": ve.TagsSchema(), + "name_regex": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringIsValidRegExp, + Description: "A Name Regex of RDS mssql instance.", + }, + "output_file": { + Type: schema.TypeString, + Optional: true, + Description: "File name where to save data source results.", + }, + "total_count": { + Type: schema.TypeInt, + Computed: true, + Description: "The total count of query.", + }, + "instances": { + Description: "The collection of query.", + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + Description: "The id of the instance.", + }, + "db_engine_version": { + Type: schema.TypeString, + Computed: true, + Description: "The db engine version.", + }, + "instance_id": { + Type: schema.TypeString, + Computed: true, + Description: "The id of the instance.", + }, + "instance_name": { + Type: schema.TypeString, + Computed: true, + Description: "The name of the instance.", + }, + "instance_status": { + Type: schema.TypeString, + Computed: true, + Description: "The status of the instance.", + }, + "instance_type": { + Type: schema.TypeString, + Computed: true, + Description: "The type of the instance.", + }, + "node_spec": { + Type: schema.TypeString, + Computed: true, + Description: "The node spec.", + }, + "port": { + Type: schema.TypeString, + Computed: true, + Description: "The port of the instance.", + }, + "project_name": { + Type: schema.TypeString, + Computed: true, + Description: "The project name.", + }, + "region_id": { + Type: schema.TypeString, + Computed: true, + Description: "The region id.", + }, + "server_collation": { + Type: schema.TypeString, + Computed: true, + Description: "Server sorting rules.", + }, + "storage_space": { + Type: schema.TypeInt, + Computed: true, + Description: "The storage space.", + }, + "storage_type": { + Type: schema.TypeString, + Computed: true, + Description: "The storage type.", + }, + "storage_use": { + Type: schema.TypeFloat, + Computed: true, + Description: "The used storage space.", + }, + "subnet_id": { + Type: schema.TypeString, + Computed: true, + Description: "The subnet id.", + }, + "time_zone": { + Type: schema.TypeString, + Computed: true, + Description: "The time zone.", + }, + "vpc_id": { + Type: schema.TypeString, + Computed: true, + Description: "The vpc id.", + }, + "zone_id": { + Type: schema.TypeString, + Computed: true, + Description: "The zone id.", + }, + "instance_category": { + Type: schema.TypeString, + Computed: true, + Description: "The instance category.", + }, + "primary_instance_id": { + Type: schema.TypeString, + Computed: true, + Description: "The id of the primary instance.", + }, + "read_only_number": { + Type: schema.TypeInt, + Computed: true, + Description: "The number of read only instance.", + }, + "backup_use": { + Type: schema.TypeFloat, + Computed: true, + Description: "The used backup space of the instance. Unit: GiB.", + }, + "inner_version": { + Type: schema.TypeString, + Computed: true, + Description: "The inner version of the instance.", + }, + "memory": { + Type: schema.TypeInt, + Computed: true, + Description: "The Memory of the instance. Unit: GiB.", + }, + "slow_query_enable": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether to enable slow query function.", + }, + "slow_query_time": { + Type: schema.TypeString, + Computed: true, + Description: "The slow query time. Unit: second.", + }, + "v_cpu": { + Type: schema.TypeInt, + Computed: true, + Description: "The CPU size of the instance. For example: 1 represents 1U.", + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: "The creation time of the instance.", + }, + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: "The update time of the instance.", + }, + "tags": ve.TagsSchemaComputed(), + "charge_detail": { + Type: schema.TypeList, + Computed: true, + Description: "The charge detail.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "charge_type": { + Type: schema.TypeString, + Computed: true, + Description: "The charge type.", + }, + "auto_renew": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether to enable automatic renewal in the prepaid scenario. This parameter can be set when ChargeType is Prepaid.", + }, + "period_unit": { + Type: schema.TypeString, + Computed: true, + Description: "Purchase cycle in prepaid scenarios. This parameter can be set when ChargeType is Prepaid.", + }, + "period": { + Type: schema.TypeInt, + Computed: true, + Description: "Purchase duration in a prepaid scenario.", + }, + "charge_start_time": { + Type: schema.TypeString, + Computed: true, + Description: "Charge start time.", + }, + "charge_end_time": { + Type: schema.TypeString, + Computed: true, + Description: "Charge end time.", + }, + "charge_status": { + Type: schema.TypeString, + Computed: true, + Description: "The charge status.", + }, + "overdue_reclaim_time": { + Type: schema.TypeString, + Computed: true, + Description: "Expected release time when overdue fees are shut down.", + }, + "overdue_time": { + Type: schema.TypeString, + Computed: true, + Description: "Time for Disconnection due to Unpaid Fees.", + }, + }, + }, + }, + "node_detail_info": { + Type: schema.TypeList, + Computed: true, + Description: "Node detail information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Computed: true, + Description: "Instance ID.", + }, + "memory": { + Type: schema.TypeInt, + Computed: true, + Description: "The Memory.", + }, + "node_id": { + Type: schema.TypeString, + Computed: true, + Description: "The Node ID.", + }, + "node_spec": { + Type: schema.TypeString, + Computed: true, + Description: "The node spec.", + }, + "node_status": { + Type: schema.TypeString, + Computed: true, + Description: "The node status.", + }, + "node_type": { + Type: schema.TypeString, + Computed: true, + Description: "The node type.", + }, + "region_id": { + Type: schema.TypeString, + Computed: true, + Description: "The region id.", + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: "Node creation time.", + }, + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: "The update time.", + }, + "v_cpu": { + Type: schema.TypeInt, + Computed: true, + Description: "CPU size. For example: 1 represents 1U.", + }, + "zone_id": { + Type: schema.TypeString, + Computed: true, + Description: "The zone id.", + }, + "node_ip": { + Type: schema.TypeString, + Computed: true, + Description: "The node ip.", + }, + }, + }, + }, + "connection_info": { + Type: schema.TypeList, + Computed: true, + Description: "The connection info of the instance.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "endpoint_id": { + Type: schema.TypeString, + Computed: true, + Description: "The endpoint id.", + }, + "endpoint_name": { + Type: schema.TypeString, + Computed: true, + Description: "The endpoint name.", + }, + "endpoint_type": { + Type: schema.TypeString, + Computed: true, + Description: "The endpoint type.", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "The description.", + }, + "address": { + Type: schema.TypeList, + Computed: true, + Description: "The address info.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dns_visibility": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether to enable private to public network resolution.", + }, + "domain": { + Type: schema.TypeString, + Computed: true, + Description: "The domain.", + }, + "eip_id": { + Type: schema.TypeString, + Computed: true, + Description: "The eip id for public address.", + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + Description: "The ip address.", + }, + "network_type": { + Type: schema.TypeString, + Computed: true, + Description: "The network type.", + }, + "port": { + Type: schema.TypeString, + Computed: true, + Description: "The port.", + }, + "subnet_id": { + Type: schema.TypeString, + Computed: true, + Description: "The subnet id for private address.", + }, + }, + }, + }, + }, + }, + }, + "parameter_count": { + Type: schema.TypeInt, + Computed: true, + Description: "The count of instance parameters.", + }, + "parameters": { + Type: schema.TypeList, + Computed: true, + Description: "The list of instance parameters.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "parameter_name": { + Type: schema.TypeString, + Computed: true, + Description: "The name of the parameter.", + }, + "parameter_value": { + Type: schema.TypeString, + Computed: true, + Description: "The value of the parameter.", + }, + "parameter_type": { + Type: schema.TypeString, + Computed: true, + Description: "The type of the parameter.", + }, + "parameter_description": { + Type: schema.TypeString, + Computed: true, + Description: "The description of the parameter.", + }, + "parameter_default_value": { + Type: schema.TypeString, + Computed: true, + Description: "The default value of the parameter.", + }, + "checking_code": { + Type: schema.TypeString, + Computed: true, + Description: "The valid value range of the parameter.", + }, + "force_modify": { + Type: schema.TypeBool, + Computed: true, + Description: "Indicates whether the parameter running value can be modified.", + }, + "force_restart": { + Type: schema.TypeBool, + Computed: true, + Description: "Indicates whether the instance needs to be restarted to take effect after modifying the running value of the parameter.", + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func dataSourceVolcengineSqlserverInstancesRead(d *schema.ResourceData, meta interface{}) error { + service := NewRdsMssqlInstanceService(meta.(*ve.SdkClient)) + return service.Dispatcher.Data(service, d, DataSourceVolcengineRdsMssqlInstances()) +} diff --git a/volcengine/rds_mssql/rds_mssql_instance/resource_volcengine_rds_mssql_instance.go b/volcengine/rds_mssql/rds_mssql_instance/resource_volcengine_rds_mssql_instance.go new file mode 100644 index 00000000..365e2e3d --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_instance/resource_volcengine_rds_mssql_instance.go @@ -0,0 +1,218 @@ +package sqlserver_instance + +import ( + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" +) + +/* + +Import +Rds Mssql Instance can be imported using the id, e.g. +``` +$ terraform import volcengine_rds_mssql_instance.default resource_id +``` + +*/ + +func ResourceVolcengineRdsMssqlInstance() *schema.Resource { + resource := &schema.Resource{ + Create: resourceVolcengineSqlserverInstanceCreate, + Read: resourceVolcengineSqlserverInstanceRead, + Update: resourceVolcengineSqlserverInstanceUpdate, + Delete: resourceVolcengineSqlserverInstanceDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(60 * time.Minute), + Update: schema.DefaultTimeout(60 * time.Minute), + Delete: schema.DefaultTimeout(60 * time.Minute), + }, + Schema: map[string]*schema.Schema{ + "db_engine_version": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The Compatible version. Valid values: `SQLServer_2019_Std`, `SQLServer_2019_Web`, `SQLServer_2019_Ent`.", + }, + "instance_type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The Instance type. When the value of the `db_engine_version` is `SQLServer_2019_Std`, the value of this field can be `HA` or `Basic`." + + "When the value of the `db_engine_version` is `SQLServer_2019_Ent`, the value of this field can be `Cluster` or `Basic`." + + "When the value of the `db_engine_version` is `SQLServer_2019_Web`, the value of this field can be `Basic`.", + }, + "subnet_id": { + Type: schema.TypeList, + Required: true, + ForceNew: true, + MinItems: 1, + MaxItems: 2, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "The subnet id of the instance node. When creating an instance that includes primary and backup nodes and needs to deploy primary and backup nodes across availability zones, you can specify two subnet_id. " + + "By default, the first is the primary node availability zone, and the second is the backup node availability zone.", + }, + "node_spec": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The node specification.", + }, + "storage_space": { + Type: schema.TypeInt, + Required: true, + ForceNew: true, + Description: "Storage space size, measured in GiB. The range of values is 20GiB to 4000GiB, with a step size of 10GiB.", + }, + "super_account_password": { + Type: schema.TypeString, + Required: true, + Sensitive: true, + ForceNew: true, + Description: "The super account password. When importing resources, this attribute will not be imported. If this attribute is set, please use lifecycle and ignore_changes ignore changes in fields.", + }, + "instance_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "Name of the instance.", + }, + "project_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "The project name.", + }, + "tags": ve.TagsSchema(), + "charge_info": { + Type: schema.TypeList, + MaxItems: 1, + Required: true, + ForceNew: true, + Description: "The charge info.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "charge_type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The charge type. Valid values: `PostPaid`, `PrePaid`.", + }, + "auto_renew": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + Computed: true, + DiffSuppressFunc: rdsMssqlInstanceDiffSuppress, + Description: "Whether to enable automatic renewal in the prepaid scenario. This parameter can be set when the ChargeType is `Prepaid`.", + }, + "period": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Computed: true, + DiffSuppressFunc: rdsMssqlInstanceDiffSuppress, + Description: "Purchase duration in a prepaid scenario. This parameter is required when the ChargeType is `Prepaid`.", + }, + "charge_start_time": { + Type: schema.TypeString, + Computed: true, + Description: "Charge start time.", + }, + "charge_end_time": { + Type: schema.TypeString, + Computed: true, + Description: "Charge end time.", + }, + "charge_status": { + Type: schema.TypeString, + Computed: true, + Description: "The charge status.", + }, + "overdue_reclaim_time": { + Type: schema.TypeString, + Computed: true, + Description: "Expected release time when overdue fees are shut down.", + }, + "overdue_time": { + Type: schema.TypeString, + Computed: true, + Description: "Time for Disconnection due to Unpaid Fees.", + }, + }, + }, + }, + "backup_time": { + Type: schema.TypeString, + Optional: true, + Description: "The time window for starting the backup task is one hour interval. " + + "\nThis field is valid and required when updating the backup plan of instance.", + }, + "full_backup_period": { + Type: schema.TypeSet, + Set: schema.HashString, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "Full backup cycle. Multiple values separated by commas. " + + "The values are as follows: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. " + + "\nThis field is valid and required when updating the backup plan of instance.", + }, + "backup_retention_period": { + Type: schema.TypeInt, + Optional: true, + Description: "Data backup retention days, value range: 7~30. " + + "\nThis field is valid and required when updating the backup plan of instance.", + }, + }, + } + return resource +} + +func resourceVolcengineSqlserverInstanceCreate(d *schema.ResourceData, meta interface{}) (err error) { + service := NewRdsMssqlInstanceService(meta.(*ve.SdkClient)) + err = service.Dispatcher.Create(service, d, ResourceVolcengineRdsMssqlInstance()) + if err != nil { + return fmt.Errorf("error on creating rds_mssql_instance %q, %s", d.Id(), err) + } + return resourceVolcengineSqlserverInstanceRead(d, meta) +} + +func resourceVolcengineSqlserverInstanceRead(d *schema.ResourceData, meta interface{}) (err error) { + service := NewRdsMssqlInstanceService(meta.(*ve.SdkClient)) + err = service.Dispatcher.Read(service, d, ResourceVolcengineRdsMssqlInstance()) + if err != nil { + return fmt.Errorf("error on reading rds_mssql_instance %q, %s", d.Id(), err) + } + return err +} + +func resourceVolcengineSqlserverInstanceUpdate(d *schema.ResourceData, meta interface{}) (err error) { + service := NewRdsMssqlInstanceService(meta.(*ve.SdkClient)) + err = service.Dispatcher.Update(service, d, ResourceVolcengineRdsMssqlInstance()) + if err != nil { + return fmt.Errorf("error on updating rds_mssql_instance %q, %s", d.Id(), err) + } + return resourceVolcengineSqlserverInstanceRead(d, meta) +} + +func resourceVolcengineSqlserverInstanceDelete(d *schema.ResourceData, meta interface{}) (err error) { + return fmt.Errorf("This resource does not support deletion. " + + "If you want to remove it from terraform state, " + + "please use `terraform state rm volcengine_rds_mssql_instance.resource_name` command. ") +} + +func rdsMssqlInstanceDiffSuppress(k, old, new string, d *schema.ResourceData) bool { + //在计费方式为PostPaid的时候 period的变化会被忽略 + if d.Get("charge_info.0.charge_type").(string) == "PostPaid" && (k == "charge_info.0.period" || k == "charge_info.0.auto_renew") { + return true + } + + return false +} diff --git a/volcengine/rds_mssql/rds_mssql_instance/service_volcengine_rds_mssql_instance.go b/volcengine/rds_mssql/rds_mssql_instance/service_volcengine_rds_mssql_instance.go new file mode 100644 index 00000000..5848bc6d --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_instance/service_volcengine_rds_mssql_instance.go @@ -0,0 +1,538 @@ +package sqlserver_instance + +import ( + "encoding/json" + "errors" + "fmt" + "github.com/volcengine/terraform-provider-volcengine/volcengine/vpc/subnet" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/logger" +) + +type VolcengineRdsMssqlInstanceService struct { + Client *ve.SdkClient + Dispatcher *ve.Dispatcher +} + +func NewRdsMssqlInstanceService(c *ve.SdkClient) *VolcengineRdsMssqlInstanceService { + return &VolcengineRdsMssqlInstanceService{ + Client: c, + Dispatcher: &ve.Dispatcher{}, + } +} + +func (s *VolcengineRdsMssqlInstanceService) GetClient() *ve.SdkClient { + return s.Client +} + +func (s *VolcengineRdsMssqlInstanceService) ReadResources(m map[string]interface{}) (data []interface{}, err error) { + var ( + resp *map[string]interface{} + results interface{} + ok bool + ) + return ve.WithPageNumberQuery(m, "PageSize", "PageNumber", 100, 1, func(condition map[string]interface{}) ([]interface{}, error) { + action := "DescribeDBInstances" + + bytes, _ := json.Marshal(condition) + logger.Debug(logger.ReqFormat, action, string(bytes)) + if condition == nil { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), nil) + if err != nil { + return data, err + } + } else { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), &condition) + if err != nil { + return data, err + } + } + respBytes, _ := json.Marshal(resp) + logger.Debug(logger.RespFormat, action, condition, string(respBytes)) + results, err = ve.ObtainSdkValue("Result.InstancesInfo", *resp) + if err != nil { + return data, err + } + if results == nil { + results = []interface{}{} + } + if data, ok = results.([]interface{}); !ok { + return data, errors.New("Result.InstancesInfo is not Slice") + } + + for _, v := range data { + rdsInstance, ok := v.(map[string]interface{}) + if !ok { + return data, fmt.Errorf("Instance is not map ") + } + + detailAction := "DescribeDBInstanceDetail" + detailReq := map[string]interface{}{ + "InstanceId": rdsInstance["InstanceId"], + } + logger.Debug(logger.ReqFormat, detailAction, detailReq) + detailInfo, err := s.Client.UniversalClient.DoCall(getUniversalInfo(detailAction), &detailReq) + if err != nil { + logger.Info("DescribeDBInstanceDetail error:", err) + continue + } + logger.Debug(logger.RespFormat, detailAction, detailReq, &detailInfo) + basicInfo, err := ve.ObtainSdkValue("Result.BasicInfo", *detailInfo) + if err != nil { + logger.Info("ObtainSdkValue Result.BasicInfo error:", err) + continue + } + basicMap, ok := basicInfo.(map[string]interface{}) + if !ok { + logger.Info("Result.BasicInfo is not map") + continue + } + for k, v := range basicMap { + rdsInstance[k] = v + } + + nodeDetail, err := ve.ObtainSdkValue("Result.NodeDetailInfo", *detailInfo) + if err != nil { + logger.Info("ObtainSdkValue Result.NodeDetailInfo error:", err) + continue + } + rdsInstance["NodeDetailInfo"] = nodeDetail + + connection, err := ve.ObtainSdkValue("Result.ConnectionInfo", *detailInfo) + if err != nil { + logger.Info("ObtainSdkValue Result.ConnectionInfo error:", err) + continue + } + rdsInstance["ConnectionInfo"] = connection + + action := "DescribeDBInstanceParameters" + req := map[string]interface{}{ + "InstanceId": rdsInstance["InstanceId"], + } + logger.Debug(logger.ReqFormat, action, req) + parameterInfo, err := s.Client.UniversalClient.DoCall(getUniversalInfo(action), &req) + if err != nil { + logger.Info("DescribeDBInstanceParameters error:", err) + continue + } + logger.Debug(logger.RespFormat, action, req, ¶meterInfo) + + count, err := ve.ObtainSdkValue("Result.ParameterCount", *parameterInfo) + if err != nil { + logger.Info("ObtainSdkValue Result.ParameterCount error:", err) + continue + } + rdsInstance["ParameterCount"] = count + + parameters, err := ve.ObtainSdkValue("Result.InstanceParameters", *parameterInfo) + if err != nil { + logger.Info("ObtainSdkValue Result.InstanceParameters error:", err) + continue + } + rdsInstance["Parameters"] = parameters + } + + return data, err + }) +} + +func (s *VolcengineRdsMssqlInstanceService) ReadResource(resourceData *schema.ResourceData, id string) (data map[string]interface{}, err error) { + var ( + results []interface{} + ok bool + ) + if id == "" { + id = s.ReadResourceId(resourceData.Id()) + } + req := map[string]interface{}{ + "InstanceId": id, + } + results, err = s.ReadResources(req) + if err != nil { + return data, err + } + for _, v := range results { + if data, ok = v.(map[string]interface{}); !ok { + return data, errors.New("Value is not map ") + } else { + // 处理 subnet_id + if subnetIds, ok := data["SubnetId"]; ok { + ids := strings.Split(subnetIds.(string), ";") + data["SubnetId"] = ids + } + + // 回填数据 + if _, ok = data["ChargeDetail"]; ok { + data["ChargeInfo"] = data["ChargeDetail"] + } + if _, ok = data["DBEngineVersion"]; ok { + data["DbEngineVersion"] = data["DBEngineVersion"] + } + if fullBackupPeriod, ok := resourceData.GetOk("full_backup_period"); ok { + data["FullBackupPeriod"] = fullBackupPeriod + } + } + } + if len(data) == 0 { + return data, fmt.Errorf("sqlserver_instance %s not exist ", id) + } + return data, err +} + +func (s *VolcengineRdsMssqlInstanceService) RefreshResourceState(resourceData *schema.ResourceData, target []string, timeout time.Duration, id string) *resource.StateChangeConf { + return &resource.StateChangeConf{ + Pending: []string{}, + Delay: 1 * time.Second, + MinTimeout: 1 * time.Second, + Target: target, + Timeout: timeout, + Refresh: func() (result interface{}, state string, err error) { + var ( + d map[string]interface{} + status interface{} + failStates []string + ) + failStates = append(failStates, "Error") + if err = resource.Retry(20*time.Minute, func() *resource.RetryError { + d, err = s.ReadResource(resourceData, id) + if err != nil { + if ve.ResourceNotFoundError(err) { + return resource.RetryableError(err) + } else { + return resource.NonRetryableError(err) + } + } + return nil + }); err != nil { + return nil, "", err + } + status, err = ve.ObtainSdkValue("InstanceStatus", d) + if err != nil { + return nil, "", err + } + for _, v := range failStates { + if v == status.(string) { + return nil, "", fmt.Errorf("sqlserver_instance status error, status: %s", status.(string)) + } + } + return d, status.(string), err + }, + } +} + +func (s *VolcengineRdsMssqlInstanceService) CreateResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { + var callbacks []ve.Callback + callback := ve.Callback{ + Call: ve.SdkCall{ + Action: "CreateDBInstance", + ConvertMode: ve.RequestConvertAll, + ContentType: ve.ContentTypeJson, + Convert: map[string]ve.RequestConvert{ + "db_engine_version": { + TargetField: "DBEngineVersion", + }, + "charge_info": { + ConvertType: ve.ConvertJsonObject, + }, + "tags": { + ConvertType: ve.ConvertJsonObjectArray, + }, + "subnet_id": { + Ignore: true, + }, + "full_backup_period": { + Ignore: true, + }, + "backup_time": { + Ignore: true, + }, + "backup_retention_period": { + Ignore: true, + }, + }, + BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { + subnetId := d.Get("subnet_id") + ids, ok := subnetId.([]interface{}) + if !ok { + return false, fmt.Errorf("subnet_id is not slice ") + } + zoneIds := make([]string, 0) + subnetIds := make([]string, 0) + for _, id := range ids { + resp, err := subnet.NewSubnetService(s.Client).ReadResource(resourceData, id.(string)) + if err != nil { + return false, err + } + (*call.SdkParam)["VpcId"] = resp["VpcId"] + zoneIds = append(zoneIds, resp["ZoneId"].(string)) + subnetIds = append(subnetIds, id.(string)) + } + (*call.SdkParam)["ZoneId"] = strings.Join(zoneIds, ";") + (*call.SdkParam)["SubnetId"] = strings.Join(subnetIds, ";") + + if (*call.SdkParam)["ChargeInfo.0.ChargeType"] == "PrePaid" { + if (*call.SdkParam)["ChargeInfo.0.Period"] == nil || (*call.SdkParam)["ChargeInfo.0.Period"].(int) < 1 { + return false, fmt.Errorf("Instance Charge Type is PrePaid. Must set Period more than 1. ") + } + (*call.SdkParam)["ChargeInfo.0.PeriodUnit"] = "Month" + } + + (*call.SdkParam)["DBTimeZone"] = "China Standard Time" + (*call.SdkParam)["ServerCollation"] = "Chinese_PRC_CI_AS" + return true, nil + }, + ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.RespFormat, call.Action, call.SdkParam) + resp, err := s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + logger.Debug(logger.RespFormat, call.Action, resp, err) + return resp, err + }, + AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error { + id, _ := ve.ObtainSdkValue("Result.InstanceId", *resp) + d.SetId(id.(string)) + return nil + }, + Refresh: &ve.StateRefresh{ + Target: []string{"Running"}, + Timeout: resourceData.Timeout(schema.TimeoutCreate), + }, + }, + } + callbacks = append(callbacks, callback) + + backTime, timeOk := resourceData.GetOk("backup_time") + fullBackupPeriod, fullOk := resourceData.GetOk("full_backup_period") + backPeriod, retentionOk := resourceData.GetOk("backup_retention_period") + if timeOk || fullOk || retentionOk { + backupCallback := ve.Callback{ + Call: ve.SdkCall{ + Action: "ModifyBackupPolicy", + ContentType: ve.ContentTypeJson, + ConvertMode: ve.RequestConvertIgnore, + BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { + err := fmt.Errorf("backup_time, full_backup_period and backup_retention_period are required when set the backup plan. ") + if retentionOk { + (*call.SdkParam)["BackupRetentionPeriod"] = backPeriod + } else { + return false, err + } + if timeOk { + (*call.SdkParam)["BackupTime"] = backTime + } else { + return false, err + } + if fullOk { + var ( + period string + periodStr []string + ) + periodList := fullBackupPeriod.(*schema.Set).List() + for _, p := range periodList { + periodStr = append(periodStr, p.(string)) + } + period = strings.Join(periodStr, ",") + (*call.SdkParam)["FullBackupPeriod"] = period + } else { + return false, err + } + (*call.SdkParam)["InstanceId"] = d.Id() + return true, nil + }, + ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.RespFormat, call.Action, call.SdkParam) + resp, err := s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + logger.Debug(logger.RespFormat, call.Action, resp, err) + return resp, err + }, + }, + } + callbacks = append(callbacks, backupCallback) + } + return callbacks +} + +func (VolcengineRdsMssqlInstanceService) WithResourceResponseHandlers(d map[string]interface{}) []ve.ResourceResponseHandler { + handler := func() (map[string]interface{}, map[string]ve.ResponseConvert, error) { + return d, nil, nil + } + return []ve.ResourceResponseHandler{handler} +} + +func (s *VolcengineRdsMssqlInstanceService) ModifyResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { + var callbacks []ve.Callback + if resourceData.HasChange("backup_time") || resourceData.HasChange("full_backup_period") || + resourceData.HasChange("backup_retention_period") { + backupCallback := ve.Callback{ + Call: ve.SdkCall{ + Action: "ModifyBackupPolicy", + ContentType: ve.ContentTypeJson, + ConvertMode: ve.RequestConvertIgnore, + BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { + err := fmt.Errorf("backup_time, full_backup_period and backup_retention_period are required when set the backup plan. ") + if backPeriod, ok := d.GetOk("backup_retention_period"); ok { + (*call.SdkParam)["BackupRetentionPeriod"] = backPeriod + } else { + return false, err + } + if backTime, ok := d.GetOk("backup_time"); ok { + (*call.SdkParam)["BackupTime"] = backTime + } else { + return false, err + } + if fullBackupPeriod, ok := d.GetOk("full_backup_period"); ok { + var ( + period string + periodStr []string + ) + periodList := fullBackupPeriod.(*schema.Set).List() + for _, p := range periodList { + periodStr = append(periodStr, p.(string)) + } + period = strings.Join(periodStr, ",") + (*call.SdkParam)["FullBackupPeriod"] = period + } else { + return false, err + } + (*call.SdkParam)["InstanceId"] = d.Id() + return true, nil + }, + ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.RespFormat, call.Action, call.SdkParam) + resp, err := s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + logger.Debug(logger.RespFormat, call.Action, resp, err) + return resp, err + }, + }, + } + callbacks = append(callbacks, backupCallback) + } + + // 更新Tags + callbacks = s.setResourceTags(resourceData, callbacks) + + return callbacks +} + +func (s *VolcengineRdsMssqlInstanceService) RemoveResource(resourceData *schema.ResourceData, r *schema.Resource) []ve.Callback { + callback := ve.Callback{} + return []ve.Callback{callback} +} + +func (s *VolcengineRdsMssqlInstanceService) DatasourceResources(*schema.ResourceData, *schema.Resource) ve.DataSourceInfo { + return ve.DataSourceInfo{ + RequestConverts: map[string]ve.RequestConvert{ + "db_engine_version": { + TargetField: "DBEngineVersion", + }, + "tags": { + TargetField: "TagFilters", + ConvertType: ve.ConvertJsonObjectArray, + }, + }, + ContentType: ve.ContentTypeJson, + NameField: "InstanceName", + IdField: "InstanceId", + CollectField: "instances", + ResponseConverts: map[string]ve.ResponseConvert{ + "InstanceId": { + TargetField: "id", + KeepDefault: true, + }, + "VCPU": { + TargetField: "v_cpu", + }, + "NodeIP": { + TargetField: "node_ip", + }, + "DBEngineVersion": { + TargetField: "db_engine_version", + }, + "DNSVisibility": { + TargetField: "dns_visibility", + }, + "IPAddress": { + TargetField: "ip_address", + }, + }, + } +} + +func (s *VolcengineRdsMssqlInstanceService) ReadResourceId(id string) string { + return id +} + +func getUniversalInfo(actionName string) ve.UniversalInfo { + return ve.UniversalInfo{ + ServiceName: "rds_mssql", + Version: "2022-01-01", + HttpMethod: ve.POST, + ContentType: ve.ApplicationJSON, + Action: actionName, + } +} + +func (s *VolcengineRdsMssqlInstanceService) setResourceTags(resourceData *schema.ResourceData, callbacks []ve.Callback) []ve.Callback { + addedTags, removedTags, _, _ := ve.GetSetDifference("tags", resourceData, ve.TagsHash, false) + + removeCallback := ve.Callback{ + Call: ve.SdkCall{ + Action: "RemoveTagsFromResource", + ConvertMode: ve.RequestConvertIgnore, + BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { + if removedTags != nil && len(removedTags.List()) > 0 { + (*call.SdkParam)["InstanceIds"] = []string{resourceData.Id()} + (*call.SdkParam)["TagKeys"] = make([]string, 0) + for _, tag := range removedTags.List() { + (*call.SdkParam)["TagKeys"] = append((*call.SdkParam)["TagKeys"].([]string), tag.(map[string]interface{})["key"].(string)) + } + return true, nil + } + return false, nil + }, + ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.ReqFormat, call.Action, call.SdkParam) + return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + }, + }, + } + callbacks = append(callbacks, removeCallback) + + addCallback := ve.Callback{ + Call: ve.SdkCall{ + Action: "AddTagsToResource", + ConvertMode: ve.RequestConvertIgnore, + BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { + if addedTags != nil && len(addedTags.List()) > 0 { + (*call.SdkParam)["InstanceIds"] = []string{resourceData.Id()} + (*call.SdkParam)["Tags"] = make([]map[string]interface{}, 0) + for _, tag := range addedTags.List() { + (*call.SdkParam)["Tags"] = append((*call.SdkParam)["Tags"].([]map[string]interface{}), tag.(map[string]interface{})) + } + return true, nil + } + return false, nil + }, + ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.ReqFormat, call.Action, call.SdkParam) + return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + }, + }, + } + callbacks = append(callbacks, addCallback) + + return callbacks +} + +func (s *VolcengineRdsMssqlInstanceService) ProjectTrn() *ve.ProjectTrn { + return &ve.ProjectTrn{ + ServiceName: "rds_mssql", + ResourceType: "instance", + ProjectResponseField: "ProjectName", + ProjectSchemaField: "project_name", + } +} diff --git a/volcengine/rds_mssql/rds_mssql_region/data_source_volcengine_rds_mssql_regions.go b/volcengine/rds_mssql/rds_mssql_region/data_source_volcengine_rds_mssql_regions.go new file mode 100644 index 00000000..e9f32afa --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_region/data_source_volcengine_rds_mssql_regions.go @@ -0,0 +1,48 @@ +package rds_mssql_region + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" +) + +func DataSourceVolcengineRdsMssqlRegions() *schema.Resource { + return &schema.Resource{ + Read: dataSourceVolcengineRdsMssqlRegionsRead, + Schema: map[string]*schema.Schema{ + "output_file": { + Type: schema.TypeString, + Optional: true, + Description: "File name where to save data source results.", + }, + "total_count": { + Type: schema.TypeInt, + Computed: true, + Description: "The total count of region query.", + }, + "regions": { + Description: "The collection of region query.", + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "region_id": { + Type: schema.TypeString, + Computed: true, + Description: "The id of the region.", + }, + "region_name": { + Type: schema.TypeString, + Computed: true, + Description: "The name of region.", + }, + }, + }, + }, + }, + } +} + +func dataSourceVolcengineRdsMssqlRegionsRead(d *schema.ResourceData, meta interface{}) error { + regionService := NewRegionService(meta.(*ve.SdkClient)) + return ve.DefaultDispatcher().Data(regionService, d, DataSourceVolcengineRdsMssqlRegions()) +} diff --git a/volcengine/rds_mssql/rds_mssql_region/service_volcengine_rds_mssql_region.go b/volcengine/rds_mssql/rds_mssql_region/service_volcengine_rds_mssql_region.go new file mode 100644 index 00000000..f7677a26 --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_region/service_volcengine_rds_mssql_region.go @@ -0,0 +1,118 @@ +package rds_mssql_region + +import ( + "errors" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/logger" +) + +type VolcengineRegionService struct { + Client *ve.SdkClient +} + +func NewRegionService(c *ve.SdkClient) *VolcengineRegionService { + return &VolcengineRegionService{ + Client: c, + } +} + +func (s *VolcengineRegionService) GetClient() *ve.SdkClient { + return s.Client +} + +func getUniversalInfo(actionName string) ve.UniversalInfo { + return ve.UniversalInfo{ + ServiceName: "rds_mssql", + Version: "2022-01-01", + HttpMethod: ve.POST, + ContentType: ve.ApplicationJSON, + Action: actionName, + } +} + +func (s *VolcengineRegionService) ReadResources(condition map[string]interface{}) ([]interface{}, error) { + var ( + resp *map[string]interface{} + results interface{} + ok bool + err error + data []interface{} + ) + action := "DescribeRegions" + logger.Debug(logger.ReqFormat, action, condition) + if condition == nil { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), nil) + } else { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), &condition) + } + if err != nil { + return nil, err + } + logger.Debug(logger.RespFormat, action, condition, *resp) + + results, err = ve.ObtainSdkValue("Result.Regions", *resp) + if err != nil { + return nil, err + } + if results == nil { + results = make([]interface{}, 0) + } + + if data, ok = results.([]interface{}); !ok { + return nil, errors.New("Result.Regions is not Slice") + } + + return data, nil +} + +func (s *VolcengineRegionService) ReadResource(resourceData *schema.ResourceData, id string) (data map[string]interface{}, err error) { + return nil, nil +} + +func (s *VolcengineRegionService) RefreshResourceState(resourceData *schema.ResourceData, target []string, timeout time.Duration, id string) *resource.StateChangeConf { + return &resource.StateChangeConf{ + Pending: []string{}, + Delay: 5 * time.Second, + MinTimeout: 5 * time.Second, + Target: target, + Timeout: timeout, + Refresh: func() (result interface{}, state string, err error) { + return nil, "", err + }, + } +} + +func (s *VolcengineRegionService) WithResourceResponseHandlers(zone map[string]interface{}) []ve.ResourceResponseHandler { + handler := func() (map[string]interface{}, map[string]ve.ResponseConvert, error) { + return zone, nil, nil + } + return []ve.ResourceResponseHandler{handler} +} + +func (s *VolcengineRegionService) CreateResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { + return []ve.Callback{} +} + +func (s *VolcengineRegionService) ModifyResource(resourceData *schema.ResourceData, resource *schema.Resource) (callbacks []ve.Callback) { + return callbacks +} + +func (s *VolcengineRegionService) RemoveResource(resourceData *schema.ResourceData, r *schema.Resource) []ve.Callback { + return []ve.Callback{} +} + +func (s *VolcengineRegionService) DatasourceResources(data *schema.ResourceData, resource *schema.Resource) ve.DataSourceInfo { + return ve.DataSourceInfo{ + NameField: "RegionName", + IdField: "RegionId", + CollectField: "regions", + } +} + +func (s *VolcengineRegionService) ReadResourceId(id string) string { + return id +} diff --git a/volcengine/rds_mssql/rds_mssql_zone/data_source_volcengine_rds_mssql_zones.go b/volcengine/rds_mssql/rds_mssql_zone/data_source_volcengine_rds_mssql_zones.go new file mode 100644 index 00000000..b0edb2ec --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_zone/data_source_volcengine_rds_mssql_zones.go @@ -0,0 +1,63 @@ +package rds_mssql_zone + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" +) + +func DataSourceVolcengineRdsMssqlZones() *schema.Resource { + return &schema.Resource{ + Read: dataSourceVolcengineRdsMssqlZonesRead, + Schema: map[string]*schema.Schema{ + "region_id": { + Type: schema.TypeString, + Optional: true, + Description: "The Id of Region.", + }, + "output_file": { + Type: schema.TypeString, + Optional: true, + Description: "File name where to save data source results.", + }, + "total_count": { + Type: schema.TypeInt, + Computed: true, + Description: "The total count of zone query.", + }, + "zones": { + Description: "The collection of zone query.", + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + Description: "The id of the zone.", + }, + "zone_id": { + Type: schema.TypeString, + Computed: true, + Description: "The id of the zone.", + }, + "zone_name": { + Type: schema.TypeString, + Computed: true, + Description: "The name of the zone.", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "The description of the zone.", + }, + }, + }, + }, + }, + } +} + +func dataSourceVolcengineRdsMssqlZonesRead(d *schema.ResourceData, meta interface{}) error { + zoneService := NewZoneService(meta.(*ve.SdkClient)) + return ve.DefaultDispatcher().Data(zoneService, d, DataSourceVolcengineRdsMssqlZones()) +} diff --git a/volcengine/rds_mssql/rds_mssql_zone/service_volcengine_rds_mssql_zone.go b/volcengine/rds_mssql/rds_mssql_zone/service_volcengine_rds_mssql_zone.go new file mode 100644 index 00000000..7bc2ef5d --- /dev/null +++ b/volcengine/rds_mssql/rds_mssql_zone/service_volcengine_rds_mssql_zone.go @@ -0,0 +1,124 @@ +package rds_mssql_zone + +import ( + "errors" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/logger" +) + +type VolcengineZoneService struct { + Client *ve.SdkClient +} + +func NewZoneService(c *ve.SdkClient) *VolcengineZoneService { + return &VolcengineZoneService{ + Client: c, + } +} + +func (s *VolcengineZoneService) GetClient() *ve.SdkClient { + return s.Client +} + +func getUniversalInfo(actionName string) ve.UniversalInfo { + return ve.UniversalInfo{ + ServiceName: "rds_mssql", + Version: "2022-01-01", + HttpMethod: ve.POST, + ContentType: ve.ApplicationJSON, + Action: actionName, + } +} + +func (s *VolcengineZoneService) ReadResources(condition map[string]interface{}) ([]interface{}, error) { + var ( + resp *map[string]interface{} + results interface{} + ok bool + err error + data []interface{} + ) + action := "DescribeAvailabilityZones" + logger.Debug(logger.ReqFormat, action, condition) + if condition == nil { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), nil) + } else { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), &condition) + } + if err != nil { + return nil, err + } + logger.Debug(logger.RespFormat, action, condition, *resp) + + results, err = ve.ObtainSdkValue("Result.Zones", *resp) + if err != nil { + return nil, err + } + if results == nil { + results = make([]interface{}, 0) + } + + if data, ok = results.([]interface{}); !ok { + return nil, errors.New("Result.Zones is not Slice") + } + + return data, nil +} + +func (s *VolcengineZoneService) ReadResource(resourceData *schema.ResourceData, id string) (data map[string]interface{}, err error) { + return nil, nil +} + +func (s *VolcengineZoneService) RefreshResourceState(resourceData *schema.ResourceData, target []string, timeout time.Duration, id string) *resource.StateChangeConf { + return &resource.StateChangeConf{ + Pending: []string{}, + Delay: 5 * time.Second, + MinTimeout: 5 * time.Second, + Target: target, + Timeout: timeout, + Refresh: func() (result interface{}, state string, err error) { + return nil, "", err + }, + } +} + +func (s *VolcengineZoneService) WithResourceResponseHandlers(zone map[string]interface{}) []ve.ResourceResponseHandler { + handler := func() (map[string]interface{}, map[string]ve.ResponseConvert, error) { + return zone, nil, nil + } + return []ve.ResourceResponseHandler{handler} +} + +func (s *VolcengineZoneService) CreateResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { + return []ve.Callback{} +} + +func (s *VolcengineZoneService) ModifyResource(resourceData *schema.ResourceData, resource *schema.Resource) (callbacks []ve.Callback) { + return callbacks +} + +func (s *VolcengineZoneService) RemoveResource(resourceData *schema.ResourceData, r *schema.Resource) []ve.Callback { + return []ve.Callback{} +} + +func (s *VolcengineZoneService) DatasourceResources(data *schema.ResourceData, resource *schema.Resource) ve.DataSourceInfo { + return ve.DataSourceInfo{ + NameField: "ZoneName", + IdField: "ZoneId", + CollectField: "zones", + ResponseConverts: map[string]ve.ResponseConvert{ + "ZoneId": { + TargetField: "id", + KeepDefault: true, + }, + }, + } +} + +func (s *VolcengineZoneService) ReadResourceId(id string) string { + return id +} diff --git a/volcengine/vke/default_node_pool/resource_volcengine_vke_default_node_pool.go b/volcengine/vke/default_node_pool/resource_volcengine_vke_default_node_pool.go index 8c707a39..3facb5f7 100644 --- a/volcengine/vke/default_node_pool/resource_volcengine_vke_default_node_pool.go +++ b/volcengine/vke/default_node_pool/resource_volcengine_vke_default_node_pool.go @@ -147,6 +147,11 @@ func ResourceVolcengineDefaultNodePool() *schema.Resource { Required: true, Description: "The Cordon of KubernetesConfig.", }, + "name_prefix": { + Type: schema.TypeString, + Optional: true, + Description: "The NamePrefix of node metadata.", + }, }, }, Description: "The KubernetesConfig of NodeConfig.", diff --git a/volcengine/vke/default_node_pool/service_volcengine_vke_default_node_pool.go b/volcengine/vke/default_node_pool/service_volcengine_vke_default_node_pool.go index 8cf90a7f..e38ff75f 100644 --- a/volcengine/vke/default_node_pool/service_volcengine_vke_default_node_pool.go +++ b/volcengine/vke/default_node_pool/service_volcengine_vke_default_node_pool.go @@ -228,6 +228,9 @@ func (s *VolcengineDefaultNodePoolService) CreateResource(resourceData *schema.R "taints": { ConvertType: ve.ConvertJsonArray, }, + "name_prefix": { + ConvertType: ve.ConvertJsonObject, + }, }, }, "node_config": { @@ -350,6 +353,9 @@ func (s *VolcengineDefaultNodePoolService) ModifyResource(resourceData *schema.R "cordon": { ConvertType: ve.ConvertJsonObject, }, + "name_prefix": { + ConvertType: ve.ConvertJsonObject, + }, }, }, }, diff --git a/volcengine/vke/kubeconfig/data_source_volcengine_vke_kubeconfigs.go b/volcengine/vke/kubeconfig/data_source_volcengine_vke_kubeconfigs.go index f1efc7f0..ede03861 100644 --- a/volcengine/vke/kubeconfig/data_source_volcengine_vke_kubeconfigs.go +++ b/volcengine/vke/kubeconfig/data_source_volcengine_vke_kubeconfigs.go @@ -57,6 +57,15 @@ func DataSourceVolcengineVkeKubeconfigs() *schema.Resource { Set: schema.HashString, Description: "A list of Cluster IDs.", }, + "role_ids": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Set: schema.HashInt, + Description: "A list of Role IDs.", + }, "types": { Type: schema.TypeSet, Optional: true, diff --git a/volcengine/vke/kubeconfig/service_volcengine_vke_kubeconfig.go b/volcengine/vke/kubeconfig/service_volcengine_vke_kubeconfig.go index ccc6224e..eec100b4 100644 --- a/volcengine/vke/kubeconfig/service_volcengine_vke_kubeconfig.go +++ b/volcengine/vke/kubeconfig/service_volcengine_vke_kubeconfig.go @@ -196,6 +196,10 @@ func (s *VolcengineVkeKubeconfigService) DatasourceResources(*schema.ResourceDat TargetField: "Filter.ClusterIds", ConvertType: ve.ConvertJsonArray, }, + "role_ids": { + TargetField: "Filter.RoleIds", + ConvertType: ve.ConvertJsonArray, + }, "types": { TargetField: "Filter.Types", ConvertType: ve.ConvertJsonArray, diff --git a/volcengine/vke/node_pool/data_source_volcengine_vke_node_pools.go b/volcengine/vke/node_pool/data_source_volcengine_vke_node_pools.go index 61dbc027..7b981bae 100644 --- a/volcengine/vke/node_pool/data_source_volcengine_vke_node_pools.go +++ b/volcengine/vke/node_pool/data_source_volcengine_vke_node_pools.go @@ -300,6 +300,11 @@ func DataSourceVolcengineNodePools() *schema.Resource { Computed: true, Description: "The Cordon of KubernetesConfig.", }, + "kube_config_name_prefix": { + Type: schema.TypeString, + Computed: true, + Description: "The NamePrefix of node metadata.", + }, "label_content": { Type: schema.TypeList, Computed: true, diff --git a/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go b/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go index d1acb776..709a0d2f 100644 --- a/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go +++ b/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go @@ -364,6 +364,11 @@ func ResourceVolcengineNodePool() *schema.Resource { Required: true, Description: "The Cordon of KubernetesConfig.", }, + "name_prefix": { + Type: schema.TypeString, + Optional: true, + Description: "The NamePrefix of node metadata.", + }, }, }, Description: "The KubernetesConfig of NodeConfig.", diff --git a/volcengine/vke/node_pool/service_volcengine_vke_node_pool.go b/volcengine/vke/node_pool/service_volcengine_vke_node_pool.go index ca110172..52e5c023 100644 --- a/volcengine/vke/node_pool/service_volcengine_vke_node_pool.go +++ b/volcengine/vke/node_pool/service_volcengine_vke_node_pool.go @@ -369,6 +369,9 @@ func (s *VolcengineNodePoolService) CreateResource(resourceData *schema.Resource "cordon": { ConvertType: ve.ConvertJsonObject, }, + "name_prefix": { + ConvertType: ve.ConvertJsonObject, + }, }, }, "auto_scaling": { @@ -554,6 +557,9 @@ func (s *VolcengineNodePoolService) ModifyResource(resourceData *schema.Resource "cordon": { ConvertType: ve.ConvertJsonObject, }, + "name_prefix": { + ConvertType: ve.ConvertJsonObject, + }, }, }, }, @@ -849,6 +855,9 @@ func (s *VolcengineNodePoolService) DatasourceResources(*schema.ResourceData, *s "AutoScaling.SubnetPolicy": { TargetField: "subnet_policy", }, + "KubernetesConfig.NamePrefix": { + TargetField: "kube_config_name_prefix", + }, "KubernetesConfig.Cordon": { TargetField: "cordon", }, diff --git a/volcengine/vpn/ssl_vpn_client_cert/resource_volcengine_ssl_vpn_client_cert_test.go b/volcengine/vpn/ssl_vpn_client_cert/resource_volcengine_ssl_vpn_client_cert_test.go index 292dd3ee..78fa0e16 100644 --- a/volcengine/vpn/ssl_vpn_client_cert/resource_volcengine_ssl_vpn_client_cert_test.go +++ b/volcengine/vpn/ssl_vpn_client_cert/resource_volcengine_ssl_vpn_client_cert_test.go @@ -101,6 +101,9 @@ func TestAccVolcengineSslVpnClientCertResource_Basic(t *testing.T) { } const testAccVolcengineSslVpnClientCertUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + resource "volcengine_vpc" "foo" { vpc_name = "acc-test-vpc" cidr_block = "172.16.0.0/16" @@ -109,7 +112,7 @@ resource "volcengine_vpc" "foo" { resource "volcengine_subnet" "foo" { subnet_name = "acc-test-subnet" cidr_block = "172.16.0.0/24" - zone_id = "cn-guilin-a" + zone_id = data.volcengine_zones.foo.zones[0].id vpc_id = volcengine_vpc.foo.id } diff --git a/website/docs/d/rds_mssql_backups.html.markdown b/website/docs/d/rds_mssql_backups.html.markdown new file mode 100644 index 00000000..782d74da --- /dev/null +++ b/website/docs/d/rds_mssql_backups.html.markdown @@ -0,0 +1,52 @@ +--- +subcategory: "RDS_MSSQL" +layout: "volcengine" +page_title: "Volcengine: volcengine_rds_mssql_backups" +sidebar_current: "docs-volcengine-datasource-rds_mssql_backups" +description: |- + Use this data source to query detailed information of rds mssql backups +--- +# volcengine_rds_mssql_backups +Use this data source to query detailed information of rds mssql backups +## Example Usage +```hcl +data "volcengine_rds_mssql_backups" "foo" { + instance_id = "mssql-40914121fd22" +} +``` +## Argument Reference +The following arguments are supported: +* `instance_id` - (Required) The id of the instance. +* `backup_end_time` - (Optional) The end time of the backup. +* `backup_id` - (Optional) The id of the backup. +* `backup_start_time` - (Optional) The start time of the backup. +* `backup_type` - (Optional) The type of the backup. +* `output_file` - (Optional) File name where to save data source results. + +## Attributes Reference +In addition to all arguments above, the following attributes are exported: +* `backups` - The collection of query. + * `backup_database_detail` - The detail of the database. + * `backup_download_link_eip` - External backup download link. + * `backup_download_link_inner` - Intranet backup download link. + * `backup_end_time` - The end time of the backup. + * `backup_file_name` - The name of the backup file. + * `backup_file_size` - The size of the backup file. + * `backup_start_time` - The start time of the backup. + * `backup_type` - The type of the backup. + * `database_name` - The name of the database. + * `download_progress` - Backup file preparation progress, unit: %. + * `download_status` - Download status. + * `link_expired_time` - Download link expiration time. + * `backup_end_time` - The end time of the backup. + * `backup_file_size` - The size of the backup file. + * `backup_id` - The id of the backup. + * `backup_method` - The name of the backup method. + * `backup_start_time` - The start time of the backup. + * `backup_status` - The status of the backup. + * `backup_type` - The type of the backup. + * `create_type` - The type of the backup create. + * `id` - The id of the backup. +* `total_count` - The total count of query. + + diff --git a/website/docs/d/rds_mssql_instances.html.markdown b/website/docs/d/rds_mssql_instances.html.markdown new file mode 100644 index 00000000..35d4690b --- /dev/null +++ b/website/docs/d/rds_mssql_instances.html.markdown @@ -0,0 +1,120 @@ +--- +subcategory: "RDS_MSSQL" +layout: "volcengine" +page_title: "Volcengine: volcengine_rds_mssql_instances" +sidebar_current: "docs-volcengine-datasource-rds_mssql_instances" +description: |- + Use this data source to query detailed information of rds mssql instances +--- +# volcengine_rds_mssql_instances +Use this data source to query detailed information of rds mssql instances +## Example Usage +```hcl +data "volcengine_rds_mssql_instances" "foo" { + instance_id = "mssql-d2fc5abe****" +} +``` +## Argument Reference +The following arguments are supported: +* `charge_type` - (Optional) The charge type. Valid values: `PostPaid`, `PrePaid`. +* `create_time_end` - (Optional) The end time of creating the instance, using UTC time format. +* `create_time_start` - (Optional) The start time of creating the instance, using UTC time format. +* `db_engine_version` - (Optional) Compatible version. Valid values: `SQLServer_2019_Std`, `SQLServer_2019_Web`, `SQLServer_2019_Ent`. +* `instance_id` - (Optional) Id of the instance. +* `instance_name` - (Optional) Name of the instance. +* `instance_status` - (Optional) Status of the instance. +* `instance_type` - (Optional) Instance type. Valid values: `HA`, `Basic`, `Cluster`. +* `name_regex` - (Optional) A Name Regex of RDS mssql instance. +* `output_file` - (Optional) File name where to save data source results. +* `tags` - (Optional) Tags. +* `zone_id` - (Optional) The id of the zone. + +The `tags` object supports the following: + +* `key` - (Required) The Key of Tags. +* `value` - (Required) The Value of Tags. + +## Attributes Reference +In addition to all arguments above, the following attributes are exported: +* `instances` - The collection of query. + * `backup_use` - The used backup space of the instance. Unit: GiB. + * `charge_detail` - The charge detail. + * `auto_renew` - Whether to enable automatic renewal in the prepaid scenario. This parameter can be set when ChargeType is Prepaid. + * `charge_end_time` - Charge end time. + * `charge_start_time` - Charge start time. + * `charge_status` - The charge status. + * `charge_type` - The charge type. + * `overdue_reclaim_time` - Expected release time when overdue fees are shut down. + * `overdue_time` - Time for Disconnection due to Unpaid Fees. + * `period_unit` - Purchase cycle in prepaid scenarios. This parameter can be set when ChargeType is Prepaid. + * `period` - Purchase duration in a prepaid scenario. + * `connection_info` - The connection info of the instance. + * `address` - The address info. + * `dns_visibility` - Whether to enable private to public network resolution. + * `domain` - The domain. + * `eip_id` - The eip id for public address. + * `ip_address` - The ip address. + * `network_type` - The network type. + * `port` - The port. + * `subnet_id` - The subnet id for private address. + * `description` - The description. + * `endpoint_id` - The endpoint id. + * `endpoint_name` - The endpoint name. + * `endpoint_type` - The endpoint type. + * `create_time` - The creation time of the instance. + * `db_engine_version` - The db engine version. + * `id` - The id of the instance. + * `inner_version` - The inner version of the instance. + * `instance_category` - The instance category. + * `instance_id` - The id of the instance. + * `instance_name` - The name of the instance. + * `instance_status` - The status of the instance. + * `instance_type` - The type of the instance. + * `memory` - The Memory of the instance. Unit: GiB. + * `node_detail_info` - Node detail information. + * `create_time` - Node creation time. + * `instance_id` - Instance ID. + * `memory` - The Memory. + * `node_id` - The Node ID. + * `node_ip` - The node ip. + * `node_spec` - The node spec. + * `node_status` - The node status. + * `node_type` - The node type. + * `region_id` - The region id. + * `update_time` - The update time. + * `v_cpu` - CPU size. For example: 1 represents 1U. + * `zone_id` - The zone id. + * `node_spec` - The node spec. + * `parameter_count` - The count of instance parameters. + * `parameters` - The list of instance parameters. + * `checking_code` - The valid value range of the parameter. + * `force_modify` - Indicates whether the parameter running value can be modified. + * `force_restart` - Indicates whether the instance needs to be restarted to take effect after modifying the running value of the parameter. + * `parameter_default_value` - The default value of the parameter. + * `parameter_description` - The description of the parameter. + * `parameter_name` - The name of the parameter. + * `parameter_type` - The type of the parameter. + * `parameter_value` - The value of the parameter. + * `port` - The port of the instance. + * `primary_instance_id` - The id of the primary instance. + * `project_name` - The project name. + * `read_only_number` - The number of read only instance. + * `region_id` - The region id. + * `server_collation` - Server sorting rules. + * `slow_query_enable` - Whether to enable slow query function. + * `slow_query_time` - The slow query time. Unit: second. + * `storage_space` - The storage space. + * `storage_type` - The storage type. + * `storage_use` - The used storage space. + * `subnet_id` - The subnet id. + * `tags` - Tags. + * `key` - The Key of Tags. + * `value` - The Value of Tags. + * `time_zone` - The time zone. + * `update_time` - The update time of the instance. + * `v_cpu` - The CPU size of the instance. For example: 1 represents 1U. + * `vpc_id` - The vpc id. + * `zone_id` - The zone id. +* `total_count` - The total count of query. + + diff --git a/website/docs/d/rds_mssql_regions.html.markdown b/website/docs/d/rds_mssql_regions.html.markdown new file mode 100644 index 00000000..a522843f --- /dev/null +++ b/website/docs/d/rds_mssql_regions.html.markdown @@ -0,0 +1,27 @@ +--- +subcategory: "RDS_MSSQL" +layout: "volcengine" +page_title: "Volcengine: volcengine_rds_mssql_regions" +sidebar_current: "docs-volcengine-datasource-rds_mssql_regions" +description: |- + Use this data source to query detailed information of rds mssql regions +--- +# volcengine_rds_mssql_regions +Use this data source to query detailed information of rds mssql regions +## Example Usage +```hcl +data "volcengine_rds_mssql_regions" "foo" { +} +``` +## Argument Reference +The following arguments are supported: +* `output_file` - (Optional) File name where to save data source results. + +## Attributes Reference +In addition to all arguments above, the following attributes are exported: +* `regions` - The collection of region query. + * `region_id` - The id of the region. + * `region_name` - The name of region. +* `total_count` - The total count of region query. + + diff --git a/website/docs/d/rds_mssql_zones.html.markdown b/website/docs/d/rds_mssql_zones.html.markdown new file mode 100644 index 00000000..eda0681e --- /dev/null +++ b/website/docs/d/rds_mssql_zones.html.markdown @@ -0,0 +1,31 @@ +--- +subcategory: "RDS_MSSQL" +layout: "volcengine" +page_title: "Volcengine: volcengine_rds_mssql_zones" +sidebar_current: "docs-volcengine-datasource-rds_mssql_zones" +description: |- + Use this data source to query detailed information of rds mssql zones +--- +# volcengine_rds_mssql_zones +Use this data source to query detailed information of rds mssql zones +## Example Usage +```hcl +data "volcengine_rds_mssql_zones" "foo" { + +} +``` +## Argument Reference +The following arguments are supported: +* `output_file` - (Optional) File name where to save data source results. +* `region_id` - (Optional) The Id of Region. + +## Attributes Reference +In addition to all arguments above, the following attributes are exported: +* `total_count` - The total count of zone query. +* `zones` - The collection of zone query. + * `description` - The description of the zone. + * `id` - The id of the zone. + * `zone_id` - The id of the zone. + * `zone_name` - The name of the zone. + + diff --git a/website/docs/d/vke_kubeconfigs.html.markdown b/website/docs/d/vke_kubeconfigs.html.markdown index 010c7629..899c8afb 100644 --- a/website/docs/d/vke_kubeconfigs.html.markdown +++ b/website/docs/d/vke_kubeconfigs.html.markdown @@ -84,6 +84,7 @@ The following arguments are supported: * `output_file` - (Optional) File name where to save data source results. * `page_number` - (Optional) The page number of Kubeconfigs query. * `page_size` - (Optional) The page size of Kubeconfigs query. +* `role_ids` - (Optional) A list of Role IDs. * `types` - (Optional) The type of Kubeconfigs query. ## Attributes Reference diff --git a/website/docs/d/vke_node_pools.html.markdown b/website/docs/d/vke_node_pools.html.markdown index 4b8872fa..932a2d47 100644 --- a/website/docs/d/vke_node_pools.html.markdown +++ b/website/docs/d/vke_node_pools.html.markdown @@ -182,6 +182,7 @@ In addition to all arguments above, the following attributes are exported: * `initialize_script` - The InitializeScript of NodeConfig. * `instance_charge_type` - The InstanceChargeType of NodeConfig. * `instance_type_ids` - The InstanceTypeIds of NodeConfig. + * `kube_config_name_prefix` - The NamePrefix of node metadata. * `label_content` - The LabelContent of KubernetesConfig. * `key` - The Key of KubernetesConfig. * `value` - The Value of KubernetesConfig. diff --git a/website/docs/r/rds_mssql_backup.html.markdown b/website/docs/r/rds_mssql_backup.html.markdown new file mode 100644 index 00000000..ab71ce07 --- /dev/null +++ b/website/docs/r/rds_mssql_backup.html.markdown @@ -0,0 +1,38 @@ +--- +subcategory: "RDS_MSSQL" +layout: "volcengine" +page_title: "Volcengine: volcengine_rds_mssql_backup" +sidebar_current: "docs-volcengine-resource-rds_mssql_backup" +description: |- + Provides a resource to manage rds mssql backup +--- +# volcengine_rds_mssql_backup +Provides a resource to manage rds mssql backup +## Example Usage +```hcl +resource "volcengine_rds_mssql_backup" "foo" { + instance_id = "mssql-40914121fd22" +} +``` +## Argument Reference +The following arguments are supported: +* `instance_id` - (Required, ForceNew) The id of the instance. +* `backup_meta` - (Optional, ForceNew) Backup repository information. When importing resources, this attribute will not be imported. If this attribute is set, please use lifecycle and ignore_changes ignore changes in fields. +* `backup_type` - (Optional, ForceNew) Backup type. Currently only supports full backup, with a value of Full (default). + +The `backup_meta` object supports the following: + +* `db_name` - (Required, ForceNew) The name of the database. + +## Attributes Reference +In addition to all arguments above, the following attributes are exported: +* `id` - ID of the resource. +* `backup_id` - The ID of the backup. + + +## Import +Rds Mssql Backup can be imported using the id, e.g. +``` +$ terraform import volcengine_rds_mssql_backup.default instanceId:backupId +``` + diff --git a/website/docs/r/rds_mssql_instance.html.markdown b/website/docs/r/rds_mssql_instance.html.markdown new file mode 100644 index 00000000..44049de6 --- /dev/null +++ b/website/docs/r/rds_mssql_instance.html.markdown @@ -0,0 +1,91 @@ +--- +subcategory: "RDS_MSSQL" +layout: "volcengine" +page_title: "Volcengine: volcengine_rds_mssql_instance" +sidebar_current: "docs-volcengine-resource-rds_mssql_instance" +description: |- + Provides a resource to manage rds mssql instance +--- +# volcengine_rds_mssql_instance +Provides a resource to manage rds mssql instance +## Example Usage +```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mssql_instance" "foo" { + db_engine_version = "SQLServer_2019_Std" + instance_type = "HA" + node_spec = "rds.mssql.se.ha.d2.2c4g" + storage_space = 20 + subnet_id = [volcengine_subnet.foo.id] + super_account_password = "Tftest110" + instance_name = "acc-test-mssql" + project_name = "default" + charge_info { + charge_type = "PostPaid" + } + tags { + key = "k1" + value = "v1" + } + + backup_time = "18:00Z-19:00Z" + full_backup_period = ["Monday", "Tuesday"] + backup_retention_period = 14 +} +``` +## Argument Reference +The following arguments are supported: +* `charge_info` - (Required, ForceNew) The charge info. +* `db_engine_version` - (Required, ForceNew) The Compatible version. Valid values: `SQLServer_2019_Std`, `SQLServer_2019_Web`, `SQLServer_2019_Ent`. +* `instance_type` - (Required, ForceNew) The Instance type. When the value of the `db_engine_version` is `SQLServer_2019_Std`, the value of this field can be `HA` or `Basic`.When the value of the `db_engine_version` is `SQLServer_2019_Ent`, the value of this field can be `Cluster` or `Basic`.When the value of the `db_engine_version` is `SQLServer_2019_Web`, the value of this field can be `Basic`. +* `node_spec` - (Required, ForceNew) The node specification. +* `storage_space` - (Required, ForceNew) Storage space size, measured in GiB. The range of values is 20GiB to 4000GiB, with a step size of 10GiB. +* `subnet_id` - (Required, ForceNew) The subnet id of the instance node. When creating an instance that includes primary and backup nodes and needs to deploy primary and backup nodes across availability zones, you can specify two subnet_id. By default, the first is the primary node availability zone, and the second is the backup node availability zone. +* `super_account_password` - (Required, ForceNew) The super account password. When importing resources, this attribute will not be imported. If this attribute is set, please use lifecycle and ignore_changes ignore changes in fields. +* `backup_retention_period` - (Optional) Data backup retention days, value range: 7~30. +This field is valid and required when updating the backup plan of instance. +* `backup_time` - (Optional) The time window for starting the backup task is one hour interval. +This field is valid and required when updating the backup plan of instance. +* `full_backup_period` - (Optional) Full backup cycle. Multiple values separated by commas. The values are as follows: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. +This field is valid and required when updating the backup plan of instance. +* `instance_name` - (Optional, ForceNew) Name of the instance. +* `project_name` - (Optional) The project name. +* `tags` - (Optional) Tags. + +The `charge_info` object supports the following: + +* `charge_type` - (Required, ForceNew) The charge type. Valid values: `PostPaid`, `PrePaid`. +* `auto_renew` - (Optional, ForceNew) Whether to enable automatic renewal in the prepaid scenario. This parameter can be set when the ChargeType is `Prepaid`. +* `period` - (Optional, ForceNew) Purchase duration in a prepaid scenario. This parameter is required when the ChargeType is `Prepaid`. + +The `tags` object supports the following: + +* `key` - (Required) The Key of Tags. +* `value` - (Required) The Value of Tags. + +## Attributes Reference +In addition to all arguments above, the following attributes are exported: +* `id` - ID of the resource. + + + +## Import +Rds Mssql Instance can be imported using the id, e.g. +``` +$ terraform import volcengine_rds_mssql_instance.default resource_id +``` + diff --git a/website/docs/r/vke_default_node_pool.html.markdown b/website/docs/r/vke_default_node_pool.html.markdown index 82dbd638..e6b0f86c 100644 --- a/website/docs/r/vke_default_node_pool.html.markdown +++ b/website/docs/r/vke_default_node_pool.html.markdown @@ -137,6 +137,7 @@ The `kubernetes_config` object supports the following: * `cordon` - (Required) The Cordon of KubernetesConfig. * `labels` - (Optional) The Labels of KubernetesConfig. +* `name_prefix` - (Optional) The NamePrefix of node metadata. * `taints` - (Optional) The Taints of KubernetesConfig. The `labels` object supports the following: diff --git a/website/docs/r/vke_node_pool.html.markdown b/website/docs/r/vke_node_pool.html.markdown index cc56af5a..f7681a8d 100644 --- a/website/docs/r/vke_node_pool.html.markdown +++ b/website/docs/r/vke_node_pool.html.markdown @@ -161,6 +161,7 @@ The `kubernetes_config` object supports the following: * `cordon` - (Required) The Cordon of KubernetesConfig. * `labels` - (Optional) The Labels of KubernetesConfig. +* `name_prefix` - (Optional) The NamePrefix of node metadata. * `taints` - (Optional) The Taints of KubernetesConfig. The `labels` object supports the following: diff --git a/website/volcengine.erb b/website/volcengine.erb index 162f85a5..5e1a4999 100644 --- a/website/volcengine.erb +++ b/website/volcengine.erb @@ -910,6 +910,39 @@ +
  • + RDS_MSSQL + +
  • RDS_MYSQL