Skip to content

Commit 2a67659

Browse files
authored
feat: vpc assistant-cidr (#800)
1 parent 07d5661 commit 2a67659

File tree

4 files changed

+208
-9
lines changed

4 files changed

+208
-9
lines changed

tencentcloud/resource_tc_postgresql_instance.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ package tencentcloud
5757
import (
5858
"context"
5959
"fmt"
60-
postgresql "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres/v20170312"
6160
"log"
6261
"strconv"
6362
"strings"
6463
"time"
6564

65+
postgresql "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres/v20170312"
66+
6667
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
6768

6869
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"

tencentcloud/resource_tc_vpc.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ resource "tencentcloud_vpc" "foo" {
1616
}
1717
```
1818
19+
Using Assistant CIDR
20+
```hcl
21+
resource "tencentcloud_vpc" "foo" {
22+
name = "ci-temp-test-updated"
23+
cidr_block = "10.0.0.0/16"
24+
is_multicast = false
25+
assistant_cidr = ["172.16.0.0/24"]
26+
27+
tags = {
28+
"test" = "test"
29+
}
30+
}
31+
```
32+
1933
Import
2034
2135
Vpc instance can be imported, e.g.
@@ -31,6 +45,8 @@ import (
3145
"fmt"
3246
"log"
3347

48+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
49+
3450
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
3551
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
3652
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
@@ -78,6 +94,14 @@ func resourceTencentCloudVpcInstance() *schema.Resource {
7894
Default: true,
7995
Description: "Indicates whether VPC multicast is enabled. The default value is 'true'.",
8096
},
97+
"assistant_cidrs": {
98+
Type: schema.TypeList,
99+
Optional: true,
100+
Description: "List of Assistant CIDR.",
101+
Elem: &schema.Schema{
102+
Type: schema.TypeString,
103+
},
104+
},
81105
"tags": {
82106
Type: schema.TypeMap,
83107
Optional: true,
@@ -148,6 +172,17 @@ func resourceTencentCloudVpcInstanceCreate(d *schema.ResourceData, meta interfac
148172

149173
d.SetId(vpcId)
150174

175+
if v, ok := d.GetOk("assistant_cidrs"); ok {
176+
assistantCidrs := v.([]interface{})
177+
request := vpc.NewCreateAssistantCidrRequest()
178+
request.VpcId = &vpcId
179+
request.CidrBlocks = helper.InterfacesStringsPoint(assistantCidrs)
180+
_, err := vpcService.CreateAssistantCidr(ctx, request)
181+
if err != nil {
182+
return err
183+
}
184+
}
185+
151186
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
152187
tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn}
153188

@@ -223,6 +258,7 @@ func resourceTencentCloudVpcInstanceRead(d *schema.ResourceData, meta interface{
223258
_ = d.Set("is_multicast", info.isMulticast)
224259
_ = d.Set("create_time", info.createTime)
225260
_ = d.Set("is_default", info.isDefault)
261+
_ = d.Set("assistant_cidrs", info.assistantCidrs)
226262
_ = d.Set("tags", tags)
227263

228264
return nil
@@ -300,6 +336,18 @@ func resourceTencentCloudVpcInstanceUpdate(d *schema.ResourceData, meta interfac
300336
d.SetPartial(attr)
301337
}
302338

339+
if d.HasChange("assistant_cidrs") {
340+
old, now := d.GetChange("assistant_cidrs")
341+
request := vpc.NewModifyAssistantCidrRequest()
342+
request.VpcId = &id
343+
request.NewCidrBlocks = helper.InterfacesStringsPoint(now.([]interface{}))
344+
request.OldCidrBlocks = helper.InterfacesStringsPoint(old.([]interface{}))
345+
if err := vpcService.ModifyAssistantCidr(ctx, request); err != nil {
346+
return err
347+
}
348+
d.SetPartial("assistant_cidrs")
349+
}
350+
303351
if d.HasChange("tags") {
304352
oldTags, newTags := d.GetChange("tags")
305353
replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{}))

tencentcloud/service_tencentcloud_vpc.go

Lines changed: 142 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ var eipUnattachLocker = &sync.Mutex{}
2727

2828
// VPC basic information
2929
type VpcBasicInfo struct {
30-
vpcId string
31-
name string
32-
cidr string
33-
isMulticast bool
34-
isDefault bool
35-
dnsServers []string
36-
createTime string
37-
tags []*vpc.Tag
30+
vpcId string
31+
name string
32+
cidr string
33+
isMulticast bool
34+
isDefault bool
35+
dnsServers []string
36+
createTime string
37+
tags []*vpc.Tag
38+
assistantCidrs []string
3839
}
3940

4041
// subnet basic information
@@ -338,6 +339,13 @@ getMoreData:
338339
}
339340
hasVpc[basicInfo.vpcId] = true
340341

342+
if len(item.AssistantCidrSet) > 0 {
343+
for i := range item.AssistantCidrSet {
344+
cidr := item.AssistantCidrSet[i].CidrBlock
345+
basicInfo.assistantCidrs = append(basicInfo.assistantCidrs, *cidr)
346+
}
347+
}
348+
341349
if len(item.TagSet) > 0 {
342350
basicInfo.tags = item.TagSet
343351
}
@@ -4154,3 +4162,129 @@ func (me *VpcService) DescribeNatGatewaySnats(ctx context.Context, natGatewayId
41544162
offset = offset + limit
41554163
}
41564164
}
4165+
4166+
func (me *VpcService) DescribeAssistantCidr(ctx context.Context, vpcId string) (info []*vpc.AssistantCidr, errRet error) {
4167+
logId := getLogId(ctx)
4168+
request := vpc.NewDescribeAssistantCidrRequest()
4169+
4170+
defer func() {
4171+
if errRet != nil {
4172+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
4173+
logId, request.GetAction(), request.ToJsonString(), errRet.Error())
4174+
}
4175+
}()
4176+
4177+
request.VpcIds = []*string{&vpcId}
4178+
4179+
ratelimit.Check(request.GetAction())
4180+
response, err := me.client.UseVpcClient().DescribeAssistantCidr(request)
4181+
4182+
if err != nil {
4183+
errRet = err
4184+
return
4185+
}
4186+
4187+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
4188+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
4189+
4190+
info = response.Response.AssistantCidrSet
4191+
4192+
return
4193+
}
4194+
4195+
// CheckAssistantCidr used for check if cidr conflict
4196+
func (me *VpcService) CheckAssistantCidr(ctx context.Context, request *vpc.CheckAssistantCidrRequest) (info []*vpc.ConflictSource, errRet error) {
4197+
logId := getLogId(ctx)
4198+
defer func() {
4199+
if errRet != nil {
4200+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
4201+
logId, request.GetAction(), request.ToJsonString(), errRet.Error())
4202+
}
4203+
}()
4204+
4205+
ratelimit.Check(request.GetAction())
4206+
response, err := me.client.UseVpcClient().CheckAssistantCidr(request)
4207+
4208+
if err != nil {
4209+
errRet = err
4210+
return
4211+
}
4212+
4213+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
4214+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
4215+
4216+
info = response.Response.ConflictSourceSet
4217+
4218+
return
4219+
}
4220+
4221+
func (me *VpcService) CreateAssistantCidr(ctx context.Context, request *vpc.CreateAssistantCidrRequest) (info []*vpc.AssistantCidr, errRet error) {
4222+
logId := getLogId(ctx)
4223+
defer func() {
4224+
if errRet != nil {
4225+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
4226+
logId, request.GetAction(), request.ToJsonString(), errRet.Error())
4227+
}
4228+
}()
4229+
4230+
ratelimit.Check(request.GetAction())
4231+
response, err := me.client.UseVpcClient().CreateAssistantCidr(request)
4232+
4233+
if err != nil {
4234+
errRet = err
4235+
return
4236+
}
4237+
4238+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
4239+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
4240+
4241+
info = response.Response.AssistantCidrSet
4242+
4243+
return
4244+
}
4245+
4246+
func (me *VpcService) ModifyAssistantCidr(ctx context.Context, request *vpc.ModifyAssistantCidrRequest) (errRet error) {
4247+
logId := getLogId(ctx)
4248+
defer func() {
4249+
if errRet != nil {
4250+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
4251+
logId, request.GetAction(), request.ToJsonString(), errRet.Error())
4252+
}
4253+
}()
4254+
4255+
ratelimit.Check(request.GetAction())
4256+
response, err := me.client.UseVpcClient().ModifyAssistantCidr(request)
4257+
4258+
if err != nil {
4259+
errRet = err
4260+
return
4261+
}
4262+
4263+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
4264+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
4265+
4266+
return
4267+
}
4268+
4269+
func (me *VpcService) DeleteAssistantCidr(ctx context.Context, request *vpc.DeleteAssistantCidrRequest) (errRet error) {
4270+
logId := getLogId(ctx)
4271+
defer func() {
4272+
if errRet != nil {
4273+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
4274+
logId, request.GetAction(), request.ToJsonString(), errRet.Error())
4275+
}
4276+
}()
4277+
4278+
ratelimit.Check(request.GetAction())
4279+
response, err := me.client.UseVpcClient().DeleteAssistantCidr(request)
4280+
4281+
if err != nil {
4282+
errRet = err
4283+
return
4284+
}
4285+
4286+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
4287+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
4288+
4289+
return
4290+
}

website/docs/r/vpc.html.markdown

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,28 @@ resource "tencentcloud_vpc" "foo" {
2626
}
2727
```
2828

29+
Using Assistant CIDR
30+
31+
```hcl
32+
resource "tencentcloud_vpc" "foo" {
33+
name = "ci-temp-test-updated"
34+
cidr_block = "10.0.0.0/16"
35+
is_multicast = false
36+
assistant_cidr = ["172.16.0.0/24"]
37+
38+
tags = {
39+
"test" = "test"
40+
}
41+
}
42+
```
43+
2944
## Argument Reference
3045

3146
The following arguments are supported:
3247

3348
* `cidr_block` - (Required, ForceNew) A network address block which should be a subnet of the three internal network segments (10.0.0.0/16, 172.16.0.0/12 and 192.168.0.0/16).
3449
* `name` - (Required) The name of the VPC.
50+
* `assistant_cidrs` - (Optional) List of Assistant CIDR.
3551
* `dns_servers` - (Optional) The DNS server list of the VPC. And you can specify 0 to 5 servers to this list.
3652
* `is_multicast` - (Optional) Indicates whether VPC multicast is enabled. The default value is 'true'.
3753
* `tags` - (Optional) Tags of the VPC.

0 commit comments

Comments
 (0)