Skip to content

Commit 04b6fe6

Browse files
authored
feat: support pts (#2139)
* feat: support pts * feat: add changelog * fix: rename
1 parent c475655 commit 04b6fe6

File tree

6 files changed

+264
-0
lines changed

6 files changed

+264
-0
lines changed

.changelog/2139.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
tencentcloud_pts_tmp_key_generate
3+
```

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,7 @@ Performance Testing Service(PTS)
13421342
tencentcloud_pts_file
13431343
tencentcloud_pts_job
13441344
tencentcloud_pts_cron_job
1345+
tencentcloud_pts_tmp_key_generate
13451346
13461347
TencentCloud Automation Tools(TAT)
13471348
Data Source
@@ -2911,6 +2912,7 @@ func Provider() *schema.Provider {
29112912
"tencentcloud_pts_file": resourceTencentCloudPtsFile(),
29122913
"tencentcloud_pts_job": resourceTencentCloudPtsJob(),
29132914
"tencentcloud_pts_cron_job": resourceTencentCloudPtsCronJob(),
2915+
"tencentcloud_pts_tmp_key_generate": resourceTencentCloudPtsTmpKeyGenerate(),
29142916
"tencentcloud_tat_command": resourceTencentCloudTatCommand(),
29152917
"tencentcloud_tat_invoker": resourceTencentCloudTatInvoker(),
29162918
"tencentcloud_tat_invoker_config": resourceTencentCloudTatInvokerConfig(),
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
Provides a resource to create a pts tmp_key
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_pts_tmp_key_generate" "tmp_key" {
8+
project_id = "project-1b0zqmhg"
9+
scenario_id = "scenario-abc"
10+
}
11+
```
12+
*/
13+
package tencentcloud
14+
15+
import (
16+
"log"
17+
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
20+
pts "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts/v20210728"
21+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
22+
)
23+
24+
func resourceTencentCloudPtsTmpKeyGenerate() *schema.Resource {
25+
return &schema.Resource{
26+
Create: resourceTencentCloudPtsTmpKeyGenerateCreate,
27+
Read: resourceTencentCloudPtsTmpKeyGenerateRead,
28+
Delete: resourceTencentCloudPtsTmpKeyGenerateDelete,
29+
30+
Schema: map[string]*schema.Schema{
31+
"project_id": {
32+
Required: true,
33+
ForceNew: true,
34+
Type: schema.TypeString,
35+
Description: "Project ID.",
36+
},
37+
38+
"scenario_id": {
39+
Optional: true,
40+
ForceNew: true,
41+
Type: schema.TypeString,
42+
Description: "Scenario ID.",
43+
},
44+
45+
"start_time": {
46+
Computed: true,
47+
Type: schema.TypeInt,
48+
Description: "The timestamp of the moment when the temporary access credential was obtained (in seconds).",
49+
},
50+
"expired_time": {
51+
Computed: true,
52+
Type: schema.TypeInt,
53+
Description: "Timestamp of temporary access credential timeout (in seconds).",
54+
},
55+
"credentials": {
56+
Type: schema.TypeList,
57+
Computed: true,
58+
Description: "Temporary access credentials.",
59+
Elem: &schema.Resource{
60+
Schema: map[string]*schema.Schema{
61+
"tmp_secret_id": {
62+
Type: schema.TypeString,
63+
Computed: true,
64+
Description: "Temporary secret ID.",
65+
},
66+
"tmp_secret_key": {
67+
Type: schema.TypeString,
68+
Computed: true,
69+
Description: "Temporary secret key.",
70+
},
71+
"token": {
72+
Type: schema.TypeString,
73+
Computed: true,
74+
Description: "Temporary token.",
75+
},
76+
},
77+
},
78+
},
79+
},
80+
}
81+
}
82+
83+
func resourceTencentCloudPtsTmpKeyGenerateCreate(d *schema.ResourceData, meta interface{}) error {
84+
defer logElapsed("resource.tencentcloud_pts_tmp_key_generate.create")()
85+
defer inconsistentCheck(d, meta)()
86+
87+
logId := getLogId(contextNil)
88+
89+
var (
90+
request = pts.NewGenerateTmpKeyRequest()
91+
response = pts.NewGenerateTmpKeyResponse()
92+
projectId string
93+
)
94+
if v, ok := d.GetOk("project_id"); ok {
95+
projectId = v.(string)
96+
request.ProjectId = helper.String(v.(string))
97+
}
98+
99+
if v, ok := d.GetOk("scenario_id"); ok {
100+
request.ScenarioId = helper.String(v.(string))
101+
}
102+
103+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
104+
result, e := meta.(*TencentCloudClient).apiV3Conn.UsePtsClient().GenerateTmpKey(request)
105+
if e != nil {
106+
return retryError(e)
107+
} else {
108+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
109+
}
110+
response = result
111+
return nil
112+
})
113+
if err != nil {
114+
log.Printf("[CRITAL]%s operate pts tmpKey failed, reason:%+v", logId, err)
115+
return err
116+
}
117+
118+
d.SetId(projectId)
119+
120+
if response != nil || response.Response != nil {
121+
credentials := response.Response.Credentials
122+
if credentials != nil {
123+
credentialsMap := map[string]interface{}{}
124+
if credentials.TmpSecretId != nil {
125+
credentialsMap["tmp_secret_id"] = credentials.TmpSecretId
126+
}
127+
128+
if credentials.TmpSecretKey != nil {
129+
credentialsMap["tmp_secret_key"] = credentials.TmpSecretKey
130+
}
131+
132+
if credentials.Token != nil {
133+
credentialsMap["token"] = credentials.Token
134+
}
135+
136+
_ = d.Set("credentials", []interface{}{credentialsMap})
137+
}
138+
139+
if response.Response.StartTime != nil {
140+
_ = d.Set("start_time", response.Response.StartTime)
141+
}
142+
143+
if response.Response.ExpiredTime != nil {
144+
_ = d.Set("expired_time", response.Response.ExpiredTime)
145+
}
146+
}
147+
148+
return resourceTencentCloudPtsTmpKeyGenerateRead(d, meta)
149+
}
150+
151+
func resourceTencentCloudPtsTmpKeyGenerateRead(d *schema.ResourceData, meta interface{}) error {
152+
defer logElapsed("resource.tencentcloud_pts_tmp_key_generate.read")()
153+
defer inconsistentCheck(d, meta)()
154+
155+
return nil
156+
}
157+
158+
func resourceTencentCloudPtsTmpKeyGenerateDelete(d *schema.ResourceData, meta interface{}) error {
159+
defer logElapsed("resource.tencentcloud_pts_tmp_key_generate.delete")()
160+
defer inconsistentCheck(d, meta)()
161+
162+
return nil
163+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -test.run TestAccTencentCloudPtsTmpKeyResource_basic -v
10+
func TestAccTencentCloudPtsTmpKeyResource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccPtsTmpKey,
20+
Check: resource.ComposeTestCheckFunc(
21+
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key_generate.tmp_key", "id"),
22+
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key_generate.tmp_key", "project_id"),
23+
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key_generate.tmp_key", "scenario_id"),
24+
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key_generate.tmp_key", "start_time"),
25+
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key_generate.tmp_key", "expired_time"),
26+
resource.TestCheckResourceAttr("tencentcloud_pts_tmp_key_generate.tmp_key", "credentials.#", "1"),
27+
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key_generate.tmp_key", "credentials.0.tmp_secret_id"),
28+
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key_generate.tmp_key", "credentials.0.tmp_secret_key"),
29+
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key_generate.tmp_key", "credentials.0.token"),
30+
),
31+
},
32+
},
33+
})
34+
}
35+
36+
const testAccPtsTmpKeyVar = `
37+
variable "project_id" {
38+
default = "` + defaultPtsProjectId + `"
39+
}
40+
variable "scenario_id" {
41+
default = "` + defaultScenarioId + `"
42+
}
43+
44+
`
45+
46+
const testAccPtsTmpKey = testAccPtsTmpKeyVar + `
47+
resource "tencentcloud_pts_tmp_key_generate" "tmp_key" {
48+
project_id = var.project_id
49+
scenario_id = var.scenario_id
50+
}
51+
`
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
subcategory: "Performance Testing Service(PTS)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_pts_tmp_key_generate"
5+
sidebar_current: "docs-tencentcloud-resource-pts_tmp_key_generate"
6+
description: |-
7+
Provides a resource to create a pts tmp_key
8+
---
9+
10+
# tencentcloud_pts_tmp_key_generate
11+
12+
Provides a resource to create a pts tmp_key
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_pts_tmp_key_generate" "tmp_key" {
18+
project_id = "project-1b0zqmhg"
19+
scenario_id = "scenario-abc"
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `project_id` - (Required, String, ForceNew) Project ID.
28+
* `scenario_id` - (Optional, String, ForceNew) Scenario ID.
29+
30+
## Attributes Reference
31+
32+
In addition to all arguments above, the following attributes are exported:
33+
34+
* `id` - ID of the resource.
35+
* `credentials` - Temporary access credentials.
36+
* `tmp_secret_id` - Temporary secret ID.
37+
* `tmp_secret_key` - Temporary secret key.
38+
* `token` - Temporary token.
39+
* `expired_time` - Timestamp of temporary access credential timeout (in seconds).
40+
* `start_time` - The timestamp of the moment when the temporary access credential was obtained (in seconds).
41+
42+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,9 @@
20702070
<li>
20712071
<a href="/docs/providers/tencentcloud/r/pts_scenario.html">tencentcloud_pts_scenario</a>
20722072
</li>
2073+
<li>
2074+
<a href="/docs/providers/tencentcloud/r/pts_tmp_key_generate.html">tencentcloud_pts_tmp_key_generate</a>
2075+
</li>
20732076
</ul>
20742077
</li>
20752078
</ul>

0 commit comments

Comments
 (0)