Skip to content

fix(tat): [121710659] tencentcloud_tat_command update code and doc #3083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3083.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_tat_command: update code and doc
```
39 changes: 23 additions & 16 deletions tencentcloud/services/tat/resource_tc_tat_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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": {
Expand Down Expand Up @@ -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, {'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: "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": {
Expand Down Expand Up @@ -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
Expand All @@ -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))
}

Expand Down Expand Up @@ -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
})
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
27 changes: 17 additions & 10 deletions tencentcloud/services/tat/resource_tc_tat_command.md
Original file line number Diff line number Diff line change
@@ -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 = <<EOF
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "Please run this script as the root user." >&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
```
29 changes: 18 additions & 11 deletions website/docs/r/tat_command.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<EOF
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "Please run this script as the root user." >&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"
}
}
```
Expand All @@ -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, {&amp;#39;varA&amp;#39;: &amp;#39;222&amp;#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`.
Expand Down Expand Up @@ -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
```

Loading