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 ipv6 vApp network creation #1007

Merged
merged 26 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 21 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 .changes/v3.9.0/1007-bug-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Add `prefix_length` field to `resourceVcdVappNetwork` to support creating IPv6 vApp networks [GH-1007]
dataclouder marked this conversation as resolved.
Show resolved Hide resolved
* Deprecate `netmask` in `resourceVcdVappNetwork` [GH-1007]
lvirbalas marked this conversation as resolved.
Show resolved Hide resolved
* Remove `netmask` field's `Default` value which, if not provided before, will result in a Terraform error. The user would then need to add a `"netmask" = "255.255.255.0"` to their existing vApp networks [GH-1007]
lvirbalas marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0
github.com/kr/pretty v0.2.1
github.com/vmware/go-vcloud-director/v2 v2.20.0-alpha.3
github.com/vmware/go-vcloud-director/v2 v2.20.0-alpha.6
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvC
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/vmware/go-vcloud-director/v2 v2.20.0-alpha.3 h1:meqhMTX4DQWOrPA4+3Dcwg2ckTd46LdPiaNmolgrV7A=
github.com/vmware/go-vcloud-director/v2 v2.20.0-alpha.3/go.mod h1:QPxGFgrUcSyzy9IlpwDE4UNT3tsOy2047tJOPEJ4nlw=
github.com/vmware/go-vcloud-director/v2 v2.20.0-alpha.6 h1:S7lFl4zDsmj1Wo1BixRDn28l1Ap47Buy0JPvwP1/dFg=
github.com/vmware/go-vcloud-director/v2 v2.20.0-alpha.6/go.mod h1:QPxGFgrUcSyzy9IlpwDE4UNT3tsOy2047tJOPEJ4nlw=
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
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,
dataclouder marked this conversation as resolved.
Show resolved Hide resolved
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