Skip to content

Commit a2d1e18

Browse files
authored
add tag with resource datasource NAT POSTGRE and add cos_bucket_url with COS
1 parent 8156b55 commit a2d1e18

19 files changed

+189
-3
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
## 1.46.1 (Unreleased)
2+
3+
ENHANCEMENTS:
4+
5+
* Resource: `tencentcloud_cos_bucket` add new argument `cos_bucket_url`.
6+
* Resource: `tencentcloud_nat_gateway` add new argument `tags`.
7+
* Resource: `tencentcloud_postgresql_instance` add new argument `tags`.
8+
* Data Source: `tencentcloud_cos_buckets` add new argument `cos_bucket_url`.
9+
* Data Source: `tencentcloud_nat_gateways` add new argument `tags`.
10+
* Data Source: `tencentcloud_postgresql_instances` add new argument `tags`.
11+
212
## 1.46.0 (October 26, 2020)
313

414
FEATURES:

tencentcloud/data_source_tc_cos_buckets.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ func dataSourceTencentCloudCosBuckets() *schema.Resource {
173173
Computed: true,
174174
Description: "The tags of a bucket.",
175175
},
176+
"cos_bucket_url": {
177+
Type: schema.TypeString,
178+
Computed: true,
179+
Description: "The URL of this cos bucket.",
180+
},
176181
},
177182
},
178183
},
@@ -234,7 +239,7 @@ LOOP:
234239
}
235240

236241
bucket["tags"] = respTags
237-
242+
bucket["cos_bucket_url"] = fmt.Sprintf("%s.cos.%s.myqcloud.com", *v.Name, meta.(*TencentCloudClient).apiV3Conn.Region)
238243
bucketList = append(bucketList, bucket)
239244
}
240245

tencentcloud/data_source_tc_cos_buckets_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestAccTencentCloudCosBucketDataSource_basic(t *testing.T) {
2424
resource.TestCheckResourceAttr("data.tencentcloud_cos_buckets.bucket_list", "bucket_list.0.cors_rules.#", "0"),
2525
resource.TestCheckResourceAttr("data.tencentcloud_cos_buckets.bucket_list", "bucket_list.0.lifecycle_rules.#", "0"),
2626
resource.TestCheckResourceAttr("data.tencentcloud_cos_buckets.bucket_list", "bucket_list.0.website.#", "0"),
27+
resource.TestCheckResourceAttrSet("data.tencentcloud_cos_buckets.bucket_list", "bucket_list.0.cos_bucket_url"),
2728
),
2829
},
2930
},

tencentcloud/data_source_tc_nat_gateways.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ func dataSourceTencentCloudNatGateways() *schema.Resource {
9696
Computed: true,
9797
Description: "Create time of the NAT gateway.",
9898
},
99+
"tags": {
100+
Type: schema.TypeMap,
101+
Computed: true,
102+
Description: "The available tags within this NAT gateway.",
103+
},
99104
},
100105
},
101106
},
@@ -170,6 +175,13 @@ func dataSourceTencentCloudNatGatewaysRead(d *schema.ResourceData, meta interfac
170175
"assigned_eip_set": flattenAddressList((*nat).PublicIpAddressSet),
171176
"create_time": *nat.CreatedTime,
172177
}
178+
if nat.TagSet != nil {
179+
tags := make(map[string]interface{}, len(nat.TagSet))
180+
for _, t := range nat.TagSet {
181+
tags[*t.Key] = *t.Value
182+
}
183+
mapping["tags"] = tags
184+
}
173185
natList = append(natList, mapping)
174186
ids = append(ids, *nat.NatGatewayId)
175187
}

tencentcloud/data_source_tc_nat_gateways_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestAccTencentCloudNatGatewaysDataSource(t *testing.T) {
1818
resource.TestCheckResourceAttr("data.tencentcloud_nat_gateways.multi_nat", "nats.#", "2"),
1919
resource.TestCheckResourceAttr("data.tencentcloud_nat_gateways.multi_nat", "nats.0.name", "terraform_test_nats"),
2020
resource.TestCheckResourceAttr("data.tencentcloud_nat_gateways.multi_nat", "nats.1.bandwidth", "500"),
21+
resource.TestCheckResourceAttr("data.tencentcloud_nat_gateways.multi_nat", "nats.0.tags.tf", "test"),
2122
),
2223
},
2324
},
@@ -44,6 +45,10 @@ resource "tencentcloud_nat_gateway" "dev_nat" {
4445
assigned_eip_set = [
4546
tencentcloud_eip.eip_dev_dnat.public_ip,
4647
]
48+
49+
tags = {
50+
tf = "test"
51+
}
4752
}
4853
resource "tencentcloud_nat_gateway" "test_nat" {
4954
vpc_id = tencentcloud_vpc.main.id

tencentcloud/data_source_tc_postgresql_instances.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ func dataSourceTencentCloudPostgresqlInstances() *schema.Resource {
148148
Computed: true,
149149
Description: "Create time of the postgresql instance.",
150150
},
151+
"tags": {
152+
Type: schema.TypeMap,
153+
Computed: true,
154+
Description: "The available tags within this postgresql.",
155+
},
151156
},
152157
},
153158
},
@@ -185,6 +190,8 @@ func dataSourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta i
185190

186191
ids := make([]string, 0, len(instanceList))
187192
list := make([]map[string]interface{}, 0, len(instanceList))
193+
tcClient := meta.(*TencentCloudClient).apiV3Conn
194+
tagService := &TagService{client: tcClient}
188195

189196
for _, v := range instanceList {
190197
listItem := make(map[string]interface{})
@@ -222,6 +229,15 @@ func dataSourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta i
222229
} else {
223230
listItem["charge_type"] = COMMON_PAYTYPE_POSTPAID
224231
}
232+
233+
//the describe list API is delayed with argument `tag`
234+
tagList, err := tagService.DescribeResourceTags(ctx, "postgres", "DBInstanceId", tcClient.Region, *v.DBInstanceId)
235+
if err != nil {
236+
return err
237+
}
238+
239+
listItem["tags"] = tagList
240+
225241
list = append(list, listItem)
226242
ids = append(ids, *v.DBInstanceId)
227243
}

tencentcloud/data_source_tc_postgresql_instances_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func TestAccTencentCloudDataPostgresqlInstances(t *testing.T) {
2121
resource.TestCheckResourceAttr(testDataPostgresqlInstancesName, "instance_list.#", "1"),
2222
resource.TestCheckResourceAttrSet(testDataPostgresqlInstancesName, "instance_list.0.id"),
2323
resource.TestCheckResourceAttrSet(testDataPostgresqlInstancesName, "instance_list.0.create_time"),
24-
resource.TestCheckResourceAttrSet(testDataPostgresqlInstancesName, "instance_list.0.id"),
2524
resource.TestCheckResourceAttr(testDataPostgresqlInstancesName, "instance_list.0.charge_type", "POSTPAID_BY_HOUR"),
2625
resource.TestCheckResourceAttr(testDataPostgresqlInstancesName, "instance_list.0.engine_version", "9.3.5"),
2726
resource.TestCheckResourceAttr(testDataPostgresqlInstancesName, "instance_list.0.project_id", "0"),
@@ -31,6 +30,7 @@ func TestAccTencentCloudDataPostgresqlInstances(t *testing.T) {
3130
resource.TestCheckResourceAttrSet(testDataPostgresqlInstancesName, "instance_list.0.private_access_port"),
3231
resource.TestCheckResourceAttrSet(testDataPostgresqlInstancesName, "instance_list.0.public_access_switch"),
3332
resource.TestCheckResourceAttrSet(testDataPostgresqlInstancesName, "instance_list.0.charset"),
33+
resource.TestCheckResourceAttr(testDataPostgresqlInstancesName, "instance_list.0.tags.tf", "test"),
3434
),
3535
},
3636
},
@@ -52,6 +52,10 @@ charset = "UTF8"
5252
project_id = 0
5353
memory = 2
5454
storage = 10
55+
56+
tags = {
57+
tf = "test"
58+
}
5559
}
5660
5761
data "tencentcloud_postgresql_instances" "id_test"{

tencentcloud/resource_tc_cos_bucket.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ func resourceTencentCloudCosBucket() *schema.Resource {
271271
Optional: true,
272272
Description: "The tags of a bucket.",
273273
},
274+
//computed
275+
"cos_bucket_url": {
276+
Type: schema.TypeString,
277+
Computed: true,
278+
Description: "The URL of this cos bucket.",
279+
},
274280
},
275281
}
276282
}
@@ -323,6 +329,8 @@ func resourceTencentCloudCosBucketRead(d *schema.ResourceData, meta interface{})
323329
}
324330
}
325331

332+
cosBuckeUrl := fmt.Sprintf("%s.cos.%s.myqcloud.com", d.Id(), meta.(*TencentCloudClient).apiV3Conn.Region)
333+
_ = d.Set("cos_bucket_url", cosBuckeUrl)
326334
// set bucket in the import case
327335
if _, ok := d.GetOk("bucket"); !ok {
328336
_ = d.Set("bucket", d.Id())

tencentcloud/resource_tc_cos_bucket_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func TestAccTencentCloudCosBucket_basic(t *testing.T) {
8282
testAccCheckCosBucketExists("tencentcloud_cos_bucket.bucket_basic"),
8383
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_basic", "encryption_algorithm", "AES256"),
8484
resource.TestCheckResourceAttr("tencentcloud_cos_bucket.bucket_basic", "versioning_enable", "true"),
85+
resource.TestCheckResourceAttrSet("tencentcloud_cos_bucket.bucket_basic", "cos_bucket_url"),
8586
),
8687
},
8788
{

tencentcloud/resource_tc_nat_gateway.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ resource "tencentcloud_nat_gateway" "foo" {
1010
bandwidth = 100
1111
max_concurrent = 1000000
1212
assigned_eip_set = ["1.1.1.1"]
13+
14+
tags = {
15+
test = "tf"
16+
}
1317
}
1418
```
1519
@@ -24,6 +28,7 @@ $ terraform import tencentcloud_nat_gateway.foo nat-1asg3t63
2428
package tencentcloud
2529

2630
import (
31+
"context"
2732
"fmt"
2833
"log"
2934
"time"
@@ -81,6 +86,12 @@ func resourceTencentCloudNatGateway() *schema.Resource {
8186
MaxItems: 10,
8287
Description: "EIP IP address set bound to the gateway. The value of at least 1 and at most 10.",
8388
},
89+
"tags": {
90+
Type: schema.TypeMap,
91+
Optional: true,
92+
Description: "The available tags within this NAT gateway.",
93+
},
94+
//computed
8495
"created_time": {
8596
Type: schema.TypeString,
8697
Computed: true,
@@ -161,6 +172,17 @@ func resourceTencentCloudNatGatewayCreate(d *schema.ResourceData, meta interface
161172
log.Printf("[CRITAL]%s create NAT gateway failed, reason:%s\n", logId, err.Error())
162173
return err
163174
}
175+
176+
//cs::vpc:ap-guangzhou:uin/12345:nat/nat-nxxx
177+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
178+
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
179+
tcClient := meta.(*TencentCloudClient).apiV3Conn
180+
tagService := &TagService{client: tcClient}
181+
resourceName := BuildTagResourceName("vpc", "nat", tcClient.Region, d.Id())
182+
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
183+
return err
184+
}
185+
}
164186
return resourceTencentCloudNatGatewayRead(d, meta)
165187
}
166188

@@ -169,6 +191,7 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
169191
defer inconsistentCheck(d, meta)()
170192

171193
logId := getLogId(contextNil)
194+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
172195

173196
natGatewayId := d.Id()
174197
request := vpc.NewDescribeNatGatewaysRequest()
@@ -201,6 +224,15 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{}
201224
_ = d.Set("bandwidth", *nat.InternetMaxBandwidthOut)
202225
_ = d.Set("create_time", *nat.CreatedTime)
203226
_ = d.Set("assigned_eip_set", flattenAddressList((*nat).PublicIpAddressSet))
227+
228+
tcClient := meta.(*TencentCloudClient).apiV3Conn
229+
tagService := &TagService{client: tcClient}
230+
tags, err := tagService.DescribeResourceTags(ctx, "vpc", "nat", tcClient.Region, d.Id())
231+
if err != nil {
232+
return err
233+
}
234+
_ = d.Set("tags", tags)
235+
204236
return nil
205237
}
206238

@@ -407,6 +439,23 @@ func resourceTencentCloudNatGatewayUpdate(d *schema.ResourceData, meta interface
407439
}
408440

409441
}
442+
443+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
444+
if d.HasChange("tags") {
445+
446+
oldValue, newValue := d.GetChange("tags")
447+
replaceTags, deleteTags := diffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{}))
448+
449+
tcClient := meta.(*TencentCloudClient).apiV3Conn
450+
tagService := &TagService{client: tcClient}
451+
resourceName := BuildTagResourceName("vpc", "nat", tcClient.Region, d.Id())
452+
err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags)
453+
if err != nil {
454+
return err
455+
}
456+
d.SetPartial("tags")
457+
}
458+
410459
d.Partial(false)
411460

412461
return nil

0 commit comments

Comments
 (0)