Skip to content

Commit 490a1cd

Browse files
authored
add param sg (#2482)
* add param sg * add changelog
1 parent e6098c4 commit 490a1cd

File tree

5 files changed

+97
-12
lines changed

5 files changed

+97
-12
lines changed

.changelog/2482.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_vpc_end_point: Support set `security_groups_ids`
3+
```

tencentcloud/services/pls/resource_tc_vpc_end_point.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func ResourceTencentCloudVpcEndPoint() *schema.Resource {
5555
Description: "VIP of endpoint ip.",
5656
},
5757

58+
"security_groups_ids": {
59+
Optional: true,
60+
Type: schema.TypeList,
61+
Computed: true,
62+
Elem: &schema.Schema{Type: schema.TypeString},
63+
Description: "Ordered security groups associated with the endpoint.",
64+
},
65+
5866
"end_point_owner": {
5967
Computed: true,
6068
Type: schema.TypeString,
@@ -121,10 +129,29 @@ func resourceTencentCloudVpcEndPointCreate(d *schema.ResourceData, meta interfac
121129
log.Printf("[CRITAL]%s create vpc endPoint failed, reason:%+v", logId, err)
122130
return err
123131
}
124-
125132
endPointId = *response.Response.EndPoint.EndPointId
126133
d.SetId(endPointId)
127134

135+
if v, ok := d.GetOk("security_groups_ids"); ok {
136+
request := vpc.NewModifyVpcEndPointAttributeRequest()
137+
request.EndPointId = helper.String(endPointId)
138+
request.SecurityGroupIds = helper.InterfacesStringsPoint(v.([]interface{}))
139+
140+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
141+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient().ModifyVpcEndPointAttribute(request)
142+
if e != nil {
143+
return tccommon.RetryError(e)
144+
} else {
145+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
146+
}
147+
return nil
148+
})
149+
if err != nil {
150+
log.Printf("[CRITAL]%s create vpc endPoint failed, reason:%+v", logId, err)
151+
return err
152+
}
153+
154+
}
128155
return resourceTencentCloudVpcEndPointRead(d, meta)
129156
}
130157

@@ -182,6 +209,10 @@ func resourceTencentCloudVpcEndPointRead(d *schema.ResourceData, meta interface{
182209
_ = d.Set("create_time", endPoint.CreateTime)
183210
}
184211

212+
if endPoint.GroupSet != nil {
213+
_ = d.Set("security_groups_ids", endPoint.GroupSet)
214+
}
215+
185216
return nil
186217
}
187218

@@ -209,10 +240,14 @@ func resourceTencentCloudVpcEndPointUpdate(d *schema.ResourceData, meta interfac
209240
}
210241
}
211242

212-
if d.HasChange("end_point_name") {
243+
if d.HasChange("end_point_name") || d.HasChange("security_groups_ids") {
213244
if v, ok := d.GetOk("end_point_name"); ok {
214245
request.EndPointName = helper.String(v.(string))
215246
}
247+
248+
if v, ok := d.GetOk("security_groups_ids"); ok {
249+
request.SecurityGroupIds = helper.InterfacesStringsPoint(v.([]interface{}))
250+
}
216251
}
217252

218253
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {

tencentcloud/services/pls/resource_tc_vpc_end_point.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ Example Usage
44

55
```hcl
66
resource "tencentcloud_vpc_end_point" "end_point" {
7-
vpc_id = "vpc-391sv4w3"
8-
subnet_id = "subnet-ljyn7h30"
9-
end_point_name = "terraform-test"
7+
vpc_id = "vpc-391sv4w3"
8+
subnet_id = "subnet-ljyn7h30"
9+
end_point_name = "terraform-test"
1010
end_point_service_id = "vpcsvc-69y13tdb"
11-
end_point_vip = "10.0.2.1"
11+
end_point_vip = "10.0.2.1"
12+
13+
security_groups_ids = [
14+
"sg-ghvp9djf",
15+
"sg-if748odn",
16+
"sg-3k7vtgf7",
17+
]
1218
}
1319
```
1420

tencentcloud/services/pls/resource_tc_vpc_end_point_test.go

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,19 @@ func TestAccTencentCloudVpcEndPointResource_basic(t *testing.T) {
1818
Steps: []resource.TestStep{
1919
{
2020
Config: testAccVpcEndPoint,
21-
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_vpc_end_point.end_point", "id")),
21+
Check: resource.ComposeTestCheckFunc(
22+
resource.TestCheckResourceAttrSet("tencentcloud_vpc_end_point.end_point", "id"),
23+
resource.TestCheckResourceAttr("tencentcloud_vpc_end_point.end_point", "end_point_name", "terraform_test"),
24+
resource.TestCheckResourceAttr("tencentcloud_vpc_end_point.end_point", "security_groups_ids.0", "sg-ghvp9djf"),
25+
),
26+
},
27+
28+
{
29+
Config: testAccVpcEndPointUpdate,
30+
Check: resource.ComposeAggregateTestCheckFunc(
31+
resource.TestCheckResourceAttr("tencentcloud_vpc_end_point.end_point", "end_point_name", "terraform_test_for"),
32+
resource.TestCheckResourceAttr("tencentcloud_vpc_end_point.end_point", "security_groups_ids.0", "sg-3k7vtgf7"),
33+
),
2234
},
2335
{
2436
ResourceName: "tencentcloud_vpc_end_point.end_point",
@@ -32,11 +44,33 @@ func TestAccTencentCloudVpcEndPointResource_basic(t *testing.T) {
3244
const testAccVpcEndPoint = `
3345
3446
resource "tencentcloud_vpc_end_point" "end_point" {
35-
vpc_id = "vpc-391sv4w3"
36-
subnet_id = "subnet-ljyn7h30"
37-
end_point_name = "terraform-test"
38-
end_point_service_id = "vpcsvc-98jddhcz"
39-
end_point_vip = "10.0.2.2"
47+
end_point_name = "terraform_test"
48+
end_point_service_id = "vpcsvc-5y4yb85d"
49+
end_point_vip = "10.0.0.58"
50+
security_groups_ids = [
51+
"sg-ghvp9djf",
52+
"sg-if748odn",
53+
"sg-3k7vtgf7",
54+
]
55+
subnet_id = "subnet-cpknsqgo"
56+
vpc_id = "vpc-gmq0mxoj"
57+
}
58+
59+
`
60+
61+
const testAccVpcEndPointUpdate = `
62+
63+
resource "tencentcloud_vpc_end_point" "end_point" {
64+
end_point_name = "terraform_test_for"
65+
end_point_service_id = "vpcsvc-5y4yb85d"
66+
end_point_vip = "10.0.0.58"
67+
security_groups_ids = [
68+
"sg-3k7vtgf7",
69+
"sg-ghvp9djf",
70+
"sg-if748odn",
71+
]
72+
subnet_id = "subnet-cpknsqgo"
73+
vpc_id = "vpc-gmq0mxoj"
4074
}
4175
4276
`

website/docs/r/vpc_end_point.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ resource "tencentcloud_vpc_end_point" "end_point" {
2020
end_point_name = "terraform-test"
2121
end_point_service_id = "vpcsvc-69y13tdb"
2222
end_point_vip = "10.0.2.1"
23+
24+
security_groups_ids = [
25+
"sg-ghvp9djf",
26+
"sg-if748odn",
27+
"sg-3k7vtgf7",
28+
]
2329
}
2430
```
2531

@@ -32,6 +38,7 @@ The following arguments are supported:
3238
* `subnet_id` - (Required, String) ID of subnet instance.
3339
* `vpc_id` - (Required, String) ID of vpc instance.
3440
* `end_point_vip` - (Optional, String) VIP of endpoint ip.
41+
* `security_groups_ids` - (Optional, List: [`String`]) Ordered security groups associated with the endpoint.
3542

3643
## Attributes Reference
3744

0 commit comments

Comments
 (0)