diff --git a/.changelog/3083.txt b/.changelog/3083.txt new file mode 100644 index 0000000000..3023edb84e --- /dev/null +++ b/.changelog/3083.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_tat_command: update code and doc +``` diff --git a/tencentcloud/services/tat/resource_tc_tat_command.go b/tencentcloud/services/tat/resource_tc_tat_command.go index efee42a94f..ee68af431b 100644 --- a/tencentcloud/services/tat/resource_tc_tat_command.go +++ b/tencentcloud/services/tat/resource_tc_tat_command.go @@ -16,8 +16,8 @@ import ( func ResourceTencentCloudTatCommand() *schema.Resource { return &schema.Resource{ - Read: resourceTencentCloudTatCommandRead, Create: resourceTencentCloudTatCommandCreate, + Read: resourceTencentCloudTatCommandRead, Update: resourceTencentCloudTatCommandUpdate, Delete: resourceTencentCloudTatCommandDelete, Importer: &schema.ResourceImporter{ @@ -33,7 +33,7 @@ func ResourceTencentCloudTatCommand() *schema.Resource { "content": { Type: schema.TypeString, Required: true, - Description: "Command. The maximum length of Base64 encoding is 64KB.", + Description: "Base64-encoded command. The maximum length is 64 KB.", }, "description": { @@ -69,7 +69,7 @@ func ResourceTencentCloudTatCommand() *schema.Resource { "default_parameters": { Type: schema.TypeString, Optional: true, - Description: "The default value of the custom parameter value when it is enabled. The field type is JSON encoded string. For example, {&#39;varA&#39;: &#39;222&#39;}.`key` is the name of the custom parameter and value is the default value. Both `key` and `value` are strings.If no parameter value is provided in the `InvokeCommand` API, the default value is used.Up to 20 custom parameters are supported.The name of the custom parameter cannot exceed 64 characters and can contain [a-z], [A-Z], [0-9] and [-_].", + Description: "The default value of the custom parameter value when it is enabled. The field type is JSON encoded string. For example, {\"varA\": \"222\"}.`key` is the name of the custom parameter and value is the default value. Both `key` and `value` are strings.If no parameter value is provided in the `InvokeCommand` API, the default value is used.Up to 20 custom parameters are supported.The name of the custom parameter cannot exceed 64 characters and can contain [a-z], [A-Z], [0-9] and [-_].", }, "tags": { @@ -141,9 +141,8 @@ func resourceTencentCloudTatCommandCreate(d *schema.ResourceData, meta interface defer tccommon.LogElapsed("resource.tencentcloud_tat_command.create")() defer tccommon.InconsistentCheck(d, meta)() - logId := tccommon.GetLogId(tccommon.ContextNil) - var ( + logId = tccommon.GetLogId(tccommon.ContextNil) request = tat.NewCreateCommandRequest() response *tat.CreateCommandResponse commandId string @@ -169,11 +168,11 @@ func resourceTencentCloudTatCommandCreate(d *schema.ResourceData, meta interface request.WorkingDirectory = helper.String(v.(string)) } - if v, ok := d.GetOk("timeout"); ok { + if v, ok := d.GetOkExists("timeout"); ok { request.Timeout = helper.IntUint64(v.(int)) } - if v, _ := d.GetOk("enable_parameter"); v != nil { + if v, ok := d.GetOkExists("enable_parameter"); ok { request.EnableParameter = helper.Bool(v.(bool)) } @@ -216,6 +215,11 @@ func resourceTencentCloudTatCommandCreate(d *schema.ResourceData, meta interface log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Create tat command failed, Response is nil.")) + } + response = result return nil }) @@ -225,6 +229,10 @@ func resourceTencentCloudTatCommandCreate(d *schema.ResourceData, meta interface return err } + if response.Response.CommandId == nil { + return fmt.Errorf("CommandId is nil.") + } + commandId = *response.Response.CommandId d.SetId(commandId) @@ -341,9 +349,16 @@ func resourceTencentCloudTatCommandUpdate(d *schema.ResourceData, meta interface defer tccommon.InconsistentCheck(d, meta)() logId := tccommon.GetLogId(tccommon.ContextNil) - request := tat.NewModifyCommandRequest() + if d.HasChange("enable_parameter") { + return fmt.Errorf("`enable_parameter` do not support change now.") + } + + if d.HasChange("tags") { + return fmt.Errorf("`tags` do not support change now.") + } + commandId := d.Id() request.CommandId = &commandId @@ -383,20 +398,12 @@ func resourceTencentCloudTatCommandUpdate(d *schema.ResourceData, meta interface } } - if d.HasChange("enable_parameter") { - return fmt.Errorf("`enable_parameter` do not support change now.") - } - if d.HasChange("default_parameters") { if v, ok := d.GetOk("default_parameters"); ok { request.DefaultParameters = helper.String(v.(string)) } } - if d.HasChange("tags") { - return fmt.Errorf("`tags` do not support change now.") - } - if d.HasChange("username") { if v, ok := d.GetOk("username"); ok { request.Username = helper.String(v.(string)) diff --git a/tencentcloud/services/tat/resource_tc_tat_command.md b/tencentcloud/services/tat/resource_tc_tat_command.md index 71f13f317a..d8db46dc93 100644 --- a/tencentcloud/services/tat/resource_tc_tat_command.md +++ b/tencentcloud/services/tat/resource_tc_tat_command.md @@ -1,26 +1,33 @@ -Provides a resource to create a tat command +Provides a resource to create a TAT command Example Usage ```hcl -resource "tencentcloud_tat_command" "command" { +resource "tencentcloud_tat_command" "example" { username = "root" - command_name = "ls" - content = "bHM=" - description = "xxx" + command_name = "tf-example" + content = <&2 + exit 1 +fi +ps aux +EOF + description = "Terraform demo." command_type = "SHELL" working_directory = "/root" - timeout = 50 + timeout = 50 tags { - key = "" - value = "" + key = "createBy" + value = "Terraform" } } - ``` + Import tat command can be imported using the id, e.g. ``` -$ terraform import tencentcloud_tat_command.command cmd-6fydo27j +$ terraform import tencentcloud_tat_command.example cmd-6fydo27j ``` \ No newline at end of file diff --git a/website/docs/r/tat_command.html.markdown b/website/docs/r/tat_command.html.markdown index f64e378bf7..938bcc20c2 100644 --- a/website/docs/r/tat_command.html.markdown +++ b/website/docs/r/tat_command.html.markdown @@ -4,27 +4,34 @@ layout: "tencentcloud" page_title: "TencentCloud: tencentcloud_tat_command" sidebar_current: "docs-tencentcloud-resource-tat_command" description: |- - Provides a resource to create a tat command + Provides a resource to create a TAT command --- # tencentcloud_tat_command -Provides a resource to create a tat command +Provides a resource to create a TAT command ## Example Usage ```hcl -resource "tencentcloud_tat_command" "command" { +resource "tencentcloud_tat_command" "example" { username = "root" - command_name = "ls" - content = "bHM=" - description = "xxx" + command_name = "tf-example" + content = <&2 + exit 1 +fi +ps aux +EOF + description = "Terraform demo." command_type = "SHELL" working_directory = "/root" timeout = 50 tags { - key = "" - value = "" + key = "createBy" + value = "Terraform" } } ``` @@ -34,9 +41,9 @@ resource "tencentcloud_tat_command" "command" { The following arguments are supported: * `command_name` - (Required, String) Command name. The name can be up to 60 bytes, and contain [a-z], [A-Z], [0-9] and [_-.]. -* `content` - (Required, String) Command. The maximum length of Base64 encoding is 64KB. +* `content` - (Required, String) Base64-encoded command. The maximum length is 64 KB. * `command_type` - (Optional, String) Command type. `SHELL` and `POWERSHELL` are supported. The default value is `SHELL`. -* `default_parameters` - (Optional, String) The default value of the custom parameter value when it is enabled. The field type is JSON encoded string. For example, {&#39;varA&#39;: &#39;222&#39;}.`key` is the name of the custom parameter and value is the default value. Both `key` and `value` are strings.If no parameter value is provided in the `InvokeCommand` API, the default value is used.Up to 20 custom parameters are supported.The name of the custom parameter cannot exceed 64 characters and can contain [a-z], [A-Z], [0-9] and [-_]. +* `default_parameters` - (Optional, String) The default value of the custom parameter value when it is enabled. The field type is JSON encoded string. For example, {"varA": "222"}.`key` is the name of the custom parameter and value is the default value. Both `key` and `value` are strings.If no parameter value is provided in the `InvokeCommand` API, the default value is used.Up to 20 custom parameters are supported.The name of the custom parameter cannot exceed 64 characters and can contain [a-z], [A-Z], [0-9] and [-_]. * `description` - (Optional, String) Command description. The maximum length is 120 characters. * `enable_parameter` - (Optional, Bool) Whether to enable the custom parameter feature.This cannot be modified once created.Default value: `false`. * `output_cos_bucket_url` - (Optional, String) The COS bucket URL for uploading logs. The URL must start with `https`, such as `https://BucketName-123454321.cos.ap-beijing.myqcloud.com`. @@ -66,6 +73,6 @@ In addition to all arguments above, the following attributes are exported: tat command can be imported using the id, e.g. ``` -$ terraform import tencentcloud_tat_command.command cmd-6fydo27j +$ terraform import tencentcloud_tat_command.example cmd-6fydo27j ```