|
| 1 | +package wedata |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "log" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 9 | + wedatav20250806 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata/v20250806" |
| 10 | + |
| 11 | + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" |
| 12 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 13 | +) |
| 14 | + |
| 15 | +func ResourceTencentCloudWedataAddCalcEnginesToProjectOperation() *schema.Resource { |
| 16 | + return &schema.Resource{ |
| 17 | + Create: resourceTencentCloudWedataAddCalcEnginesToProjectOperationCreate, |
| 18 | + Read: resourceTencentCloudWedataAddCalcEnginesToProjectOperationRead, |
| 19 | + Delete: resourceTencentCloudWedataAddCalcEnginesToProjectOperationDelete, |
| 20 | + Schema: map[string]*schema.Schema{ |
| 21 | + "project_id": { |
| 22 | + Type: schema.TypeString, |
| 23 | + Required: true, |
| 24 | + ForceNew: true, |
| 25 | + Description: "Project ID to be modified.", |
| 26 | + }, |
| 27 | + |
| 28 | + "dlc_info": { |
| 29 | + Type: schema.TypeList, |
| 30 | + Required: true, |
| 31 | + ForceNew: true, |
| 32 | + Description: "DLC cluster information.", |
| 33 | + Elem: &schema.Resource{ |
| 34 | + Schema: map[string]*schema.Schema{ |
| 35 | + "compute_resources": { |
| 36 | + Type: schema.TypeSet, |
| 37 | + Required: true, |
| 38 | + Description: "DLC resource names (need to add role Uin to DLC, otherwise resources may not be available).", |
| 39 | + Elem: &schema.Schema{ |
| 40 | + Type: schema.TypeString, |
| 41 | + }, |
| 42 | + }, |
| 43 | + "region": { |
| 44 | + Type: schema.TypeString, |
| 45 | + Required: true, |
| 46 | + Description: "DLC region.", |
| 47 | + }, |
| 48 | + "default_database": { |
| 49 | + Type: schema.TypeString, |
| 50 | + Required: true, |
| 51 | + Description: "Specify the default database for the DLC cluster.", |
| 52 | + }, |
| 53 | + "standard_mode_env_tag": { |
| 54 | + Type: schema.TypeString, |
| 55 | + Optional: true, |
| 56 | + Description: "Cluster configuration tag (only effective for standard mode projects and required for standard mode). Enum values:\n- Prod (Production environment)\n- Dev (Development environment).", |
| 57 | + }, |
| 58 | + "access_account": { |
| 59 | + Type: schema.TypeString, |
| 60 | + Optional: true, |
| 61 | + Description: "Access account (only effective for standard mode projects and required for standard mode), used to submit DLC tasks.\nIt is recommended to use a specified sub-account and set corresponding database table permissions for the sub-account; task runner mode may cause task failures when the responsible person leaves; main account mode is not easy for permission control when multiple projects have different permissions.\n\nEnum values:\n- TASK_RUNNER (Task Runner)\n- OWNER (Main Account Mode)\n- SUB (Sub-Account Mode).", |
| 62 | + }, |
| 63 | + "sub_account_uin": { |
| 64 | + Type: schema.TypeString, |
| 65 | + Optional: true, |
| 66 | + Description: "Sub-account ID (only effective for standard mode projects), when AccessAccount is in sub-account mode, the sub-account ID information needs to be specified, other modes do not need to be specified.", |
| 67 | + }, |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +func resourceTencentCloudWedataAddCalcEnginesToProjectOperationCreate(d *schema.ResourceData, meta interface{}) error { |
| 76 | + defer tccommon.LogElapsed("resource.tencentcloud_wedata_add_calc_engines_to_project_operation.create")() |
| 77 | + defer tccommon.InconsistentCheck(d, meta)() |
| 78 | + |
| 79 | + var ( |
| 80 | + logId = tccommon.GetLogId(tccommon.ContextNil) |
| 81 | + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) |
| 82 | + request = wedatav20250806.NewAddCalcEnginesToProjectRequest() |
| 83 | + projectId string |
| 84 | + ) |
| 85 | + |
| 86 | + if v, ok := d.GetOk("project_id"); ok { |
| 87 | + request.ProjectId = helper.String(v.(string)) |
| 88 | + projectId = v.(string) |
| 89 | + } |
| 90 | + |
| 91 | + if v, ok := d.GetOk("dlc_info"); ok { |
| 92 | + for _, item := range v.([]interface{}) { |
| 93 | + dLCInfoMap := item.(map[string]interface{}) |
| 94 | + dLCClusterInfo := wedatav20250806.DLCClusterInfo{} |
| 95 | + if v, ok := dLCInfoMap["compute_resources"]; ok { |
| 96 | + computeResourcesSet := v.(*schema.Set).List() |
| 97 | + for i := range computeResourcesSet { |
| 98 | + computeResources := computeResourcesSet[i].(string) |
| 99 | + dLCClusterInfo.ComputeResources = append(dLCClusterInfo.ComputeResources, helper.String(computeResources)) |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + if v, ok := dLCInfoMap["region"].(string); ok && v != "" { |
| 104 | + dLCClusterInfo.Region = helper.String(v) |
| 105 | + } |
| 106 | + |
| 107 | + if v, ok := dLCInfoMap["default_database"].(string); ok && v != "" { |
| 108 | + dLCClusterInfo.DefaultDatabase = helper.String(v) |
| 109 | + } |
| 110 | + |
| 111 | + if v, ok := dLCInfoMap["standard_mode_env_tag"].(string); ok && v != "" { |
| 112 | + dLCClusterInfo.StandardModeEnvTag = helper.String(v) |
| 113 | + } |
| 114 | + |
| 115 | + if v, ok := dLCInfoMap["access_account"].(string); ok && v != "" { |
| 116 | + dLCClusterInfo.AccessAccount = helper.String(v) |
| 117 | + } |
| 118 | + |
| 119 | + if v, ok := dLCInfoMap["sub_account_uin"].(string); ok && v != "" { |
| 120 | + dLCClusterInfo.SubAccountUin = helper.String(v) |
| 121 | + } |
| 122 | + |
| 123 | + request.DLCInfo = append(request.DLCInfo, &dLCClusterInfo) |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { |
| 128 | + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseWedataV20250806Client().AddCalcEnginesToProjectWithContext(ctx, request) |
| 129 | + if e != nil { |
| 130 | + return tccommon.RetryError(e) |
| 131 | + } else { |
| 132 | + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) |
| 133 | + } |
| 134 | + |
| 135 | + return nil |
| 136 | + }) |
| 137 | + |
| 138 | + if reqErr != nil { |
| 139 | + log.Printf("[CRITAL]%s create wedata add calc engines to project operation failed, reason:%+v", logId, reqErr) |
| 140 | + return reqErr |
| 141 | + } |
| 142 | + |
| 143 | + d.SetId(projectId) |
| 144 | + return resourceTencentCloudWedataAddCalcEnginesToProjectOperationRead(d, meta) |
| 145 | +} |
| 146 | + |
| 147 | +func resourceTencentCloudWedataAddCalcEnginesToProjectOperationRead(d *schema.ResourceData, meta interface{}) error { |
| 148 | + defer tccommon.LogElapsed("resource.tencentcloud_wedata_add_calc_engines_to_project_operation.read")() |
| 149 | + defer tccommon.InconsistentCheck(d, meta)() |
| 150 | + |
| 151 | + return nil |
| 152 | +} |
| 153 | + |
| 154 | +func resourceTencentCloudWedataAddCalcEnginesToProjectOperationDelete(d *schema.ResourceData, meta interface{}) error { |
| 155 | + defer tccommon.LogElapsed("resource.tencentcloud_wedata_add_calc_engines_to_project_operation.delete")() |
| 156 | + defer tccommon.InconsistentCheck(d, meta)() |
| 157 | + |
| 158 | + return nil |
| 159 | +} |
0 commit comments