Skip to content

Commit 69c3b17

Browse files
authored
fix(tat): [121710659] tencentcloud_tat_command update code and doc (#3083)
* add * add * add
1 parent 39ebdf8 commit 69c3b17

File tree

4 files changed

+61
-37
lines changed

4 files changed

+61
-37
lines changed

.changelog/3083.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_tat_command: update code and doc
3+
```

tencentcloud/services/tat/resource_tc_tat_command.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616

1717
func ResourceTencentCloudTatCommand() *schema.Resource {
1818
return &schema.Resource{
19-
Read: resourceTencentCloudTatCommandRead,
2019
Create: resourceTencentCloudTatCommandCreate,
20+
Read: resourceTencentCloudTatCommandRead,
2121
Update: resourceTencentCloudTatCommandUpdate,
2222
Delete: resourceTencentCloudTatCommandDelete,
2323
Importer: &schema.ResourceImporter{
@@ -33,7 +33,7 @@ func ResourceTencentCloudTatCommand() *schema.Resource {
3333
"content": {
3434
Type: schema.TypeString,
3535
Required: true,
36-
Description: "Command. The maximum length of Base64 encoding is 64KB.",
36+
Description: "Base64-encoded command. The maximum length is 64 KB.",
3737
},
3838

3939
"description": {
@@ -69,7 +69,7 @@ func ResourceTencentCloudTatCommand() *schema.Resource {
6969
"default_parameters": {
7070
Type: schema.TypeString,
7171
Optional: true,
72-
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 [-_].",
72+
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 [-_].",
7373
},
7474

7575
"tags": {
@@ -141,9 +141,8 @@ func resourceTencentCloudTatCommandCreate(d *schema.ResourceData, meta interface
141141
defer tccommon.LogElapsed("resource.tencentcloud_tat_command.create")()
142142
defer tccommon.InconsistentCheck(d, meta)()
143143

144-
logId := tccommon.GetLogId(tccommon.ContextNil)
145-
146144
var (
145+
logId = tccommon.GetLogId(tccommon.ContextNil)
147146
request = tat.NewCreateCommandRequest()
148147
response *tat.CreateCommandResponse
149148
commandId string
@@ -169,11 +168,11 @@ func resourceTencentCloudTatCommandCreate(d *schema.ResourceData, meta interface
169168
request.WorkingDirectory = helper.String(v.(string))
170169
}
171170

172-
if v, ok := d.GetOk("timeout"); ok {
171+
if v, ok := d.GetOkExists("timeout"); ok {
173172
request.Timeout = helper.IntUint64(v.(int))
174173
}
175174

176-
if v, _ := d.GetOk("enable_parameter"); v != nil {
175+
if v, ok := d.GetOkExists("enable_parameter"); ok {
177176
request.EnableParameter = helper.Bool(v.(bool))
178177
}
179178

@@ -216,6 +215,11 @@ func resourceTencentCloudTatCommandCreate(d *schema.ResourceData, meta interface
216215
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
217216
logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
218217
}
218+
219+
if result == nil || result.Response == nil {
220+
return resource.NonRetryableError(fmt.Errorf("Create tat command failed, Response is nil."))
221+
}
222+
219223
response = result
220224
return nil
221225
})
@@ -225,6 +229,10 @@ func resourceTencentCloudTatCommandCreate(d *schema.ResourceData, meta interface
225229
return err
226230
}
227231

232+
if response.Response.CommandId == nil {
233+
return fmt.Errorf("CommandId is nil.")
234+
}
235+
228236
commandId = *response.Response.CommandId
229237

230238
d.SetId(commandId)
@@ -341,9 +349,16 @@ func resourceTencentCloudTatCommandUpdate(d *schema.ResourceData, meta interface
341349
defer tccommon.InconsistentCheck(d, meta)()
342350

343351
logId := tccommon.GetLogId(tccommon.ContextNil)
344-
345352
request := tat.NewModifyCommandRequest()
346353

354+
if d.HasChange("enable_parameter") {
355+
return fmt.Errorf("`enable_parameter` do not support change now.")
356+
}
357+
358+
if d.HasChange("tags") {
359+
return fmt.Errorf("`tags` do not support change now.")
360+
}
361+
347362
commandId := d.Id()
348363
request.CommandId = &commandId
349364

@@ -383,20 +398,12 @@ func resourceTencentCloudTatCommandUpdate(d *schema.ResourceData, meta interface
383398
}
384399
}
385400

386-
if d.HasChange("enable_parameter") {
387-
return fmt.Errorf("`enable_parameter` do not support change now.")
388-
}
389-
390401
if d.HasChange("default_parameters") {
391402
if v, ok := d.GetOk("default_parameters"); ok {
392403
request.DefaultParameters = helper.String(v.(string))
393404
}
394405
}
395406

396-
if d.HasChange("tags") {
397-
return fmt.Errorf("`tags` do not support change now.")
398-
}
399-
400407
if d.HasChange("username") {
401408
if v, ok := d.GetOk("username"); ok {
402409
request.Username = helper.String(v.(string))
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
Provides a resource to create a tat command
1+
Provides a resource to create a TAT command
22

33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_tat_command" "command" {
6+
resource "tencentcloud_tat_command" "example" {
77
username = "root"
8-
command_name = "ls"
9-
content = "bHM="
10-
description = "xxx"
8+
command_name = "tf-example"
9+
content = <<EOF
10+
#!/bin/bash
11+
if [ "$(id -u)" != "0" ]; then
12+
echo "Please run this script as the root user." >&2
13+
exit 1
14+
fi
15+
ps aux
16+
EOF
17+
description = "Terraform demo."
1118
command_type = "SHELL"
1219
working_directory = "/root"
13-
timeout = 50
20+
timeout = 50
1421
tags {
15-
key = ""
16-
value = ""
22+
key = "createBy"
23+
value = "Terraform"
1724
}
1825
}
19-
2026
```
27+
2128
Import
2229

2330
tat command can be imported using the id, e.g.
2431
```
25-
$ terraform import tencentcloud_tat_command.command cmd-6fydo27j
32+
$ terraform import tencentcloud_tat_command.example cmd-6fydo27j
2633
```

website/docs/r/tat_command.html.markdown

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,34 @@ layout: "tencentcloud"
44
page_title: "TencentCloud: tencentcloud_tat_command"
55
sidebar_current: "docs-tencentcloud-resource-tat_command"
66
description: |-
7-
Provides a resource to create a tat command
7+
Provides a resource to create a TAT command
88
---
99

1010
# tencentcloud_tat_command
1111

12-
Provides a resource to create a tat command
12+
Provides a resource to create a TAT command
1313

1414
## Example Usage
1515

1616
```hcl
17-
resource "tencentcloud_tat_command" "command" {
17+
resource "tencentcloud_tat_command" "example" {
1818
username = "root"
19-
command_name = "ls"
20-
content = "bHM="
21-
description = "xxx"
19+
command_name = "tf-example"
20+
content = <<EOF
21+
#!/bin/bash
22+
if [ "$(id -u)" != "0" ]; then
23+
echo "Please run this script as the root user." >&2
24+
exit 1
25+
fi
26+
ps aux
27+
EOF
28+
description = "Terraform demo."
2229
command_type = "SHELL"
2330
working_directory = "/root"
2431
timeout = 50
2532
tags {
26-
key = ""
27-
value = ""
33+
key = "createBy"
34+
value = "Terraform"
2835
}
2936
}
3037
```
@@ -34,9 +41,9 @@ resource "tencentcloud_tat_command" "command" {
3441
The following arguments are supported:
3542

3643
* `command_name` - (Required, String) Command name. The name can be up to 60 bytes, and contain [a-z], [A-Z], [0-9] and [_-.].
37-
* `content` - (Required, String) Command. The maximum length of Base64 encoding is 64KB.
44+
* `content` - (Required, String) Base64-encoded command. The maximum length is 64 KB.
3845
* `command_type` - (Optional, String) Command type. `SHELL` and `POWERSHELL` are supported. The default value is `SHELL`.
39-
* `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 [-_].
46+
* `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 [-_].
4047
* `description` - (Optional, String) Command description. The maximum length is 120 characters.
4148
* `enable_parameter` - (Optional, Bool) Whether to enable the custom parameter feature.This cannot be modified once created.Default value: `false`.
4249
* `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:
6673

6774
tat command can be imported using the id, e.g.
6875
```
69-
$ terraform import tencentcloud_tat_command.command cmd-6fydo27j
76+
$ terraform import tencentcloud_tat_command.example cmd-6fydo27j
7077
```
7178

0 commit comments

Comments
 (0)