Skip to content

Commit

Permalink
Fix ipv6 vApp network creation (#1007)
Browse files Browse the repository at this point in the history
Add prefix length support while creating vapp networks.

---------

Signed-off-by: Adam Jasinski <[email protected]>
  • Loading branch information
adezxc authored Mar 21, 2023
1 parent ee5d7ea commit 64c0827
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .changes/v3.9.0/1007-bug-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Add `prefix_length` field to `vcd_vapp_network` as creating IPv6 vApp networks was not supported due to the lack of a suitable subnet representation (Issue #999) [GH-1007]
* Remove incorrect default value from `vcd_vapp_network` `netmask` field, as it prevents using IPV6 networks. Users of already defined resources need to add a `netmask = "255.255.255.0"` when using Ipv4 [GH-1007]
1 change: 1 addition & 0 deletions .changes/v3.9.0/1007-deprecations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Deprecate `netmask` in `vcd_vapp_network` [GH-1007]
6 changes: 3 additions & 3 deletions vcd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,14 +982,14 @@ func importStateIdOrgCatalogObject(objectName string) resource.ImportStateIdFunc
}

// Used by all entities that depend on Org + VDC + vApp (such as VM, vapp networks)
func importStateIdVappObject(vappName, objectName string) resource.ImportStateIdFunc {
func importStateIdVappObject(vappName, objectName, vdc string) resource.ImportStateIdFunc {
return func(*terraform.State) (string, error) {
if testConfig.VCD.Org == "" || testConfig.VCD.Vdc == "" || vappName == "" || objectName == "" {
if testConfig.VCD.Org == "" || vappName == "" || objectName == "" {
return "", fmt.Errorf("missing information to generate import path")
}
return testConfig.VCD.Org +
ImportSeparator +
testConfig.VCD.Vdc +
vdc +
ImportSeparator +
vappName +
ImportSeparator +
Expand Down
6 changes: 6 additions & 0 deletions vcd/datasource_vcd_vapp_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vcd

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -41,6 +42,11 @@ func datasourceVcdVappNetwork() *schema.Resource {
Computed: true,
Description: "Netmask address for a subnet",
},
"prefix_length": {
Type: schema.TypeString,
Computed: true,
Description: "Subnet prefix length",
},
"gateway": {
Type: schema.TypeString,
Computed: true,
Expand Down
24 changes: 19 additions & 5 deletions vcd/resource_vcd_vapp_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,22 @@ func resourceVcdVappNetwork() *schema.Resource {
Description: "Optional description for the network",
},
"netmask": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "255.255.255.0",
Description: "Netmask address for a subnet. Default is 255.255.255.0",
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Deprecated: "Use prefix_length instead which supports both IPv4 and IPv6",
Description: "Netmask address for a subnet.",
ExactlyOneOf: []string{"prefix_length", "netmask"},
},
"prefix_length": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "Prefix length for a subnet",
ExactlyOneOf: []string{"netmask", "prefix_length"},
ValidateFunc: IsIntAndAtLeast(0),
},
"gateway": {
Type: schema.TypeString,
Expand Down Expand Up @@ -194,6 +205,7 @@ func resourceVappNetworkCreate(ctx context.Context, d *schema.ResourceData, meta
Description: d.Get("description").(string),
Gateway: d.Get("gateway").(string),
NetMask: d.Get("netmask").(string),
SubnetPrefixLength: d.Get("prefix_length").(string),
DNS1: d.Get("dns1").(string),
DNS2: d.Get("dns2").(string),
DNSSuffix: d.Get("dns_suffix").(string),
Expand Down Expand Up @@ -318,6 +330,7 @@ func genericVappNetworkRead(d *schema.ResourceData, meta interface{}, origin str
if config.IPScopes != nil {
dSet(d, "gateway", config.IPScopes.IPScope[0].Gateway)
dSet(d, "netmask", config.IPScopes.IPScope[0].Netmask)
dSet(d, "prefix_length", config.IPScopes.IPScope[0].SubnetPrefixLength)
dSet(d, "dns1", config.IPScopes.IPScope[0].DNS1)
dSet(d, "dns2", config.IPScopes.IPScope[0].DNS2)
dSet(d, "dns_suffix", config.IPScopes.IPScope[0].DNSSuffix)
Expand Down Expand Up @@ -401,6 +414,7 @@ func resourceVappNetworkUpdate(ctx context.Context, d *schema.ResourceData, meta
Description: d.Get("description").(string),
Gateway: d.Get("gateway").(string),
NetMask: d.Get("netmask").(string),
SubnetPrefixLength: d.Get("prefix_length").(string),
DNS1: d.Get("dns1").(string),
DNS2: d.Get("dns2").(string),
DNSSuffix: d.Get("dns_suffix").(string),
Expand Down
Loading

0 comments on commit 64c0827

Please sign in to comment.