Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vpc): [121226612] tencentcloud_vpn_gateway support bgp_asn #3041

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3041.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_vpn_gateway: support `bgp_asn`
```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1034
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1046
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1066
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1068
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1053
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1058
Expand Down Expand Up @@ -96,7 +96,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.857
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.860
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.1060
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.1068
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.1037
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.792
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1065 h1:krc
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1065/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1066 h1:D55KWjZcHJrrZC92ObBJBeo+ZGwzdVWTduIqiD2RACo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1066/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1068 h1:mI0xoreGp9GkDJWkdzqgZcPsfoWXciahPAvEcaGSA6g=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1068/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
Expand Down Expand Up @@ -1067,6 +1069,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.1045 h1:7+rfyx
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.1045/go.mod h1:yn4I7fSwpiM6ltjqksS1JtZZAHkZ35ywN+kLm6AJPzc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.1060 h1:hPEbNpABdOT1YA2B8aibfSQfxd91Ux2Xz8J7GqNHswE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.1060/go.mod h1:owVatMEAkXaooNfoH99tMFY+AAiSnsf9m+Rb/HY+oc0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.1068 h1:oHot9DQppI0bAZmUXZfP6SbYz7m48GBuQpUG2DnHwFU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.1068/go.mod h1:eY2rMPyFp9RQKaZAD6EvJda4+X9XljtqxZ5jkM5h7EQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.1037 h1:sgHOHqVFcO266dnoh0KJ0CoxrRglRZYKW78iBh41Giw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.1037/go.mod h1:QM5m6aZ65kaxaES0D44BNKmemn+9WBf5vr3HDDPrh8U=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.792 h1:NLgKNOIHWa38AmW7dyfI9Jlcp2Kr9VRD94f48pPNmxM=
Expand Down
106 changes: 73 additions & 33 deletions tencentcloud/services/vpn/resource_tc_vpn_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ func ResourceTencentCloudVpnGateway() *schema.Resource {
Optional: true,
Description: "A list of tags used to associate different resources.",
},
"bgp_asn": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "BGP ASN. Value range: 1 - 4294967295. Using BGP requires configuring ASN.",
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -196,6 +202,10 @@ func resourceTencentCloudVpnGatewayCreate(d *schema.ResourceData, meta interface
request.MaxConnection = helper.IntUint64(v.(int))
}

if v, ok := d.GetOkExists("bgp_asn"); ok {
request.BgpAsn = helper.IntUint64(v.(int))
}

var response *vpc.CreateVpnGatewayResponse
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient().CreateVpnGateway(request)
Expand All @@ -204,17 +214,24 @@ func resourceTencentCloudVpnGatewayCreate(d *schema.ResourceData, meta interface
logId, request.GetAction(), request.ToJsonString(), e.Error())
return tccommon.RetryError(e)
}

if result == nil || result.Response == nil || result.Response.VpnGateway == nil {
return resource.NonRetryableError(fmt.Errorf("create VPN gateway failed, Response is nil."))
}

response = result
return nil
})

if err != nil {
log.Printf("[CRITAL]%s create VPN gateway failed, reason:%s\n", logId, err.Error())
return err
}

if response.Response.VpnGateway == nil {
if response.Response.VpnGateway.VpnGatewayId == nil {
return fmt.Errorf("VPN gateway id is nil")
}

gatewayId := *response.Response.VpnGateway.VpnGatewayId
d.SetId(gatewayId)

Expand All @@ -229,14 +246,18 @@ func resourceTencentCloudVpnGatewayCreate(d *schema.ResourceData, meta interface
return tccommon.RetryError(e)
} else {
//if not, quit
if len(result.Response.VpnGatewaySet) != 1 {
return resource.NonRetryableError(fmt.Errorf("creating error"))
} else {
if *result.Response.VpnGatewaySet[0].State == svcvpc.VPN_STATE_AVAILABLE {
return nil
if result != nil && result.Response != nil && result.Response.VpnGatewaySet != nil {
if len(result.Response.VpnGatewaySet) != 1 {
return resource.NonRetryableError(fmt.Errorf("creating error"))
} else {
return resource.RetryableError(fmt.Errorf("State is not available: %s, wait for state to be AVAILABLE.", *result.Response.VpnGatewaySet[0].State))
if *result.Response.VpnGatewaySet[0].State == svcvpc.VPN_STATE_AVAILABLE {
return nil
} else {
return resource.RetryableError(fmt.Errorf("State is not available: %s, wait for state to be AVAILABLE.", *result.Response.VpnGatewaySet[0].State))
}
}
} else {
return resource.NonRetryableError(fmt.Errorf("Describe Vpn Gateways failed, Response is nil."))
}
}
})
Expand Down Expand Up @@ -300,6 +321,10 @@ func resourceTencentCloudVpnGatewayRead(d *schema.ResourceData, meta interface{}
_ = d.Set("zone", gateway.Zone)
_ = d.Set("cdc_id", gateway.CdcId)
_ = d.Set("max_connection", gateway.MaxConnection)
if gateway.BgpAsn != nil {
_ = d.Set("bgp_asn", gateway.BgpAsn)
}

//tags
tagService := svctag.NewTagService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
region := meta.(tccommon.ProviderMeta).GetAPIV3Conn().Region
Expand Down Expand Up @@ -386,7 +411,7 @@ func resourceTencentCloudVpnGatewayUpdate(d *schema.ResourceData, meta interface
}
}

if d.HasChange("name") || d.HasChange("charge_type") {
if d.HasChange("name") || d.HasChange("charge_type") || d.HasChange("bgp_asn") {
//check that the charge type change is valid
//only pre-paid --> post-paid is valid
oldInterface, newInterface := d.GetChange("charge_type")
Expand All @@ -395,6 +420,9 @@ func resourceTencentCloudVpnGatewayUpdate(d *schema.ResourceData, meta interface
request := vpc.NewModifyVpnGatewayAttributeRequest()
request.VpnGatewayId = &gatewayId
request.VpnGatewayName = helper.String(d.Get("name").(string))
if v, ok := d.GetOkExists("bgp_asn"); ok {
request.BgpAsn = helper.IntUint64(v.(int))
}
if oldChargeType == svcvpc.VPN_CHARGE_TYPE_PREPAID && newChargeType == svcvpc.VPN_CHARGE_TYPE_POSTPAID_BY_HOUR {
request.InstanceChargeType = &newChargeType
} else if oldChargeType == svcvpc.VPN_CHARGE_TYPE_POSTPAID_BY_HOUR && newChargeType == svcvpc.VPN_CHARGE_TYPE_PREPAID {
Expand Down Expand Up @@ -479,26 +507,30 @@ func resourceTencentCloudVpnGatewayDelete(d *schema.ResourceData, meta interface
if e != nil {
return tccommon.RetryError(e)
} else {
//if deleted, quit
if len(result.Response.VpnGatewaySet) == 0 {
return nil
}
if result.Response.VpnGatewaySet[0].ExpiredTime != nil && *result.Response.VpnGatewaySet[0].InstanceChargeType == svcvpc.VPN_CHARGE_TYPE_PREPAID {
expiredTime := *result.Response.VpnGatewaySet[0].ExpiredTime
if expiredTime != "0000-00-00 00:00:00" {
t, err := time.Parse("2006-01-02 15:04:05", expiredTime)
if err != nil {
return resource.NonRetryableError(fmt.Errorf("Error format expired time.%x %s", expiredTime, err))
}
if time.Until(t) > 0 {
return resource.NonRetryableError(fmt.Errorf("Delete operation is unsupport when VPN gateway is not expired."))
if result != nil && result.Response != nil && result.Response.VpnGatewaySet != nil {
//if deleted, quit
if len(result.Response.VpnGatewaySet) == 0 {
return nil
}
if result.Response.VpnGatewaySet[0].ExpiredTime != nil && *result.Response.VpnGatewaySet[0].InstanceChargeType == svcvpc.VPN_CHARGE_TYPE_PREPAID {
expiredTime := *result.Response.VpnGatewaySet[0].ExpiredTime
if expiredTime != "0000-00-00 00:00:00" {
t, err := time.Parse("2006-01-02 15:04:05", expiredTime)
if err != nil {
return resource.NonRetryableError(fmt.Errorf("Error format expired time.%x %s", expiredTime, err))
}
if time.Until(t) > 0 {
return resource.NonRetryableError(fmt.Errorf("Delete operation is unsupport when VPN gateway is not expired."))
}
}
}
if *result.Response.VpnGatewaySet[0].Type == svcvpc.GATE_WAY_TYPE_CCN && *result.Response.VpnGatewaySet[0].NetworkInstanceId != "" {
return resource.NonRetryableError(fmt.Errorf("Delete operation is unsupported when VPN gateway is attached to CCN instance."))
}
return nil
} else {
return resource.NonRetryableError(fmt.Errorf("Describe Vpn Gateways failed, Response is nil."))
}
if *result.Response.VpnGatewaySet[0].Type == svcvpc.GATE_WAY_TYPE_CCN && *result.Response.VpnGatewaySet[0].NetworkInstanceId != "" {
return resource.NonRetryableError(fmt.Errorf("Delete operation is unsupported when VPN gateway is attached to CCN instance."))
}
return nil
}
})
if vpngwErr != nil {
Expand Down Expand Up @@ -534,10 +566,14 @@ func resourceTencentCloudVpnGatewayDelete(d *schema.ResourceData, meta interface
logId, tRequest.GetAction(), tRequest.ToJsonString(), e.Error())
return tccommon.RetryError(e)
} else {
if len(result.Response.VpnConnectionSet) == 0 {
return nil
if result != nil && result.Response != nil && result.Response.VpnConnectionSet != nil {
if len(result.Response.VpnConnectionSet) == 0 {
return nil
} else {
return resource.NonRetryableError(fmt.Errorf("There is associated tunnel exists, please delete associated tunnels first."))
}
} else {
return resource.NonRetryableError(fmt.Errorf("There is associated tunnel exists, please delete associated tunnels first."))
return resource.NonRetryableError(fmt.Errorf("Describe Vpn Connections failed, Response is nil."))
}
}
})
Expand Down Expand Up @@ -582,12 +618,16 @@ func resourceTencentCloudVpnGatewayDelete(d *schema.ResourceData, meta interface
return tccommon.RetryError(e)
}
} else {
//if not, quit
if len(result.Response.VpnGatewaySet) == 0 {
return nil
if result != nil && result.Response != nil && result.Response.VpnGatewaySet != nil {
//if not, quit
if len(result.Response.VpnGatewaySet) == 0 {
return nil
}
//else consider delete fail
return resource.RetryableError(fmt.Errorf("deleting retry"))
} else {
return resource.NonRetryableError(fmt.Errorf("Describe Vpn Gateways failed, Response is nil."))
}
//else consider delete fail
return resource.RetryableError(fmt.Errorf("deleting retry"))
}
})
if err != nil {
Expand Down
56 changes: 38 additions & 18 deletions tencentcloud/services/vpn/resource_tc_vpn_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,94 @@ Provides a resource to create a VPN gateway.
Example Usage

VPC SSL VPN gateway

```hcl
resource "tencentcloud_vpn_gateway" "my_cgw" {
name = "test"
resource "tencentcloud_vpn_gateway" "example" {
name = "tf-example"
bandwidth = 5
zone = "ap-guangzhou-3"
type = "SSL"
vpc_id = "vpc-86v957zb"

tags = {
test = "test"
createBy = "terraform"
}
}
```

CCN IPSEC VPN gateway

```hcl
resource "tencentcloud_vpn_gateway" "my_cgw" {
name = "test"
resource "tencentcloud_vpn_gateway" "example" {
name = "tf-example"
bandwidth = 5
zone = "ap-guangzhou-3"
type = "IPSEC"

tags = {
test = "test"
tags = {
createBy = "terraform"
}
}
```

CCN SSL VPN gateway

```hcl
resource "tencentcloud_vpn_gateway" "my_cgw" {
name = "test"
resource "tencentcloud_vpn_gateway" "example" {
name = "tf-example"
bandwidth = 5
zone = "ap-guangzhou-3"
type = "SSL_CCN"

tags = {
test = "test"
tags = {
createBy = "terraform"
}
}
```

CCN VPN gateway

```hcl
resource "tencentcloud_vpn_gateway" "example" {
name = "tf-example"
bandwidth = 200
type = "CCN"
bgp_asn = 9000

tags = {
createBy = "terraform"
}
}
```

POSTPAID_BY_HOUR VPN gateway

```hcl
resource "tencentcloud_vpn_gateway" "my_cgw" {
name = "test"
resource "tencentcloud_vpn_gateway" "example" {
name = "tf-example"
vpc_id = "vpc-dk8zmwuf"
bandwidth = 5
zone = "ap-guangzhou-3"

tags = {
test = "test"
createBy = "terraform"
}
}
```

PREPAID VPN gateway

```hcl
resource "tencentcloud_vpn_gateway" "my_cgw" {
name = "test"
resource "tencentcloud_vpn_gateway" "example" {
name = "tf-example"
vpc_id = "vpc-dk8zmwuf"
bandwidth = 5
zone = "ap-guangzhou-3"
charge_type = "PREPAID"
prepaid_period = 1

tags = {
test = "test"
createBy = "terraform"
}
}
```
Expand All @@ -82,5 +102,5 @@ Import
VPN gateway can be imported using the id, e.g.

```
$ terraform import tencentcloud_vpn_gateway.foo vpngw-8ccsnclt
$ terraform import tencentcloud_vpn_gateway.example vpngw-8ccsnclt
```

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading