Skip to content

Commit

Permalink
feat(vpn): VPN gateway flavor field supports updates (#5819)
Browse files Browse the repository at this point in the history
  • Loading branch information
profoundwu authored Nov 7, 2024
1 parent 4880202 commit 7fb837a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
11 changes: 5 additions & 6 deletions docs/resources/vpn_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,16 @@ The following arguments are supported:

Changing this parameter will create a new resource.

* `flavor` - (Optional, String, ForceNew) The flavor of the VPN gateway.
The value can be **Basic**, **Professional1**, **Professional2** and **GM**. Defaults to **Professional1**.
* `flavor` - (Optional, String) The flavor of the VPN gateway.
+ The value at creation can be **Basic**, **Professional1**, **Professional2** or **GM**. Defaults to **Professional1**.
+ The value during update can be **Basic**, **Professional1** or **Professional2**.

Changing this parameter will create a new resource.

* `attachment_type` - (Optional, String, ForceNew) The attachment type. The value can be **vpc** and **er**.
* `attachment_type` - (Optional, String, ForceNew) The attachment type. The value can be **vpc** or **er**.
Defaults to **vpc**.

Changing this parameter will create a new resource.

* `network_type` - (Optional, String, ForceNew) The network type. The value can be **public** and **private**.
* `network_type` - (Optional, String, ForceNew) The network type. The value can be **public** or **private**.
Defaults to **public**.

Changing this parameter will create a new resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func TestAccGateway_basic(t *testing.T) {
resource.TestCheckResourceAttr(rName, "name", name+"-update"),
resource.TestCheckResourceAttrPair(rName, "local_subnets.0", "huaweicloud_vpc_subnet.test", "cidr"),
resource.TestCheckResourceAttr(rName, "local_subnets.1", "192.168.2.0/24"),
resource.TestCheckResourceAttr(rName, "flavor", "Professional2"),
resource.TestCheckResourceAttrPair(rName, "availability_zones.0",
"data.huaweicloud_vpn_gateway_availability_zones.test", "names.0"),
resource.TestCheckResourceAttrPair(rName, "availability_zones.1",
"data.huaweicloud_vpn_gateway_availability_zones.test", "names.1"),
resource.TestCheckResourceAttr(rName, "tags.key", "val"),
resource.TestCheckResourceAttr(rName, "tags.foo", "bar-update"),
),
Expand Down Expand Up @@ -478,6 +483,8 @@ resource "huaweicloud_vpn_gateway" "test" {
vpc_id = huaweicloud_vpc.test.id
local_subnets = [huaweicloud_vpc_subnet.test.cidr, "192.168.2.0/24"]
connect_subnet = huaweicloud_vpc_subnet.test.id
flavor = "Professional2"
availability_zones = [
data.huaweicloud_vpn_gateway_availability_zones.test.names[0],
data.huaweicloud_vpn_gateway_availability_zones.test.names[1]
Expand Down
30 changes: 26 additions & 4 deletions huaweicloud/services/vpn/resource_huaweicloud_vpn_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
// @API VPN DELETE /v5/{project_id}/vpn-gateways/{id}
// @API VPN POST /v5/{project_id}/{resource_type}/{resource_id}/tags/create
// @API VPN POST /v5/{project_id}/{resource_type}/{resource_id}/tags/delete
// @API VPN POST /v5/{project_id}/vpn-gateways/{vgw_id}/update-specification
func ResourceGateway() *schema.Resource {
return &schema.Resource{
CreateContext: resourceGatewayCreate,
Expand Down Expand Up @@ -71,12 +72,8 @@ func ResourceGateway() *schema.Resource {
"flavor": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Description: `The flavor of the VPN gateway.`,
ValidateFunc: validation.StringInSlice([]string{
"V1G", "V300", "Basic", "Professional1", "Professional2", "GM",
}, false),
},
"attachment_type": {
Type: schema.TypeString,
Expand Down Expand Up @@ -838,6 +835,7 @@ func resourceGatewayUpdate(ctx context.Context, d *schema.ResourceData, meta int
var (
updateGatewayHttpUrl = "v5/{project_id}/vpn-gateways/{id}"
updateGatewayCertificateHttpUrl = "v5/{project_id}/vpn-gateways/{gateway_id}/certificate/{certificate_id}"
updateFlavorHttpUrl = "v5/{project_id}/vpn-gateways/{vgw_id}/update-specification"
updateGatewayProduct = "vpn"
)
updateGatewayClient, err := cfg.NewServiceClient(updateGatewayProduct, region)
Expand Down Expand Up @@ -922,6 +920,30 @@ func resourceGatewayUpdate(ctx context.Context, d *schema.ResourceData, meta int
return diag.Errorf("error updating tags of VPN gateway (%s): %s", d.Id(), tagErr)
}
}

if d.HasChange("flavor") {
updateFlavorPath := updateGatewayClient.Endpoint + updateFlavorHttpUrl
updateFlavorPath = strings.ReplaceAll(updateFlavorPath, "{project_id}", updateGatewayClient.ProjectID)
updateFlavorPath = strings.ReplaceAll(updateFlavorPath, "{vgw_id}", gatewayId)

updateGatewayOpt := golangsdk.RequestOpts{
KeepResponseBody: true,
}
updateGatewayOpt.JSONBody = map[string]interface{}{
"vpn_gateway": map[string]interface{}{
"flavor": d.Get("flavor"),
},
}
_, err = updateGatewayClient.Request("POST", updateFlavorPath, &updateGatewayOpt)
if err != nil {
return diag.Errorf("error updating VPN gateway flavor: %s", err)
}
err = updateGatewayWaitingForStateCompleted(ctx, d, meta, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return diag.Errorf("error waiting for updating VPN gateway (%s) flavor to complete: %s", gatewayId, err)
}
}

return resourceGatewayRead(ctx, d, meta)
}

Expand Down

0 comments on commit 7fb837a

Please sign in to comment.