Skip to content

Commit 70c7e80

Browse files
authored
add ssm product (#2027)
* add ssm product * add changelog
1 parent ce033b6 commit 70c7e80

12 files changed

+907
-6
lines changed

.changelog/2027.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:new-data-source
2+
tencentcloud_ssm_products
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_ssm_product_secret
7+
```

tencentcloud/data_source_tc_mysql_instance.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ Use this data source to get information about a MySQL instance.
44
Example Usage
55
66
```hcl
7-
data "tencentcloud_mysql_instance" "database" {
8-
mysql_id = "terraform-test-local-database"
9-
result_output_file = "mytestpath"
7+
data "tencentcloud_mysql_instance" "mysql" {
8+
mysql_id = "cdb-fitq5t9h"
109
}
1110
```
1211
*/
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Use this data source to query detailed information of ssm products
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_ssm_products" "products" {}
8+
```
9+
*/
10+
package tencentcloud
11+
12+
import (
13+
"context"
14+
15+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
16+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
17+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
18+
)
19+
20+
func dataSourceTencentCloudSsmProducts() *schema.Resource {
21+
return &schema.Resource{
22+
Read: dataSourceTencentCloudSsmProductsRead,
23+
Schema: map[string]*schema.Schema{
24+
"products": {
25+
Computed: true,
26+
Type: schema.TypeSet,
27+
Elem: &schema.Schema{
28+
Type: schema.TypeString,
29+
},
30+
Description: "List of supported services.",
31+
},
32+
33+
"result_output_file": {
34+
Type: schema.TypeString,
35+
Optional: true,
36+
Description: "Used to save results.",
37+
},
38+
},
39+
}
40+
}
41+
42+
func dataSourceTencentCloudSsmProductsRead(d *schema.ResourceData, meta interface{}) error {
43+
defer logElapsed("data_source.tencentcloud_ssm_products.read")()
44+
defer inconsistentCheck(d, meta)()
45+
46+
logId := getLogId(contextNil)
47+
48+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
49+
50+
service := SsmService{client: meta.(*TencentCloudClient).apiV3Conn}
51+
52+
var products []*string
53+
54+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
55+
result, e := service.DescribeSsmProductsByFilter(ctx)
56+
if e != nil {
57+
return retryError(e)
58+
}
59+
products = result
60+
return nil
61+
})
62+
if err != nil {
63+
return err
64+
}
65+
66+
if products != nil {
67+
_ = d.Set("products", products)
68+
}
69+
ids := helper.StrListToStr(products)
70+
71+
d.SetId(ids)
72+
output, ok := d.GetOk("result_output_file")
73+
if ok && output.(string) != "" {
74+
if e := writeToFile(output.(string), products); e != nil {
75+
return e
76+
}
77+
}
78+
return nil
79+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudSsmProductsDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccSsmProductsDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_ssm_products.products")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccSsmProductsDataSource = `
26+
27+
data "tencentcloud_ssm_products" "products" {}
28+
`

tencentcloud/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,12 +878,14 @@ SSL Certificates
878878
879879
Secrets Manager(SSM)
880880
Data Source
881+
tencentcloud_ssm_products
881882
tencentcloud_ssm_secrets
882883
tencentcloud_ssm_secret_versions
883884
884885
Resource
885886
tencentcloud_ssm_secret
886887
tencentcloud_ssm_secret_version
888+
tencentcloud_ssm_product_secret
887889
tencentcloud_ssm_ssh_key_pair_secret
888890
889891
TcaplusDB
@@ -2024,6 +2026,7 @@ func Provider() *schema.Provider {
20242026
"tencentcloud_protocol_templates": dataSourceTencentCloudProtocolTemplates(),
20252027
"tencentcloud_protocol_template_groups": dataSourceTencentCloudProtocolTemplateGroups(),
20262028
"tencentcloud_kms_keys": dataSourceTencentCloudKmsKeys(),
2029+
"tencentcloud_ssm_products": dataSourceTencentCloudSsmProducts(),
20272030
"tencentcloud_ssm_secrets": dataSourceTencentCloudSsmSecrets(),
20282031
"tencentcloud_ssm_secret_versions": dataSourceTencentCloudSsmSecretVersions(),
20292032
"tencentcloud_cdh_instances": dataSourceTencentCloudCdhInstances(),
@@ -2680,6 +2683,7 @@ func Provider() *schema.Provider {
26802683
"tencentcloud_kms_external_key": resourceTencentCloudKmsExternalKey(),
26812684
"tencentcloud_ssm_secret": resourceTencentCloudSsmSecret(),
26822685
"tencentcloud_ssm_ssh_key_pair_secret": resourceTencentCloudSsmSshKeyPairSecret(),
2686+
"tencentcloud_ssm_product_secret": resourceTencentCloudSsmProductSecret(),
26832687
"tencentcloud_ssm_secret_version": resourceTencentCloudSsmSecretVersion(),
26842688
"tencentcloud_cdh_instance": resourceTencentCloudCdhInstance(),
26852689
"tencentcloud_dnspod_domain_instance": resourceTencentCloudDnspodDomainInstance(),

0 commit comments

Comments
 (0)