diff --git a/common/common_volcengine_callback.go b/common/common_volcengine_callback.go index 97852ffa..8c0cbd56 100644 --- a/common/common_volcengine_callback.go +++ b/common/common_volcengine_callback.go @@ -33,6 +33,9 @@ type SdkCall struct { LockId LockId AfterLocked CallFunc ServiceCategory ServiceCategory + + //common inner use + refreshState func(*schema.ResourceData, []string, time.Duration, string) *resource.StateChangeConf } type StateRefresh struct { @@ -215,7 +218,12 @@ func CallProcess(calls []SdkCall, d *schema.ResourceData, client *SdkClient, ser // WaitForState if doExecute && fn.Refresh != nil && err == nil { - stateConf := service.RefreshResourceState(d, fn.Refresh.Target, fn.Refresh.Timeout, d.Id()) + var stateConf *resource.StateChangeConf + if fn.refreshState != nil { + stateConf = fn.refreshState(d, fn.Refresh.Target, fn.Refresh.Timeout, d.Id()) + } else { + stateConf = service.RefreshResourceState(d, fn.Refresh.Target, fn.Refresh.Timeout, d.Id()) + } if stateConf != nil { _, err = stateConf.WaitForState() } diff --git a/common/common_volcengine_dispatcher.go b/common/common_volcengine_dispatcher.go index f0dd5293..b4823bd4 100644 --- a/common/common_volcengine_dispatcher.go +++ b/common/common_volcengine_dispatcher.go @@ -98,7 +98,14 @@ func (d *Dispatcher) Update(resourceService ResourceService, resourceDate *schem } } } - callbacks := resourceService.ModifyResource(resourceDate, resource) + var callbacks []Callback + if projectUpdateEnabled, ok := resourceService.(ProjectUpdateEnabled); ok { + projectUpdateCallback := NewProjectService(resourceService.GetClient()).ModifyProject(projectUpdateEnabled.ProjectTrn(), + resourceDate, resource, resourceService) + callbacks = append(callbacks, projectUpdateCallback...) + } + callbacks = append(callbacks, resourceService.ModifyResource(resourceDate, resource)...) + var calls []SdkCall for _, callback := range callbacks { if callback.Err != nil { diff --git a/common/common_volcengine_project.go b/common/common_volcengine_project.go index 5b3f20a5..e87c74a7 100644 --- a/common/common_volcengine_project.go +++ b/common/common_volcengine_project.go @@ -2,19 +2,27 @@ package common import ( "fmt" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/volcengine/terraform-provider-volcengine/logger" ) +type ProjectUpdateEnabled interface { + ProjectTrn() *ProjectTrn +} + type Project struct { Client *SdkClient } type ProjectTrn struct { - ResourceType string - ResourceID string - ServiceName string + ResourceType string + ResourceID string + ServiceName string + ProjectSchemaField string + ProjectResponseField string } func NewProjectService(c *SdkClient) *Project { @@ -23,7 +31,83 @@ func NewProjectService(c *SdkClient) *Project { } } -func (p *Project) ModifyProject(trn ProjectTrn, resourceData *schema.ResourceData, resource *schema.Resource, key string, sr *StateRefresh) []Callback { +func (p *Project) ModifyProject(trn *ProjectTrn, resourceData *schema.ResourceData, r *schema.Resource, service ResourceService) []Callback { + var call []Callback + id := service.ReadResourceId(resourceData.Id()) + if resourceData.HasChange(trn.ProjectSchemaField) { + modifyProject := Callback{ + Call: SdkCall{ + Action: "MoveProjectResource", + ConvertMode: RequestConvertInConvert, + Convert: map[string]RequestConvert{ + trn.ProjectSchemaField: { + ConvertType: ConvertDefault, + TargetField: "TargetProjectName", + }, + }, + BeforeCall: func(d *schema.ResourceData, client *SdkClient, call SdkCall) (bool, error) { + if (*call.SdkParam)["TargetProjectName"] == nil || (*call.SdkParam)["TargetProjectName"] == "" { + return false, fmt.Errorf("Could set ProjectName to empty ") + } + //获取用户ID + input := map[string]interface{}{ + "ProjectName": (*call.SdkParam)["TargetProjectName"], + } + logger.Debug(logger.ReqFormat, "GetProject", input) + out, err := p.Client.UniversalClient.DoCall(p.getUniversalInfo("GetProject"), &input) + if err != nil { + return false, err + } + accountId, err := ObtainSdkValue("Result.AccountID", *out) + if err != nil { + return false, err + } + trnStr := fmt.Sprintf("trn:%s:%s:%d:%s/%s", trn.ServiceName, p.Client.Region, int(accountId.(float64)), + trn.ResourceType, id) + (*call.SdkParam)["ResourceTrn.1"] = trnStr + return true, nil + }, + ExecuteCall: func(d *schema.ResourceData, client *SdkClient, call SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.ReqFormat, call.Action, call.SdkParam) + return p.Client.UniversalClient.DoCall(p.getUniversalInfo(call.Action), call.SdkParam) + }, + Refresh: &StateRefresh{ + Target: []string{resourceData.Get(trn.ProjectSchemaField).(string)}, + Timeout: resourceData.Timeout(schema.TimeoutCreate), + }, + refreshState: func(data *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{} + name interface{} + ) + d, err = service.ReadResource(resourceData, service.ReadResourceId(id)) + if err != nil { + return nil, "", err + } + name, err = ObtainSdkValue(trn.ProjectResponseField, d) + if err != nil { + return nil, "", err + } + + return d, name.(string), err + }, + } + }, + }, + } + call = append(call, modifyProject) + } + return call +} + +func (p *Project) ModifyProjectOld(trn ProjectTrn, resourceData *schema.ResourceData, resource *schema.Resource, key string, sr *StateRefresh) []Callback { var call []Callback if resourceData.HasChange(key) { modifyProject := Callback{ diff --git a/common/common_volcengine_version.go b/common/common_volcengine_version.go index 7c86e63e..1ac73535 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.64" + TerraformProviderVersion = "0.0.65" ) diff --git a/example/crTag/main.tf b/example/crTag/main.tf index d1f9c594..5f042c04 100644 --- a/example/crTag/main.tf +++ b/example/crTag/main.tf @@ -1,4 +1,7 @@ # Tag cannot be created,please import by command `terraform import volcengine_cr_tag.default registry:namespace:repository:tag` -resource "volcengine_cr_tags" "default"{ - +resource "volcengine_cr_tag" "default" { + registry = "enterprise-1" + namespace = "langyu" + repository = "repo" + name = "v2" } \ No newline at end of file diff --git a/example/mongoDBInstance/main.tf b/example/mongoDBInstance/main.tf index e7a69e45..ac5a8420 100644 --- a/example/mongoDBInstance/main.tf +++ b/example/mongoDBInstance/main.tf @@ -10,6 +10,11 @@ resource "volcengine_mongodb_instance" "foo"{ instance_name="mongo-replica-be9995d32e4a" charge_type="PostPaid" super_account_password = "******" + project_name = "default" + tags { + key = "k1" + value = "v1" + } # period_unit="Month" # period=1 # auto_renew=false diff --git a/volcengine/clb/clb/service_volcengine_clb.go b/volcengine/clb/clb/service_volcengine_clb.go index 87cf7169..2cf02441 100644 --- a/volcengine/clb/clb/service_volcengine_clb.go +++ b/volcengine/clb/clb/service_volcengine_clb.go @@ -218,7 +218,7 @@ func (s *VolcengineClbService) ModifyResource(resourceData *schema.ResourceData, var callbacks []ve.Callback //project - projectCallback := ve.NewProjectService(s.Client).ModifyProject(ve.ProjectTrn{ + projectCallback := ve.NewProjectService(s.Client).ModifyProjectOld(ve.ProjectTrn{ ResourceType: "clb", ResourceID: resourceData.Id(), ServiceName: "clb", diff --git a/volcengine/cr/cr_namespace/resource_volcengine_cr_namespace.go b/volcengine/cr/cr_namespace/resource_volcengine_cr_namespace.go index f3dcec2f..e70750a5 100644 --- a/volcengine/cr/cr_namespace/resource_volcengine_cr_namespace.go +++ b/volcengine/cr/cr_namespace/resource_volcengine_cr_namespace.go @@ -37,25 +37,25 @@ func ResourceVolcengineCrNamespace() *schema.Resource { resource := &schema.Resource{ Create: resourceVolcengineCrNamespaceCreate, Read: resourceVolcengineCrNamespaceRead, - Update: resourceVolcengineCrNamespaceUpdate, Delete: resourceVolcengineCrNamespaceDelete, Importer: &schema.ResourceImporter{ State: crNamespaceImporter, }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(30 * time.Minute), }, Schema: map[string]*schema.Schema{ "registry": { Type: schema.TypeString, Required: true, + ForceNew: true, Description: "The registry name.", }, "name": { Type: schema.TypeString, Required: true, + ForceNew: true, Description: "The name of CrNamespace.", }, }, @@ -74,15 +74,6 @@ func resourceVolcengineCrNamespaceCreate(d *schema.ResourceData, meta interface{ return resourceVolcengineCrNamespaceRead(d, meta) } -func resourceVolcengineCrNamespaceUpdate(d *schema.ResourceData, meta interface{}) (err error) { - service := NewCrNamespaceService(meta.(*ve.SdkClient)) - err = ve.DefaultDispatcher().Update(service, d, ResourceVolcengineCrNamespace()) - if err != nil { - return fmt.Errorf("error on updating CrNamespace %q, %s", d.Id(), err) - } - return resourceVolcengineCrNamespaceRead(d, meta) -} - func resourceVolcengineCrNamespaceDelete(d *schema.ResourceData, meta interface{}) (err error) { service := NewCrNamespaceService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Delete(service, d, ResourceVolcengineCrNamespace()) diff --git a/volcengine/cr/cr_registry/resource_volcengine_cr_registry.go b/volcengine/cr/cr_registry/resource_volcengine_cr_registry.go index cf56469c..06e71962 100644 --- a/volcengine/cr/cr_registry/resource_volcengine_cr_registry.go +++ b/volcengine/cr/cr_registry/resource_volcengine_cr_registry.go @@ -36,13 +36,14 @@ func ResourceVolcengineCrRegistry() *schema.Resource { "name": { Type: schema.TypeString, Required: true, + ForceNew: true, Description: "The name of registry.", }, "delete_immediately": { Type: schema.TypeBool, Optional: true, Default: false, - Description: "Whether delete registry immediately.", + Description: "Whether delete registry immediately. Only effected in delete action.", }, "password": { Type: schema.TypeString, diff --git a/volcengine/cr/cr_registry/service_volcengine_cr_registry.go b/volcengine/cr/cr_registry/service_volcengine_cr_registry.go index b7408443..038dab1e 100644 --- a/volcengine/cr/cr_registry/service_volcengine_cr_registry.go +++ b/volcengine/cr/cr_registry/service_volcengine_cr_registry.go @@ -4,9 +4,10 @@ import ( "encoding/base64" "errors" "fmt" - "github.com/google/uuid" "time" + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ve "github.com/volcengine/terraform-provider-volcengine/common" @@ -151,14 +152,6 @@ func (s *VolcengineCrRegistryService) ReadResource(resourceData *schema.Resource if len(data) == 0 { return data, fmt.Errorf("CrRegistry %s is not exist", id) } - - deleteImmediately := resourceData.Get("delete_immediately") - if deleteImmediately == nil { - data["DeleteImmediately"] = false - } else { - data["DeleteImmediately"] = deleteImmediately - } - return data, err } @@ -238,20 +231,10 @@ func (s *VolcengineCrRegistryService) CreateResource(resourceData *schema.Resour callback := ve.Callback{ Call: ve.SdkCall{ Action: action, - ConvertMode: ve.RequestConvertAll, + ConvertMode: ve.RequestConvertIgnore, BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { - registry := resourceData.Id() - password := password.(string) - - if password == "" { - return false, nil - } - - bytes := []byte(password) - passwdBase64 := base64.StdEncoding.EncodeToString(bytes) - - (*call.SdkParam)["Registry"] = registry - (*call.SdkParam)["Password"] = passwdBase64 + (*call.SdkParam)["Registry"] = resourceData.Get("name") + (*call.SdkParam)["Password"] = base64.StdEncoding.EncodeToString([]byte(password.(string))) return true, nil }, ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { @@ -274,18 +257,9 @@ func (s *VolcengineCrRegistryService) ModifyResource(resourceData *schema.Resour Action: action, ConvertMode: ve.RequestConvertIgnore, BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { - registry := resourceData.Id() - password := resourceData.Get("password").(string) - - if password == "" { - return false, nil - } - - bytes := []byte(password) - passwdBase64 := base64.StdEncoding.EncodeToString(bytes) - - (*call.SdkParam)["Registry"] = registry - (*call.SdkParam)["Password"] = passwdBase64 + bytes := []byte(resourceData.Get("password").(string)) + (*call.SdkParam)["Registry"] = resourceData.Get("name") + (*call.SdkParam)["Password"] = base64.StdEncoding.EncodeToString(bytes) return true, nil }, ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { @@ -296,9 +270,6 @@ func (s *VolcengineCrRegistryService) ModifyResource(resourceData *schema.Resour } callbacks = append(callbacks, callback) } - if resourceData.HasChange("delete_immediately") { - resourceData.Set("delete_immediately", resourceData.Get("delete_immediately")) - } return callbacks } diff --git a/volcengine/cr/cr_registry_state/resource_volcengine_cr_registry_state.go b/volcengine/cr/cr_registry_state/resource_volcengine_cr_registry_state.go index b8ce1ef1..a9977f19 100644 --- a/volcengine/cr/cr_registry_state/resource_volcengine_cr_registry_state.go +++ b/volcengine/cr/cr_registry_state/resource_volcengine_cr_registry_state.go @@ -33,16 +33,15 @@ func crRegistryStateImporter(d *schema.ResourceData, m interface{}) ([]*schema.R func ResourceVolcengineCrRegistryState() *schema.Resource { return &schema.Resource{ - Delete: resourceVolcengineCrRegistryStateDelete, Create: resourceVolcengineCrRegistryStateCreate, - Read: resourceVolcengineCrRegistryStateRead, Update: resourceVolcengineCrRegistryStateUpdate, + Read: resourceVolcengineCrRegistryStateRead, + Delete: resourceVolcengineCrRegistryStateDelete, Importer: &schema.ResourceImporter{ State: crRegistryStateImporter, }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(1 * time.Hour), - Update: schema.DefaultTimeout(1 * time.Hour), Delete: schema.DefaultTimeout(1 * time.Hour), }, Schema: map[string]*schema.Schema{ @@ -58,6 +57,7 @@ func ResourceVolcengineCrRegistryState() *schema.Resource { "name": { Type: schema.TypeString, Required: true, + ForceNew: true, Description: "The cr instance id.", }, "status": { @@ -95,6 +95,10 @@ func resourceVolcengineCrRegistryStateCreate(d *schema.ResourceData, meta interf return resourceVolcengineCrRegistryStateRead(d, meta) } +func resourceVolcengineCrRegistryStateUpdate(d *schema.ResourceData, meta interface{}) error { + return fmt.Errorf("this resource does not allow update operation") +} + func resourceVolcengineCrRegistryStateRead(d *schema.ResourceData, meta interface{}) error { service := NewCrRegistryStateService(meta.(*ve.SdkClient)) if err := ve.DefaultDispatcher().Read(service, d, ResourceVolcengineCrRegistryState()); err != nil { @@ -103,14 +107,6 @@ func resourceVolcengineCrRegistryStateRead(d *schema.ResourceData, meta interfac return nil } -func resourceVolcengineCrRegistryStateUpdate(d *schema.ResourceData, meta interface{}) error { - service := NewCrRegistryStateService(meta.(*ve.SdkClient)) - if err := ve.DefaultDispatcher().Update(service, d, ResourceVolcengineCrRegistryState()); err != nil { - return fmt.Errorf("error on updating instance state %q, %w", d.Id(), err) - } - return resourceVolcengineCrRegistryStateRead(d, meta) -} - func resourceVolcengineCrRegistryStateDelete(d *schema.ResourceData, meta interface{}) error { service := NewCrRegistryStateService(meta.(*ve.SdkClient)) if err := ve.DefaultDispatcher().Delete(service, d, ResourceVolcengineCrRegistryState()); err != nil { diff --git a/volcengine/cr/cr_registry_state/service_volcengine_cr_registry_state.go b/volcengine/cr/cr_registry_state/service_volcengine_cr_registry_state.go index 19ad9730..45ec638a 100644 --- a/volcengine/cr/cr_registry_state/service_volcengine_cr_registry_state.go +++ b/volcengine/cr/cr_registry_state/service_volcengine_cr_registry_state.go @@ -219,79 +219,7 @@ func (s *VolcengineCrRegistryStateService) CreateResource(resourceData *schema.R } func (s *VolcengineCrRegistryStateService) ModifyResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { - action := "StartRegistry" - instanceAction := resourceData.Get("action").(string) - if instanceAction != "Start" { - return []ve.Callback{} - } - - name := resourceData.Id() - logger.DebugInfo("CreateResource state:name %s", name) - - callback := ve.Callback{ - Call: ve.SdkCall{ - Action: action, - ConvertMode: ve.RequestConvertAll, - Convert: map[string]ve.RequestConvert{ - "action": { - Ignore: true, - }, - }, - BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { - data, err := s.ReadResource(resourceData, name) - if err != nil { - return false, err - } - - // check instance status,only "{Stopped, [Released]}" can do start. - phase, err := ve.ObtainSdkValue("Status.Phase", data) - if err != nil { - return false, err - } - if phase.(string) != "Stopped" { - return false, fmt.Errorf("CrRegistry status is %s,can not start", phase.(string)) - } - - conditions, err := ve.ObtainSdkValue("Status.Conditions", data) - if err != nil { - return false, err - } - - conds, ok := conditions.([]interface{}) - if !ok { - return false, fmt.Errorf("CrRegistry status conditions not a slice,conditions:%v", conditions) - } - - condHit := false - for _, v := range conds { - if v.(string) == "Released" { - condHit = true - break - } - } - if !condHit { - return false, fmt.Errorf("CrRegistry status is %s,not Released,can not start", name) - } - - (*call.SdkParam)["Name"] = name - return true, 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) - }, - AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error { - id := d.Get("name").(string) - d.SetId(id) - return nil - }, - Refresh: &ve.StateRefresh{ - Target: []string{"Running"}, - Timeout: resourceData.Timeout(schema.TimeoutUpdate), - }, - }, - } - return []ve.Callback{callback} + return []ve.Callback{} } func (s *VolcengineCrRegistryStateService) RemoveResource(resourceData *schema.ResourceData, r *schema.Resource) []ve.Callback { diff --git a/volcengine/cr/cr_tag/resource_volcengine_cr_tag.go b/volcengine/cr/cr_tag/resource_volcengine_cr_tag.go index e3ef98b8..3fb3e6f9 100644 --- a/volcengine/cr/cr_tag/resource_volcengine_cr_tag.go +++ b/volcengine/cr/cr_tag/resource_volcengine_cr_tag.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ve "github.com/volcengine/terraform-provider-volcengine/common" - "github.com/volcengine/terraform-provider-volcengine/logger" ) /* @@ -21,7 +20,6 @@ $ terraform import volcengine_cr_tag.default cr-basic:namespace-1:repo-1:v1 */ func CrTagImporter(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { - logger.DebugInfo("import id:%v", d.Id()) items := strings.Split(d.Id(), ":") if len(items) != 4 { return []*schema.ResourceData{d}, fmt.Errorf("the format of import id must be 'registry:namespace:repository:tag'") @@ -38,20 +36,18 @@ func CrTagImporter(d *schema.ResourceData, m interface{}) ([]*schema.ResourceDat if err := d.Set("name", items[3]); err != nil { return []*schema.ResourceData{d}, err } - logger.DebugInfo("-------------------resourceData:%v", *d) return []*schema.ResourceData{d}, nil } func ResourceVolcengineCrTag() *schema.Resource { resource := &schema.Resource{ Read: resourceVolcengineCrTagRead, + Create: resourceVolcengineCrTagCreate, Delete: resourceVolcengineCrTagDelete, - Update: resourceVolcengineCrTagUpdate, Importer: &schema.ResourceImporter{ State: CrTagImporter, }, Timeouts: &schema.ResourceTimeout{ - Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(30 * time.Minute), }, Schema: map[string]*schema.Schema{ @@ -76,6 +72,7 @@ func ResourceVolcengineCrTag() *schema.Resource { "name": { Type: schema.TypeString, Required: true, + ForceNew: true, Description: "The name of OCI product.", }, }, @@ -86,21 +83,7 @@ func ResourceVolcengineCrTag() *schema.Resource { } func resourceVolcengineCrTagCreate(d *schema.ResourceData, meta interface{}) (err error) { - service := NewCrTagService(meta.(*ve.SdkClient)) - err = ve.DefaultDispatcher().Create(service, d, ResourceVolcengineCrTag()) - if err != nil { - return fmt.Errorf("Error on creating cr tag %q,%s", d.Id(), err) - } - return resourceVolcengineCrTagRead(d, meta) -} - -func resourceVolcengineCrTagUpdate(d *schema.ResourceData, meta interface{}) (err error) { - service := NewCrTagService(meta.(*ve.SdkClient)) - err = ve.DefaultDispatcher().Update(service, d, ResourceVolcengineCrTag()) - if err != nil { - return fmt.Errorf("error on updating cr tag %q, %s", d.Id(), err) - } - return resourceVolcengineCrTagRead(d, meta) + return fmt.Errorf("cr tag only support import") } func resourceVolcengineCrTagDelete(d *schema.ResourceData, meta interface{}) (err error) { @@ -113,7 +96,6 @@ func resourceVolcengineCrTagDelete(d *schema.ResourceData, meta interface{}) (er } func resourceVolcengineCrTagRead(d *schema.ResourceData, meta interface{}) (err error) { - logger.DebugInfo("++++++ resourceVolcengineCrTagRead", d) service := NewCrTagService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Read(service, d, ResourceVolcengineCrTag()) if err != nil { diff --git a/volcengine/cr/cr_tag/service_volcengine_cr_tag.go b/volcengine/cr/cr_tag/service_volcengine_cr_tag.go index 59282307..c27cbd67 100644 --- a/volcengine/cr/cr_tag/service_volcengine_cr_tag.go +++ b/volcengine/cr/cr_tag/service_volcengine_cr_tag.go @@ -49,7 +49,7 @@ func (s *VolcengineCrTagService) ReadResources(m map[string]interface{}) (data [ } } - logger.Debug(logger.RespFormat, action, condition, resp) + logger.Debug(logger.RespFormat, action, condition, *resp) results, err = ve.ObtainSdkValue("Result.Items", *resp) if err != nil { return data, err @@ -113,38 +113,17 @@ func (s *VolcengineCrTagService) ReadResource(resourceData *schema.ResourceData, } func (s *VolcengineCrTagService) RefreshResourceState(resourceData *schema.ResourceData, target []string, timeout time.Duration, name 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{} - ) - demo, err = s.ReadResource(resourceData, name) - if err != nil { - return nil, "", err - } - logger.DebugInfo("Refresh cr tag resp:%v", demo) - - status, err = ve.ObtainSdkValue("Name", demo) - if err != nil { - return nil, "", err - } - return demo, status.(string), err - }, - } + return nil } func (s *VolcengineCrTagService) WithResourceResponseHandlers(instance map[string]interface{}) []ve.ResourceResponseHandler { - handler := func() (map[string]interface{}, map[string]ve.ResponseConvert, error) { - return instance, nil, nil + if _, ok := instance["ImageAttributes"]; !ok { + instance["ImageAttributes"] = []interface{}{} + } + if _, ok := instance["ChartAttribute"]; !ok { + instance["ChartAttribute"] = map[string]interface{}{} } - return []ve.ResourceResponseHandler{handler} + return []ve.ResourceResponseHandler{} } func (s *VolcengineCrTagService) CreateResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { diff --git a/volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go b/volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go index 06ca39cf..06f0326c 100644 --- a/volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go +++ b/volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go @@ -500,7 +500,7 @@ func (s *VolcengineEcsService) ModifyResource(resourceData *schema.ResourceData, ) //project - projectCallback := ve.NewProjectService(s.Client).ModifyProject(ve.ProjectTrn{ + projectCallback := ve.NewProjectService(s.Client).ModifyProjectOld(ve.ProjectTrn{ ResourceType: "instance", ResourceID: resourceData.Id(), ServiceName: "ecs", diff --git a/volcengine/eip/eip_address/service_volcengine_eip_address.go b/volcengine/eip/eip_address/service_volcengine_eip_address.go index 8898e1b0..9750b7e6 100644 --- a/volcengine/eip/eip_address/service_volcengine_eip_address.go +++ b/volcengine/eip/eip_address/service_volcengine_eip_address.go @@ -189,7 +189,7 @@ func (s *VolcengineEipAddressService) ModifyResource(resourceData *schema.Resour var callbacks []ve.Callback //project - projectCallback := ve.NewProjectService(s.Client).ModifyProject(ve.ProjectTrn{ + projectCallback := ve.NewProjectService(s.Client).ModifyProjectOld(ve.ProjectTrn{ ResourceType: "eip", ResourceID: resourceData.Id(), ServiceName: "vpc", diff --git a/volcengine/escloud/instance/resource_volcengine_escloud_instance.go b/volcengine/escloud/instance/resource_volcengine_escloud_instance.go index ba58a6fb..dd1c8032 100644 --- a/volcengine/escloud/instance/resource_volcengine_escloud_instance.go +++ b/volcengine/escloud/instance/resource_volcengine_escloud_instance.go @@ -168,7 +168,7 @@ func ResourceVolcengineESCloudInstance() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - Description: "The maintainable time period for the instance.", + Description: "The maintainable time period for the instance. Works only on modified scenes.", DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { // 创建时不存在这个参数,修改时存在这个参数 return d.Id() == "" @@ -178,7 +178,7 @@ func ResourceVolcengineESCloudInstance() *schema.Resource { Type: schema.TypeList, Optional: true, Computed: true, - Description: "The maintainable date for the instance.", + Description: "The maintainable date for the instance. Works only on modified scenes.", DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { // 创建时不存在这个参数,修改时存在这个参数 return d.Id() == "" diff --git a/volcengine/escloud/instance/service_volcengine_escloud_instance.go b/volcengine/escloud/instance/service_volcengine_escloud_instance.go index e39ce6df..b8947ecc 100644 --- a/volcengine/escloud/instance/service_volcengine_escloud_instance.go +++ b/volcengine/escloud/instance/service_volcengine_escloud_instance.go @@ -4,11 +4,12 @@ import ( "encoding/json" "errors" "fmt" - "github.com/google/uuid" "strconv" "strings" "time" + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ve "github.com/volcengine/terraform-provider-volcengine/common" @@ -145,21 +146,21 @@ func (s *VolcengineESCloudInstanceService) ReadResource(resourceData *schema.Res return data, fmt.Errorf("Instance %s not exist ", id) } // Fixme: 临时解决方案 - if data["MaintenanceTime"] != "" { - data["InstanceConfiguration"].(map[string]interface{})["MaintenanceTime"] = data["MaintenanceTime"] + if val := data["MaintenanceTime"]; val != "" { + data["InstanceConfiguration"].(map[string]interface{})["MaintenanceTime"] = val } - if data["MaintenanceDay"] != nil { - data["InstanceConfiguration"].(map[string]interface{})["MaintenanceDay"] = data["MaintenanceDay"] + if val := data["MaintenanceDay"]; val != nil { + data["InstanceConfiguration"].(map[string]interface{})["MaintenanceDay"] = val } - if resourceData.Get("instance_configuration.0.admin_password") != "" { - data["InstanceConfiguration"].(map[string]interface{})["AdminPassword"] = resourceData.Get("instance_configuration.0.admin_password") + if val := resourceData.Get("instance_configuration.0.admin_password"); val != "" { + data["InstanceConfiguration"].(map[string]interface{})["AdminPassword"] = val } - if resourceData.Get("instance_configuration.0.configuration_code") != "" { - data["InstanceConfiguration"].(map[string]interface{})["ConfigurationCode"] = resourceData.Get("instance_configuration.0.configuration_code") + if val := resourceData.Get("instance_configuration.0.configuration_code"); val != "" { + data["InstanceConfiguration"].(map[string]interface{})["ConfigurationCode"] = val } assigns := resourceData.Get("instance_configuration.0.node_specs_assigns") if assigns != nil && len(assigns.([]interface{})) > 0 { - data["InstanceConfiguration"].(map[string]interface{})["NodeSpecsAssigns"] = resourceData.Get("instance_configuration.0.node_specs_assigns") + data["InstanceConfiguration"].(map[string]interface{})["NodeSpecsAssigns"] = assigns } if subnet, ok := data["InstanceConfiguration"].(map[string]interface{})["Subnet"]; ok { data["InstanceConfiguration"].(map[string]interface{})["SubnetId"] = subnet.(map[string]interface{})["SubnetId"] diff --git a/volcengine/mongodb/instance/service_volcengine_mongodb_instance.go b/volcengine/mongodb/instance/service_volcengine_mongodb_instance.go index b1db1f71..14b64e0e 100644 --- a/volcengine/mongodb/instance/service_volcengine_mongodb_instance.go +++ b/volcengine/mongodb/instance/service_volcengine_mongodb_instance.go @@ -696,6 +696,15 @@ func (s *VolcengineMongoDBInstanceService) setResourceTags(resourceData *schema. return callbacks } +func (s *VolcengineMongoDBInstanceService) ProjectTrn() *ve.ProjectTrn { + return &ve.ProjectTrn{ + ServiceName: "mongodb", + ResourceType: "instance", + ProjectResponseField: "ProjectName", + ProjectSchemaField: "project_name", + } +} + func getUniversalInfo(actionName string) ve.UniversalInfo { return ve.UniversalInfo{ ServiceName: "mongodb", diff --git a/volcengine/rds_v2/rds_instance_v2/service_volcengine_rds_instance_v2.go b/volcengine/rds_v2/rds_instance_v2/service_volcengine_rds_instance_v2.go index a00b0ac2..c5819c60 100644 --- a/volcengine/rds_v2/rds_instance_v2/service_volcengine_rds_instance_v2.go +++ b/volcengine/rds_v2/rds_instance_v2/service_volcengine_rds_instance_v2.go @@ -411,7 +411,7 @@ func (s *VolcengineRdsInstanceService) ModifyResource(resourceData *schema.Resou callbacks := make([]volc.Callback, 0) //project - projectCallback := volc.NewProjectService(s.Client).ModifyProject(volc.ProjectTrn{ + projectCallback := volc.NewProjectService(s.Client).ModifyProjectOld(volc.ProjectTrn{ ResourceType: "instance", ResourceID: resourceData.Id(), ServiceName: "rds_mysql", 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 15e7001e..0e25a0c1 100644 --- a/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go +++ b/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go @@ -68,8 +68,8 @@ func ResourceVolcengineNodePool() *schema.Resource { Type: schema.TypeInt, Optional: true, Default: 10, - ValidateFunc: validation.IntBetween(0, 1000), - Description: "The MaxReplicas of AutoScaling, default 10, range in 1~1000.", + ValidateFunc: validation.IntBetween(0, 2000), + Description: "The MaxReplicas of AutoScaling, default 10, range in 1~2000.", }, "min_replicas": { Type: schema.TypeInt, diff --git a/volcengine/vpc/vpc/service_volcengine_vpc.go b/volcengine/vpc/vpc/service_volcengine_vpc.go index ff1cca5c..c49d6ec3 100644 --- a/volcengine/vpc/vpc/service_volcengine_vpc.go +++ b/volcengine/vpc/vpc/service_volcengine_vpc.go @@ -21,6 +21,15 @@ func NewVpcService(c *ve.SdkClient) *VolcengineVpcService { } } +//func (s *VolcengineVpcService) ProjectTrn() *ve.ProjectTrn { +// return &ve.ProjectTrn{ +// ServiceName: "vpc", +// ResourceType: "vpc", +// ProjectSchemaField: "project_name", +// ProjectResponseField: "ProjectName", +// } +//} + func (s *VolcengineVpcService) GetClient() *ve.SdkClient { return s.Client } diff --git a/website/docs/r/cr_namespace.html.markdown b/website/docs/r/cr_namespace.html.markdown index 3c25d4ec..2bc0f665 100644 --- a/website/docs/r/cr_namespace.html.markdown +++ b/website/docs/r/cr_namespace.html.markdown @@ -22,8 +22,8 @@ resource "volcengine_cr_namespace" "foo1" { ``` ## Argument Reference The following arguments are supported: -* `name` - (Required) The name of CrNamespace. -* `registry` - (Required) The registry name. +* `name` - (Required, ForceNew) The name of CrNamespace. +* `registry` - (Required, ForceNew) The registry name. ## Attributes Reference In addition to all arguments above, the following attributes are exported: diff --git a/website/docs/r/cr_registry.html.markdown b/website/docs/r/cr_registry.html.markdown index 9e9d16d5..d96e9e96 100644 --- a/website/docs/r/cr_registry.html.markdown +++ b/website/docs/r/cr_registry.html.markdown @@ -18,8 +18,8 @@ resource "volcengine_cr_registry" "foo" { ``` ## Argument Reference The following arguments are supported: -* `name` - (Required) The name of registry. -* `delete_immediately` - (Optional) Whether delete registry immediately. +* `name` - (Required, ForceNew) The name of registry. +* `delete_immediately` - (Optional) Whether delete registry immediately. Only effected in delete action. * `password` - (Optional) The password of registry user. ## Attributes Reference diff --git a/website/docs/r/cr_registry_state.html.markdown b/website/docs/r/cr_registry_state.html.markdown index a49e2f71..2a968bcb 100644 --- a/website/docs/r/cr_registry_state.html.markdown +++ b/website/docs/r/cr_registry_state.html.markdown @@ -18,7 +18,7 @@ resource "volcengine_cr_registry_state" "foo" { ## Argument Reference The following arguments are supported: * `action` - (Required) Start cr instance action,the value must be `Start`. -* `name` - (Required) The cr instance id. +* `name` - (Required, ForceNew) The cr instance id. ## Attributes Reference In addition to all arguments above, the following attributes are exported: diff --git a/website/docs/r/cr_tag.html.markdown b/website/docs/r/cr_tag.html.markdown index b3afb7ca..ced973c4 100644 --- a/website/docs/r/cr_tag.html.markdown +++ b/website/docs/r/cr_tag.html.markdown @@ -11,13 +11,16 @@ Provides a resource to manage cr tag ## Example Usage ```hcl # Tag cannot be created,please import by command `terraform import volcengine_cr_tag.default registry:namespace:repository:tag` -resource "volcengine_cr_tags" "default" { - +resource "volcengine_cr_tag" "default" { + registry = "enterprise-1" + namespace = "langyu" + repository = "repo" + name = "v2" } ``` ## Argument Reference The following arguments are supported: -* `name` - (Required) The name of OCI product. +* `name` - (Required, ForceNew) The name of OCI product. * `namespace` - (Required, ForceNew) The target namespace name. * `registry` - (Required, ForceNew) The CrRegistry name. * `repository` - (Required, ForceNew) The name of repository. diff --git a/website/docs/r/escloud_instance.html.markdown b/website/docs/r/escloud_instance.html.markdown index 9f2c681f..8eadead0 100644 --- a/website/docs/r/escloud_instance.html.markdown +++ b/website/docs/r/escloud_instance.html.markdown @@ -64,8 +64,8 @@ The `instance_configuration` object supports the following: * `zone_number` - (Required, ForceNew) The zone count of the ESCloud instance used. * `force_restart_after_scale` - (Optional) Whether to force restart when changes are made. If true, it means that the cluster will be forced to restart without paying attention to instance availability. * `instance_name` - (Optional) The name of ESCloud instance. -* `maintenance_day` - (Optional) The maintainable date for the instance. -* `maintenance_time` - (Optional) The maintainable time period for the instance. +* `maintenance_day` - (Optional) The maintainable date for the instance. Works only on modified scenes. +* `maintenance_time` - (Optional) The maintainable time period for the instance. Works only on modified scenes. * `project_name` - (Optional) The project name to which the ESCloud instance belongs. * `region_id` - (Optional) The region ID of ESCloud instance. * `zone_id` - (Optional) The available zone ID of ESCloud instance. diff --git a/website/docs/r/mongodb_instance.html.markdown b/website/docs/r/mongodb_instance.html.markdown index af5cb724..34ea9a56 100644 --- a/website/docs/r/mongodb_instance.html.markdown +++ b/website/docs/r/mongodb_instance.html.markdown @@ -22,6 +22,11 @@ resource "volcengine_mongodb_instance" "foo" { instance_name = "mongo-replica-be9995d32e4a" charge_type = "PostPaid" super_account_password = "******" + project_name = "default" + tags { + key = "k1" + value = "v1" + } # period_unit="Month" # period=1 # auto_renew=false diff --git a/website/docs/r/vke_node_pool.html.markdown b/website/docs/r/vke_node_pool.html.markdown index b28874c1..a7b59f66 100644 --- a/website/docs/r/vke_node_pool.html.markdown +++ b/website/docs/r/vke_node_pool.html.markdown @@ -65,7 +65,7 @@ The `auto_scaling` object supports the following: * `desired_replicas` - (Optional) The DesiredReplicas of AutoScaling, default 0, range in min_replicas to max_replicas. * `enabled` - (Optional) Is Enabled of AutoScaling. -* `max_replicas` - (Optional) The MaxReplicas of AutoScaling, default 10, range in 1~1000. +* `max_replicas` - (Optional) The MaxReplicas of AutoScaling, default 10, range in 1~2000. * `min_replicas` - (Optional) The MinReplicas of AutoScaling, default 0. * `priority` - (Optional) The Priority of AutoScaling, default 10, rang in 0~100.