Skip to content

Commit 6766cb9

Browse files
gitmknanonymous
andauthored
Feat/tem gateway (#1494)
* fix: support clb bind * fix: support application service modify * fix: support tag * feat: add changelog * fix: modify unit * fix: modify changelog * fix: modify tags * fix: update tem sdk * fix: modify unit * fix: modify unit * fix: modify tags * fix: modify changelog * fix: modify unit Co-authored-by: anonymous <anonymous@mail.org>
1 parent b9c39b6 commit 6766cb9

18 files changed

+354
-25
lines changed

.changelog/1494.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_tem_application: Support tags field
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_tem_application_service: Support service modification
7+
```
8+
9+
```release-note:enhancement
10+
resource/tencentcloud_tem_environment: Support service modification and support tags field
11+
```
12+

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require (
3535
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.445
3636
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
3737
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412
38-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.572
38+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.573
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553
4040
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.488
4141
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
@@ -74,7 +74,7 @@ require (
7474
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.503
7575
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533
7676
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.564
77-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.527
77+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.573
7878
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529
7979
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.549
8080
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.572 h1:xbcb
544544
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.572/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
545545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.571 h1:V4JQJTavl2X8aRBRBBh4vTOInuzrbqQzHlFitmu782U=
546546
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.571/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
547+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.572 h1:xbcb/bC/cSWpfLB3TW+GBUdIcY/x+T+VrBgsz/jxv5Q=
548+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.572/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
549+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.573 h1:H2p5AhpSC9BVc5+bLsB5v/ktDx1tLw+SAChHHTpKzfY=
550+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.573/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
547551
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445 h1:Bh7XD0ypNMHYyBOM8hhKsSu+y0VVKUnJVS+YKKhfpGg=
548552
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445/go.mod h1:jMDD351efCFpT1+KVFbcpu6SbmP4TYmp4qkoCfr63nQ=
549553
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553 h1:Pl1kYgFhJp0QSoVFSzRsiGk+HfEAkBTQg7+O60tytNA=
@@ -639,6 +643,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.564 h1:YO2DCc
639643
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.564/go.mod h1:7ZZ31onSvtbcR8XJWMx2kAhgNDuX/TvyWpQgJW1NqlQ=
640644
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.527 h1:nRFYv2eZ+qMsOYID+ZmI4nSJuuXUgm2SCLFVu3bQmnw=
641645
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.527/go.mod h1:mWXRd5WNzX7ypg1MNliZvz5mlfIJ9h0KvyOGnH86KFc=
646+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.573 h1:cf0nErWh7i85lgJZwN/1I65CbhmlCZrN458vmSeIYtQ=
647+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.573/go.mod h1:rZTntzTRsDs4Rhs2gjbxduXWGt7/lTHHflf/mfy68Gc=
642648
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529 h1:vWUgseUvHs1fW/Ok+x3ld9UIhrYRNO9Yr8ccX8wmkkY=
643649
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529/go.mod h1:vOd23iOVeQqm5LSEXUmE8773kiUCwGuoJnTO0po5D+Q=
644650
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.519 h1:o8NsQPLV6T8TD4sHxufCwtCsqYM4CUM1132zut6toww=

tencentcloud/resource_tc_tem_application.go

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ resource "tencentcloud_tem_application" "application" {
1212
repo_type = 2
1313
repo_name = "qcloud/nginx"
1414
repo_server = "ccr.ccs.tencentyun.com"
15+
tags = {
16+
"created" = "terraform"
17+
}
1518
}
1619
```
1720
*/
@@ -87,6 +90,11 @@ func resourceTencentCloudTemApplication() *schema.Resource {
8790
Computed: true,
8891
Description: "tcr instance id.",
8992
},
93+
"tags": {
94+
Type: schema.TypeMap,
95+
Optional: true,
96+
Description: "application tag list.",
97+
},
9098
},
9199
}
92100
}
@@ -96,6 +104,7 @@ func resourceTencentCloudTemApplicationCreate(d *schema.ResourceData, meta inter
96104
defer inconsistentCheck(d, meta)()
97105

98106
logId := getLogId(contextNil)
107+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
99108

100109
var (
101110
request = tem.NewCreateApplicationRequest()
@@ -132,6 +141,16 @@ func resourceTencentCloudTemApplicationCreate(d *schema.ResourceData, meta inter
132141
request.InstanceId = helper.String(v.(string))
133142
}
134143

144+
if v, ok := d.GetOk("tags"); ok {
145+
for key, value := range v.(map[string]interface{}) {
146+
tag := tem.Tag{
147+
TagKey: helper.String(key),
148+
TagValue: helper.String(value.(string)),
149+
}
150+
request.Tags = append(request.Tags, &tag)
151+
}
152+
}
153+
135154
request.DeployMode = helper.String("IMAGE")
136155

137156
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
@@ -154,6 +173,16 @@ func resourceTencentCloudTemApplicationCreate(d *schema.ResourceData, meta inter
154173
applicationId := *response.Response.Result
155174

156175
d.SetId(applicationId)
176+
177+
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
178+
tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn}
179+
region := meta.(*TencentCloudClient).apiV3Conn.Region
180+
resourceName := fmt.Sprintf("qcs::tem:%s:uin/:application/%s", region, applicationId)
181+
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
182+
return err
183+
}
184+
}
185+
157186
return resourceTencentCloudTemApplicationRead(d, meta)
158187
}
159188

@@ -209,6 +238,15 @@ func resourceTencentCloudTemApplicationRead(d *schema.ResourceData, meta interfa
209238
_ = d.Set("instance_id", application.InstanceId)
210239
}
211240

241+
client := meta.(*TencentCloudClient).apiV3Conn
242+
tagService := TagService{client: client}
243+
region := client.Region
244+
tags, err := tagService.DescribeResourceTags(ctx, "tem", "application", region, applicationId)
245+
if err != nil {
246+
return err
247+
}
248+
_ = d.Set("tags", tags)
249+
212250
return nil
213251
}
214252

@@ -217,6 +255,7 @@ func resourceTencentCloudTemApplicationUpdate(d *schema.ResourceData, meta inter
217255
defer inconsistentCheck(d, meta)()
218256

219257
logId := getLogId(contextNil)
258+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
220259

221260
request := tem.NewModifyApplicationInfoRequest()
222261

@@ -226,10 +265,8 @@ func resourceTencentCloudTemApplicationUpdate(d *schema.ResourceData, meta inter
226265
return fmt.Errorf("`application_name` do not support change now.")
227266
}
228267

229-
if d.HasChange("description") {
230-
if v, ok := d.GetOk("description"); ok {
231-
request.Description = helper.String(v.(string))
232-
}
268+
if v, ok := d.GetOk("description"); ok {
269+
request.Description = helper.String(v.(string))
233270
}
234271

235272
if d.HasChange("coding_language") {
@@ -271,6 +308,17 @@ func resourceTencentCloudTemApplicationUpdate(d *schema.ResourceData, meta inter
271308
return err
272309
}
273310

311+
if d.HasChange("tags") {
312+
tcClient := meta.(*TencentCloudClient).apiV3Conn
313+
tagService := &TagService{client: tcClient}
314+
oldTags, newTags := d.GetChange("tags")
315+
replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{}))
316+
resourceName := BuildTagResourceName("tem", "application", tcClient.Region, d.Id())
317+
if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil {
318+
return err
319+
}
320+
}
321+
274322
return resourceTencentCloudTemApplicationRead(d, meta)
275323
}
276324

tencentcloud/resource_tc_tem_application_service.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,6 @@ func resourceTencentCloudTemApplicationServiceUpdate(d *schema.ResourceData, met
267267

268268
logId := getLogId(contextNil)
269269

270-
unsupportedUpdateFields := []string{
271-
"service",
272-
}
273-
for _, field := range unsupportedUpdateFields {
274-
if d.HasChange(field) {
275-
return fmt.Errorf("tencentcloud_tem_application_service update on %s is not support yet", field)
276-
}
277-
}
278-
279270
request := tem.NewModifyApplicationServiceRequest()
280271

281272
idSplit := strings.Split(d.Id(), FILED_SP)

tencentcloud/resource_tc_tem_application_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestAccTencentCloudTemApplicationResource_basic(t *testing.T) {
3232
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "repo_type", "2"),
3333
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "repo_name", "qcloud/nginx"),
3434
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "repo_server", "ccr.ccs.tencentyun.com"),
35+
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "tags.createdBy", "terraform"),
3536
),
3637
},
3738
// {
@@ -98,6 +99,9 @@ resource "tencentcloud_tem_application" "application" {
9899
repo_type = 2
99100
repo_name = "qcloud/nginx"
100101
repo_server = "ccr.ccs.tencentyun.com"
102+
tags = {
103+
"createdBy" = "terraform"
104+
}
101105
}
102106
103107
`

tencentcloud/resource_tc_tem_environment.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ resource "tencentcloud_tem_environment" "environment" {
99
description = "demo for test"
1010
vpc = "vpc-2hfyray3"
1111
subnet_ids = ["subnet-rdkj0agk", "subnet-r1c4pn5m", "subnet-02hcj95c"]
12+
tags = {
13+
"created" = "terraform"
14+
}
1215
}
1316
1417
```
@@ -68,6 +71,11 @@ func resourceTencentCloudTemEnvironment() *schema.Resource {
6871
Required: true,
6972
Description: "subnet IDs.",
7073
},
74+
"tags": {
75+
Type: schema.TypeMap,
76+
Optional: true,
77+
Description: "environment tag list.",
78+
},
7179
},
7280
}
7381
}
@@ -103,6 +111,16 @@ func resourceTencentCloudTemEnvironmentCreate(d *schema.ResourceData, meta inter
103111
}
104112
}
105113

114+
if v, ok := d.GetOk("tags"); ok {
115+
for key, value := range v.(map[string]interface{}) {
116+
tag := tem.Tag{
117+
TagKey: helper.String(key),
118+
TagValue: helper.String(value.(string)),
119+
}
120+
request.Tags = append(request.Tags, &tag)
121+
}
122+
}
123+
106124
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
107125
result, e := meta.(*TencentCloudClient).apiV3Conn.UseTemClient().CreateEnvironment(request)
108126
if e != nil {
@@ -143,6 +161,16 @@ func resourceTencentCloudTemEnvironmentCreate(d *schema.ResourceData, meta inter
143161
}
144162

145163
d.SetId(environmentId)
164+
165+
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
166+
tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn}
167+
region := meta.(*TencentCloudClient).apiV3Conn.Region
168+
resourceName := fmt.Sprintf("qcs::tem:%s:uin/:tem-environment/%s", region, environmentId)
169+
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
170+
return err
171+
}
172+
}
173+
146174
return resourceTencentCloudTemEnvironmentRead(d, meta)
147175
}
148176

@@ -184,6 +212,15 @@ func resourceTencentCloudTemEnvironmentRead(d *schema.ResourceData, meta interfa
184212
_ = d.Set("subnet_ids", environment.SubnetIds)
185213
}
186214

215+
client := meta.(*TencentCloudClient).apiV3Conn
216+
tagService := TagService{client: client}
217+
region := client.Region
218+
tags, err := tagService.DescribeResourceTags(ctx, "tem", "tem-environment", region, environmentId)
219+
if err != nil {
220+
return err
221+
}
222+
_ = d.Set("tags", tags)
223+
187224
return nil
188225
}
189226

@@ -192,6 +229,7 @@ func resourceTencentCloudTemEnvironmentUpdate(d *schema.ResourceData, meta inter
192229
defer inconsistentCheck(d, meta)()
193230

194231
logId := getLogId(contextNil)
232+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
195233

196234
request := tem.NewModifyEnvironmentRequest()
197235

@@ -238,6 +276,17 @@ func resourceTencentCloudTemEnvironmentUpdate(d *schema.ResourceData, meta inter
238276
return err
239277
}
240278

279+
if d.HasChange("tags") {
280+
tcClient := meta.(*TencentCloudClient).apiV3Conn
281+
tagService := &TagService{client: tcClient}
282+
oldTags, newTags := d.GetChange("tags")
283+
replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{}))
284+
resourceName := BuildTagResourceName("tem", "environment", tcClient.Region, d.Id())
285+
if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil {
286+
return err
287+
}
288+
}
289+
241290
return resourceTencentCloudTemEnvironmentRead(d, meta)
242291
}
243292

tencentcloud/resource_tc_tem_environment_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestAccTencentCloudTemEnvironmentResource_basic(t *testing.T) {
2828
resource.TestCheckResourceAttrSet("tencentcloud_tem_environment.environment", "id"),
2929
resource.TestCheckResourceAttr("tencentcloud_tem_environment.environment", "environment_name", "demo"),
3030
resource.TestCheckResourceAttr("tencentcloud_tem_environment.environment", "description", "demo for test"),
31+
resource.TestCheckResourceAttr("tencentcloud_tem_environment.environment", "tags.createdBy", "terraform"),
3132
),
3233
},
3334
{
@@ -106,6 +107,9 @@ resource "tencentcloud_tem_environment" "environment" {
106107
description = "demo for test"
107108
vpc = var.vpc_id
108109
subnet_ids = [var.subnet_id]
110+
tags = {
111+
"createdBy" = "terraform"
112+
}
109113
}
110114
111115
`

tencentcloud/resource_tc_tem_gateway.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ func resourceTencentCloudTemGateway() *schema.Resource {
203203
},
204204
"clb_id": {
205205
Type: schema.TypeString,
206+
Optional: true,
206207
Computed: true,
207-
Description: "related CLB ID.",
208+
Description: "related CLB ID, support binding existing clb, does not support modification.",
208209
},
209210
"create_time": {
210211
Type: schema.TypeString,
@@ -309,6 +310,9 @@ func resourceTencentCloudTemGatewayCreate(d *schema.ResourceData, meta interface
309310
ingressInfo.Rules = append(ingressInfo.Rules, &ingressRule)
310311
}
311312
}
313+
if v, ok := dMap["clb_id"]; ok {
314+
ingressInfo.ClbId = helper.String(v.(string))
315+
}
312316
request.Ingress = &ingressInfo
313317
}
314318

tencentcloud/service_tencentcloud_tem.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ func (me *TemService) DescribeTemGateway(ctx context.Context, environmentId stri
430430
if *gateway.ClbId != "" && *gateway.Vip != "" {
431431
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
432432
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
433+
log.Printf("[DEBUG]%s api[%s] if you enter a clb_id that does not exist, it may cause the vip to be empty", logId, request.GetAction())
433434
return nil
434435
}
435436
return resource.RetryableError(fmt.Errorf("gateway clb is not ready..."))

0 commit comments

Comments
 (0)