Skip to content

Commit d8c42e1

Browse files
authored
feat/ssm (#2172)
* feat/ssm * feat/ssm
1 parent 333cb18 commit d8c42e1

19 files changed

+1129
-0
lines changed

.changelog/2172.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```release-note:new-resource
2+
tencentcloud_ssm_rotate_product_secret
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_ssm_rotation_detail
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_ssm_rotation_history
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_ssm_service_status
15+
```
16+
17+
```release-note:new-data-source
18+
tencentcloud_ssm_ssh_key_pair_value
19+
```
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
Use this data source to query detailed information of ssm rotation_detail
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_ssm_rotation_detail" "example" {
8+
secret_name = "tf_example"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
ssm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm/v20190923"
20+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
21+
)
22+
23+
func dataSourceTencentCloudSsmRotationDetail() *schema.Resource {
24+
return &schema.Resource{
25+
Read: dataSourceTencentCloudSsmRotationDetailRead,
26+
Schema: map[string]*schema.Schema{
27+
"secret_name": {
28+
Required: true,
29+
Type: schema.TypeString,
30+
Description: "Secret name.",
31+
},
32+
"enable_rotation": {
33+
Computed: true,
34+
Type: schema.TypeBool,
35+
Description: "Whether to allow rotation.",
36+
},
37+
"frequency": {
38+
Computed: true,
39+
Type: schema.TypeInt,
40+
Description: "The rotation frequency, in days, defaults to 1 day.",
41+
},
42+
"latest_rotate_time": {
43+
Computed: true,
44+
Type: schema.TypeString,
45+
Description: "Time of last rotation.",
46+
},
47+
"next_rotate_begin_time": {
48+
Computed: true,
49+
Type: schema.TypeString,
50+
Description: "The time to start the next rotation.",
51+
},
52+
"result_output_file": {
53+
Type: schema.TypeString,
54+
Optional: true,
55+
Description: "Used to save results.",
56+
},
57+
},
58+
}
59+
}
60+
61+
func dataSourceTencentCloudSsmRotationDetailRead(d *schema.ResourceData, meta interface{}) error {
62+
defer logElapsed("data_source.tencentcloud_ssm_rotation_detail.read")()
63+
defer inconsistentCheck(d, meta)()
64+
65+
var (
66+
logId = getLogId(contextNil)
67+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
68+
service = SsmService{client: meta.(*TencentCloudClient).apiV3Conn}
69+
rotationDetail *ssm.DescribeRotationDetailResponseParams
70+
secretName string
71+
)
72+
73+
paramMap := make(map[string]interface{})
74+
if v, ok := d.GetOk("secret_name"); ok {
75+
paramMap["SecretName"] = helper.String(v.(string))
76+
secretName = v.(string)
77+
}
78+
79+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
80+
result, e := service.DescribeSsmRotationDetailByFilter(ctx, paramMap)
81+
if e != nil {
82+
return retryError(e)
83+
}
84+
85+
rotationDetail = result
86+
return nil
87+
})
88+
89+
if err != nil {
90+
return err
91+
}
92+
93+
if rotationDetail.EnableRotation != nil {
94+
_ = d.Set("enable_rotation", rotationDetail.EnableRotation)
95+
}
96+
97+
if rotationDetail.Frequency != nil {
98+
_ = d.Set("frequency", rotationDetail.Frequency)
99+
}
100+
101+
if rotationDetail.LatestRotateTime != nil {
102+
_ = d.Set("latest_rotate_time", rotationDetail.LatestRotateTime)
103+
}
104+
105+
if rotationDetail.NextRotateBeginTime != nil {
106+
_ = d.Set("next_rotate_begin_time", rotationDetail.NextRotateBeginTime)
107+
}
108+
109+
d.SetId(secretName)
110+
output, ok := d.GetOk("result_output_file")
111+
if ok && output.(string) != "" {
112+
if e := writeToFile(output.(string), d); e != nil {
113+
return e
114+
}
115+
}
116+
117+
return nil
118+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudNeedFixSsmRotationDetailDataSource_basic -v
10+
func TestAccTencentCloudNeedFixSsmRotationDetailDataSource_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: testAccSsmRotationDetailDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_ssm_rotation_detail.example"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccSsmRotationDetailDataSource = `
29+
data "tencentcloud_ssm_rotation_detail" "example" {
30+
secret_name = "tf_example"
31+
}
32+
`
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Use this data source to query detailed information of ssm rotation_history
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_ssm_rotation_history" "example" {
8+
secret_name = "keep_terraform"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
20+
)
21+
22+
func dataSourceTencentCloudSsmRotationHistory() *schema.Resource {
23+
return &schema.Resource{
24+
Read: dataSourceTencentCloudSsmRotationHistoryRead,
25+
Schema: map[string]*schema.Schema{
26+
"secret_name": {
27+
Required: true,
28+
Type: schema.TypeString,
29+
Description: "Secret name.",
30+
},
31+
"version_ids": {
32+
Computed: true,
33+
Type: schema.TypeSet,
34+
Elem: &schema.Schema{Type: schema.TypeString},
35+
Description: "The number of version numbers. The maximum number of version numbers that can be displayed to users is 10.",
36+
},
37+
"result_output_file": {
38+
Type: schema.TypeString,
39+
Optional: true,
40+
Description: "Used to save results.",
41+
},
42+
},
43+
}
44+
}
45+
46+
func dataSourceTencentCloudSsmRotationHistoryRead(d *schema.ResourceData, meta interface{}) error {
47+
defer logElapsed("data_source.tencentcloud_ssm_rotation_history.read")()
48+
defer inconsistentCheck(d, meta)()
49+
50+
var (
51+
logId = getLogId(contextNil)
52+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
53+
service = SsmService{client: meta.(*TencentCloudClient).apiV3Conn}
54+
versionIDs []*string
55+
secretName string
56+
)
57+
58+
paramMap := make(map[string]interface{})
59+
if v, ok := d.GetOk("secret_name"); ok {
60+
paramMap["SecretName"] = helper.String(v.(string))
61+
secretName = v.(string)
62+
}
63+
64+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
65+
result, e := service.DescribeSsmRotationHistoryByFilter(ctx, paramMap)
66+
if e != nil {
67+
return retryError(e)
68+
}
69+
70+
versionIDs = result
71+
return nil
72+
})
73+
74+
if err != nil {
75+
return err
76+
}
77+
78+
if versionIDs != nil {
79+
_ = d.Set("version_ids", versionIDs)
80+
}
81+
82+
d.SetId(secretName)
83+
output, ok := d.GetOk("result_output_file")
84+
if ok && output.(string) != "" {
85+
if e := writeToFile(output.(string), d); e != nil {
86+
return e
87+
}
88+
}
89+
90+
return nil
91+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudNeedFixSsmRotationHistoryDataSource_basic -v
10+
func TestAccTencentCloudNeedFixSsmRotationHistoryDataSource_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: testAccSsmRotationHistoryDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_ssm_rotation_history.example"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccSsmRotationHistoryDataSource = `
29+
data "tencentcloud_ssm_rotation_history" "example" {
30+
secret_name = "keep_terraform"
31+
}
32+
`
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Use this data source to query detailed information of ssm service_status
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_ssm_service_status" "example" {}
8+
```
9+
*/
10+
package tencentcloud
11+
12+
import (
13+
"context"
14+
"strconv"
15+
"time"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
ssm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm/v20190923"
20+
)
21+
22+
func dataSourceTencentCloudSsmServiceStatus() *schema.Resource {
23+
return &schema.Resource{
24+
Read: dataSourceTencentCloudSsmServiceStatusRead,
25+
Schema: map[string]*schema.Schema{
26+
"service_enabled": {
27+
Computed: true,
28+
Type: schema.TypeBool,
29+
Description: "True means the service has been activated, false means the service has not been activated yet.",
30+
},
31+
"invalid_type": {
32+
Computed: true,
33+
Type: schema.TypeInt,
34+
Description: "Service unavailability type: 0-Not purchased, 1-Normal, 2-Service suspended due to arrears, 3-Resource release.",
35+
},
36+
"access_key_escrow_enabled": {
37+
Computed: true,
38+
Type: schema.TypeBool,
39+
Description: "True means that the user can already use the key safe hosting function, false means that the user cannot use the key safe hosting function temporarily.",
40+
},
41+
"result_output_file": {
42+
Type: schema.TypeString,
43+
Optional: true,
44+
Description: "Used to save results.",
45+
},
46+
},
47+
}
48+
}
49+
50+
func dataSourceTencentCloudSsmServiceStatusRead(d *schema.ResourceData, meta interface{}) error {
51+
defer logElapsed("data_source.tencentcloud_ssm_service_status.read")()
52+
defer inconsistentCheck(d, meta)()
53+
54+
var (
55+
logId = getLogId(contextNil)
56+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
57+
service = SsmService{client: meta.(*TencentCloudClient).apiV3Conn}
58+
serviceStatus *ssm.GetServiceStatusResponseParams
59+
)
60+
61+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
62+
result, e := service.DescribeSsmServiceStatusByFilter(ctx)
63+
if e != nil {
64+
return retryError(e)
65+
}
66+
67+
serviceStatus = result
68+
return nil
69+
})
70+
71+
if err != nil {
72+
return err
73+
}
74+
75+
if serviceStatus.ServiceEnabled != nil {
76+
_ = d.Set("service_enabled", serviceStatus.ServiceEnabled)
77+
}
78+
79+
if serviceStatus.InvalidType != nil {
80+
_ = d.Set("invalid_type", serviceStatus.InvalidType)
81+
}
82+
83+
if serviceStatus.AccessKeyEscrowEnabled != nil {
84+
_ = d.Set("access_key_escrow_enabled", serviceStatus.AccessKeyEscrowEnabled)
85+
}
86+
87+
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
88+
output, ok := d.GetOk("result_output_file")
89+
if ok && output.(string) != "" {
90+
if e := writeToFile(output.(string), d); e != nil {
91+
return e
92+
}
93+
}
94+
95+
return nil
96+
}

0 commit comments

Comments
 (0)