From 676450002037e698df5f632611ea04390d274aca Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 17 Jan 2025 15:03:15 +0800 Subject: [PATCH 1/3] add --- .../services/tat/resource_tc_tat_command.go | 53 +++++++++++-------- .../services/tat/resource_tc_tat_command.md | 27 ++++++---- website/docs/r/tat_command.html.markdown | 29 ++++++---- 3 files changed, 66 insertions(+), 43 deletions(-) diff --git a/tencentcloud/services/tat/resource_tc_tat_command.go b/tencentcloud/services/tat/resource_tc_tat_command.go index efee42a94f..c55bb22d20 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": { @@ -79,14 +79,16 @@ func ResourceTencentCloudTatCommand() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "key": { - Type: schema.TypeString, - Required: true, - Description: "Tag key.", + Type: schema.TypeString, + Required: true, + ValidateFunc: tccommon.ValidateNotEmpty, + Description: "Tag key.", }, "value": { - Type: schema.TypeString, - Required: true, - Description: "Tag value.", + Type: schema.TypeString, + Required: true, + ValidateFunc: tccommon.ValidateNotEmpty, + Description: "Tag value.", }, }, }, @@ -141,9 +143,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 +170,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 +217,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 +231,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 +351,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 +400,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 ``` From 8ced4f90da8a6aa76e7e4b190bb51c534c1566a0 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 17 Jan 2025 15:06:18 +0800 Subject: [PATCH 2/3] add --- .changelog/3083.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/3083.txt 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 +``` From 518d9ed7f1b4d1f678f3da472442b1a913ada45b Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 22 Jan 2025 17:03:50 +0800 Subject: [PATCH 3/3] add --- .../services/tat/resource_tc_tat_command.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tencentcloud/services/tat/resource_tc_tat_command.go b/tencentcloud/services/tat/resource_tc_tat_command.go index c55bb22d20..ee68af431b 100644 --- a/tencentcloud/services/tat/resource_tc_tat_command.go +++ b/tencentcloud/services/tat/resource_tc_tat_command.go @@ -79,16 +79,14 @@ func ResourceTencentCloudTatCommand() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "key": { - Type: schema.TypeString, - Required: true, - ValidateFunc: tccommon.ValidateNotEmpty, - Description: "Tag key.", + Type: schema.TypeString, + Required: true, + Description: "Tag key.", }, "value": { - Type: schema.TypeString, - Required: true, - ValidateFunc: tccommon.ValidateNotEmpty, - Description: "Tag value.", + Type: schema.TypeString, + Required: true, + Description: "Tag value.", }, }, },