|
| 1 | +/* |
| 2 | +Provides a resource to create a mps enable_workflow_config |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +Enable the mps workflow |
| 7 | +
|
| 8 | +```hcl |
| 9 | +resource "tencentcloud_mps_workflow" "example" { |
| 10 | + output_dir = "/" |
| 11 | + task_priority = 0 |
| 12 | + workflow_name = "tf-workflow-enable-config" |
| 13 | +
|
| 14 | + media_process_task { |
| 15 | + adaptive_dynamic_streaming_task_set { |
| 16 | + definition = 12 |
| 17 | + output_object_path = "/out" |
| 18 | + segment_object_name = "/out" |
| 19 | + sub_stream_object_name = "/out/out/" |
| 20 | +
|
| 21 | + output_storage { |
| 22 | + type = "COS" |
| 23 | +
|
| 24 | + cos_output_storage { |
| 25 | + bucket = "cos-lock-1308919341" |
| 26 | + region = "ap-guangzhou" |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | +
|
| 31 | + snapshot_by_time_offset_task_set { |
| 32 | + definition = 10 |
| 33 | + ext_time_offset_set = [ |
| 34 | + "1s", |
| 35 | + ] |
| 36 | + output_object_path = "/snapshot/" |
| 37 | + time_offset_set = [] |
| 38 | +
|
| 39 | + output_storage { |
| 40 | + type = "COS" |
| 41 | +
|
| 42 | + cos_output_storage { |
| 43 | + bucket = "cos-lock-1308919341" |
| 44 | + region = "ap-guangzhou" |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | +
|
| 49 | + animated_graphic_task_set { |
| 50 | + definition = 20000 |
| 51 | + end_time_offset = 0 |
| 52 | + output_object_path = "/test/" |
| 53 | + start_time_offset = 0 |
| 54 | +
|
| 55 | + output_storage { |
| 56 | + type = "COS" |
| 57 | +
|
| 58 | + cos_output_storage { |
| 59 | + bucket = "cos-lock-1308919341" |
| 60 | + region = "ap-guangzhou" |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +
|
| 66 | + ai_analysis_task { |
| 67 | + definition = 20 |
| 68 | + } |
| 69 | +
|
| 70 | + ai_content_review_task { |
| 71 | + definition = 20 |
| 72 | + } |
| 73 | +
|
| 74 | + ai_recognition_task { |
| 75 | + definition = 20 |
| 76 | + } |
| 77 | +
|
| 78 | + output_storage { |
| 79 | + type = "COS" |
| 80 | +
|
| 81 | + cos_output_storage { |
| 82 | + bucket = "cos-lock-1308919341" |
| 83 | + region = "ap-guangzhou" |
| 84 | + } |
| 85 | + } |
| 86 | +
|
| 87 | + trigger { |
| 88 | + type = "CosFileUpload" |
| 89 | +
|
| 90 | + cos_file_upload_trigger { |
| 91 | + bucket = "cos-lock-1308919341" |
| 92 | + dir = "/" |
| 93 | + region = "ap-guangzhou" |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | +
|
| 98 | +resource "tencentcloud_mps_enable_workflow_config" "config" { |
| 99 | + workflow_id = tencentcloud_mps_workflow.example.id |
| 100 | + enabled = true |
| 101 | +} |
| 102 | +
|
| 103 | +``` |
| 104 | +
|
| 105 | +Disable the mps workflow |
| 106 | +
|
| 107 | +```hcl |
| 108 | +resource "tencentcloud_mps_enable_workflow_config" "config" { |
| 109 | + workflow_id = tencentcloud_mps_workflow.example.id |
| 110 | + enabled = false |
| 111 | +} |
| 112 | +
|
| 113 | +``` |
| 114 | +
|
| 115 | +Import |
| 116 | +
|
| 117 | +mps enable_workflow_config can be imported using the id, e.g. |
| 118 | +
|
| 119 | +``` |
| 120 | +terraform import tencentcloud_mps_enable_workflow_config.enable_workflow_config enable_workflow_config_id |
| 121 | +``` |
| 122 | +*/ |
| 123 | +package tencentcloud |
| 124 | + |
| 125 | +import ( |
| 126 | + "context" |
| 127 | + "log" |
| 128 | + |
| 129 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 130 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 131 | + mps "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mps/v20190612" |
| 132 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 133 | +) |
| 134 | + |
| 135 | +func resourceTencentCloudMpsEnableWorkflowConfig() *schema.Resource { |
| 136 | + return &schema.Resource{ |
| 137 | + Create: resourceTencentCloudMpsEnableWorkflowConfigCreate, |
| 138 | + Read: resourceTencentCloudMpsEnableWorkflowConfigRead, |
| 139 | + Update: resourceTencentCloudMpsEnableWorkflowConfigUpdate, |
| 140 | + Delete: resourceTencentCloudMpsEnableWorkflowConfigDelete, |
| 141 | + Importer: &schema.ResourceImporter{ |
| 142 | + State: schema.ImportStatePassthrough, |
| 143 | + }, |
| 144 | + Schema: map[string]*schema.Schema{ |
| 145 | + "workflow_id": { |
| 146 | + Required: true, |
| 147 | + Type: schema.TypeInt, |
| 148 | + Description: "Workflow ID.", |
| 149 | + }, |
| 150 | + |
| 151 | + "enabled": { |
| 152 | + Required: true, |
| 153 | + Type: schema.TypeBool, |
| 154 | + Description: "true: enable; false: disable.", |
| 155 | + }, |
| 156 | + }, |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +func resourceTencentCloudMpsEnableWorkflowConfigCreate(d *schema.ResourceData, meta interface{}) error { |
| 161 | + defer logElapsed("resource.tencentcloud_mps_enable_workflow_config.create")() |
| 162 | + defer inconsistentCheck(d, meta)() |
| 163 | + |
| 164 | + var workflowId int |
| 165 | + if v, ok := d.GetOkExists("workflow_id"); ok { |
| 166 | + workflowId = v.(int) |
| 167 | + } |
| 168 | + d.SetId(helper.IntToStr(workflowId)) |
| 169 | + |
| 170 | + return resourceTencentCloudMpsEnableWorkflowConfigUpdate(d, meta) |
| 171 | +} |
| 172 | + |
| 173 | +func resourceTencentCloudMpsEnableWorkflowConfigRead(d *schema.ResourceData, meta interface{}) error { |
| 174 | + defer logElapsed("resource.tencentcloud_mps_enable_workflow_config.read")() |
| 175 | + defer inconsistentCheck(d, meta)() |
| 176 | + |
| 177 | + logId := getLogId(contextNil) |
| 178 | + |
| 179 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 180 | + |
| 181 | + service := MpsService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 182 | + |
| 183 | + workflowId := d.Id() |
| 184 | + |
| 185 | + enableWorkflowConfig, err := service.DescribeMpsWorkflowById(ctx, workflowId) |
| 186 | + if err != nil { |
| 187 | + return err |
| 188 | + } |
| 189 | + |
| 190 | + if enableWorkflowConfig == nil { |
| 191 | + d.SetId("") |
| 192 | + log.Printf("[WARN]%s resource `MpsEnableWorkflowConfig` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) |
| 193 | + return nil |
| 194 | + } |
| 195 | + |
| 196 | + if enableWorkflowConfig.WorkflowId != nil { |
| 197 | + _ = d.Set("workflow_id", enableWorkflowConfig.WorkflowId) |
| 198 | + } |
| 199 | + |
| 200 | + status := enableWorkflowConfig.Status |
| 201 | + if status != nil { |
| 202 | + if *status == "Enabled" { |
| 203 | + _ = d.Set("enabled", true) |
| 204 | + } else { |
| 205 | + _ = d.Set("enabled", false) |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + return nil |
| 210 | +} |
| 211 | + |
| 212 | +func resourceTencentCloudMpsEnableWorkflowConfigUpdate(d *schema.ResourceData, meta interface{}) error { |
| 213 | + defer logElapsed("resource.tencentcloud_mps_enable_workflow_config.update")() |
| 214 | + defer inconsistentCheck(d, meta)() |
| 215 | + |
| 216 | + logId := getLogId(contextNil) |
| 217 | + |
| 218 | + var ( |
| 219 | + enableRequest = mps.NewEnableWorkflowRequest() |
| 220 | + disableRequest = mps.NewDisableWorkflowRequest() |
| 221 | + workflowId *int64 |
| 222 | + enabled bool |
| 223 | + ) |
| 224 | + |
| 225 | + workflowId = helper.StrToInt64Point(d.Id()) |
| 226 | + |
| 227 | + if v, ok := d.GetOkExists("enabled"); ok && v != nil { |
| 228 | + enabled = v.(bool) |
| 229 | + |
| 230 | + if enabled { |
| 231 | + enableRequest.WorkflowId = workflowId |
| 232 | + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { |
| 233 | + result, e := meta.(*TencentCloudClient).apiV3Conn.UseMpsClient().EnableWorkflow(enableRequest) |
| 234 | + if e != nil { |
| 235 | + return retryError(e) |
| 236 | + } else { |
| 237 | + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, enableRequest.GetAction(), enableRequest.ToJsonString(), result.ToJsonString()) |
| 238 | + } |
| 239 | + return nil |
| 240 | + }) |
| 241 | + if err != nil { |
| 242 | + log.Printf("[CRITAL]%s operate mps enableWorkflowConfig failed, reason:%+v", logId, err) |
| 243 | + return err |
| 244 | + } |
| 245 | + } else { |
| 246 | + disableRequest.WorkflowId = workflowId |
| 247 | + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { |
| 248 | + result, e := meta.(*TencentCloudClient).apiV3Conn.UseMpsClient().DisableWorkflow(disableRequest) |
| 249 | + if e != nil { |
| 250 | + return retryError(e) |
| 251 | + } else { |
| 252 | + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, disableRequest.GetAction(), disableRequest.ToJsonString(), result.ToJsonString()) |
| 253 | + } |
| 254 | + return nil |
| 255 | + }) |
| 256 | + if err != nil { |
| 257 | + log.Printf("[CRITAL]%s operate mps disableWorkflowConfig failed, reason:%+v", logId, err) |
| 258 | + return err |
| 259 | + } |
| 260 | + } |
| 261 | + } |
| 262 | + |
| 263 | + return resourceTencentCloudMpsEnableWorkflowConfigRead(d, meta) |
| 264 | +} |
| 265 | + |
| 266 | +func resourceTencentCloudMpsEnableWorkflowConfigDelete(d *schema.ResourceData, meta interface{}) error { |
| 267 | + defer logElapsed("resource.tencentcloud_mps_enable_workflow_config.delete")() |
| 268 | + defer inconsistentCheck(d, meta)() |
| 269 | + |
| 270 | + return nil |
| 271 | +} |
0 commit comments