-
Notifications
You must be signed in to change notification settings - Fork 136
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
feat: support pts #2139
Merged
Merged
feat: support pts #2139
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
tencentcloud_pts_tmp_key | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
Provides a resource to create a pts tmp_key | ||
|
||
Example Usage | ||
|
||
```hcl | ||
resource "tencentcloud_pts_tmp_key" "tmp_key" { | ||
project_id = "project-1b0zqmhg" | ||
scenario_id = "scenario-abc" | ||
} | ||
``` | ||
*/ | ||
package tencentcloud | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
pts "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts/v20210728" | ||
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" | ||
) | ||
|
||
func resourceTencentCloudPtsTmpKey() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceTencentCloudPtsTmpKeyCreate, | ||
Read: resourceTencentCloudPtsTmpKeyRead, | ||
Delete: resourceTencentCloudPtsTmpKeyDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"project_id": { | ||
Required: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "Project ID.", | ||
}, | ||
|
||
"scenario_id": { | ||
Optional: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "Scenario ID.", | ||
}, | ||
|
||
"start_time": { | ||
Computed: true, | ||
Type: schema.TypeInt, | ||
Description: "The timestamp of the moment when the temporary access credential was obtained (in seconds).", | ||
}, | ||
"expired_time": { | ||
Computed: true, | ||
Type: schema.TypeInt, | ||
Description: "Timestamp of temporary access credential timeout (in seconds).", | ||
}, | ||
"credentials": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "Temporary access credentials.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"tmp_secret_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Temporary secret ID.", | ||
}, | ||
"tmp_secret_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Temporary secret key.", | ||
}, | ||
"token": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Temporary token.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceTencentCloudPtsTmpKeyCreate(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("resource.tencentcloud_pts_tmp_key.create")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
logId := getLogId(contextNil) | ||
|
||
var ( | ||
request = pts.NewGenerateTmpKeyRequest() | ||
response = pts.NewGenerateTmpKeyResponse() | ||
projectId string | ||
) | ||
if v, ok := d.GetOk("project_id"); ok { | ||
projectId = v.(string) | ||
request.ProjectId = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("scenario_id"); ok { | ||
request.ScenarioId = helper.String(v.(string)) | ||
} | ||
|
||
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { | ||
result, e := meta.(*TencentCloudClient).apiV3Conn.UsePtsClient().GenerateTmpKey(request) | ||
if e != nil { | ||
return retryError(e) | ||
} else { | ||
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) | ||
} | ||
response = result | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Printf("[CRITAL]%s operate pts tmpKey failed, reason:%+v", logId, err) | ||
return err | ||
} | ||
|
||
// d.SetId(projectId + FILED_SP + scenarioId) | ||
d.SetId(projectId) | ||
|
||
if response != nil || response.Response != nil { | ||
credentials := response.Response.Credentials | ||
if credentials != nil { | ||
credentialsMap := map[string]interface{}{} | ||
if credentials.TmpSecretId != nil { | ||
credentialsMap["tmp_secret_id"] = credentials.TmpSecretId | ||
} | ||
|
||
if credentials.TmpSecretKey != nil { | ||
credentialsMap["tmp_secret_key"] = credentials.TmpSecretKey | ||
} | ||
|
||
if credentials.Token != nil { | ||
credentialsMap["token"] = credentials.Token | ||
} | ||
|
||
_ = d.Set("credentials", []interface{}{credentialsMap}) | ||
} | ||
|
||
if response.Response.StartTime != nil { | ||
_ = d.Set("start_time", response.Response.StartTime) | ||
} | ||
|
||
if response.Response.ExpiredTime != nil { | ||
_ = d.Set("expired_time", response.Response.ExpiredTime) | ||
} | ||
} | ||
|
||
return resourceTencentCloudPtsTmpKeyRead(d, meta) | ||
} | ||
|
||
func resourceTencentCloudPtsTmpKeyRead(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("resource.tencentcloud_pts_tmp_key.read")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} | ||
|
||
func resourceTencentCloudPtsTmpKeyDelete(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("resource.tencentcloud_pts_tmp_key.delete")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package tencentcloud | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
// go test -test.run TestAccTencentCloudPtsTmpKeyResource_basic -v | ||
func TestAccTencentCloudPtsTmpKeyResource_basic(t *testing.T) { | ||
t.Parallel() | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccPtsTmpKey, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key.tmp_key", "id"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key.tmp_key", "project_id"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key.tmp_key", "scenario_id"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key.tmp_key", "start_time"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key.tmp_key", "expired_time"), | ||
resource.TestCheckResourceAttr("tencentcloud_pts_tmp_key.tmp_key", "credentials.#", "1"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key.tmp_key", "credentials.0.tmp_secret_id"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key.tmp_key", "credentials.0.tmp_secret_key"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_pts_tmp_key.tmp_key", "credentials.0.token"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccPtsTmpKeyVar = ` | ||
variable "project_id" { | ||
default = "` + defaultPtsProjectId + `" | ||
} | ||
variable "scenario_id" { | ||
default = "` + defaultScenarioId + `" | ||
} | ||
|
||
` | ||
|
||
const testAccPtsTmpKey = testAccPtsTmpKeyVar + ` | ||
resource "tencentcloud_pts_tmp_key" "tmp_key" { | ||
project_id = var.project_id | ||
scenario_id = var.scenario_id | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
subcategory: "Performance Testing Service(PTS)" | ||
layout: "tencentcloud" | ||
page_title: "TencentCloud: tencentcloud_pts_tmp_key" | ||
sidebar_current: "docs-tencentcloud-resource-pts_tmp_key" | ||
description: |- | ||
Provides a resource to create a pts tmp_key | ||
--- | ||
|
||
# tencentcloud_pts_tmp_key | ||
|
||
Provides a resource to create a pts tmp_key | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "tencentcloud_pts_tmp_key" "tmp_key" { | ||
project_id = "project-1b0zqmhg" | ||
scenario_id = "scenario-abc" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `project_id` - (Required, String, ForceNew) Project ID. | ||
* `scenario_id` - (Optional, String, ForceNew) Scenario ID. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - ID of the resource. | ||
* `credentials` - Temporary access credentials. | ||
* `tmp_secret_id` - Temporary secret ID. | ||
* `tmp_secret_key` - Temporary secret key. | ||
* `token` - Temporary token. | ||
* `expired_time` - Timestamp of temporary access credential timeout (in seconds). | ||
* `start_time` - The timestamp of the moment when the temporary access credential was obtained (in seconds). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个资源不支持删除吗