Skip to content

Commit 15c718b

Browse files
committed
feat/ssm
1 parent 9419096 commit 15c718b

9 files changed

+337
-192
lines changed

tencentcloud/data_source_tc_ssm_products.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ func dataSourceTencentCloudSsmProducts() *schema.Resource {
2222
Read: dataSourceTencentCloudSsmProductsRead,
2323
Schema: map[string]*schema.Schema{
2424
"products": {
25-
Computed: true,
26-
Type: schema.TypeSet,
27-
Elem: &schema.Schema{
28-
Type: schema.TypeString,
29-
},
25+
Computed: true,
26+
Type: schema.TypeSet,
27+
Elem: &schema.Schema{Type: schema.TypeString},
3028
Description: "List of supported services.",
3129
},
32-
3330
"result_output_file": {
3431
Type: schema.TypeString,
3532
Optional: true,
@@ -43,37 +40,38 @@ func dataSourceTencentCloudSsmProductsRead(d *schema.ResourceData, meta interfac
4340
defer logElapsed("data_source.tencentcloud_ssm_products.read")()
4441
defer inconsistentCheck(d, meta)()
4542

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
43+
var (
44+
logId = getLogId(contextNil)
45+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
46+
service = SsmService{client: meta.(*TencentCloudClient).apiV3Conn}
47+
products []*string
48+
)
5349

5450
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
5551
result, e := service.DescribeSsmProductsByFilter(ctx)
5652
if e != nil {
5753
return retryError(e)
5854
}
55+
5956
products = result
6057
return nil
6158
})
59+
6260
if err != nil {
6361
return err
6462
}
6563

6664
if products != nil {
6765
_ = d.Set("products", products)
6866
}
69-
ids := helper.StrListToStr(products)
7067

71-
d.SetId(ids)
68+
d.SetId(helper.StrListToStr(products))
7269
output, ok := d.GetOk("result_output_file")
7370
if ok && output.(string) != "" {
7471
if e := writeToFile(output.(string), products); e != nil {
7572
return e
7673
}
7774
}
75+
7876
return nil
7977
}

tencentcloud/data_source_tc_ssm_products_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
77
)
88

9+
// go test -i; go test -test.run TestAccTencentCloudSsmProductsDataSource_basic -v
910
func TestAccTencentCloudSsmProductsDataSource_basic(t *testing.T) {
1011
t.Parallel()
1112
resource.Test(t, resource.TestCase{
@@ -16,13 +17,14 @@ func TestAccTencentCloudSsmProductsDataSource_basic(t *testing.T) {
1617
Steps: []resource.TestStep{
1718
{
1819
Config: testAccSsmProductsDataSource,
19-
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_ssm_products.products")),
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_ssm_products.products"),
22+
),
2023
},
2124
},
2225
})
2326
}
2427

2528
const testAccSsmProductsDataSource = `
26-
2729
data "tencentcloud_ssm_products" "products" {}
2830
`

0 commit comments

Comments
 (0)