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

Improved VM network to allow reference vApp routed network #472

Merged
merged 52 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6585559
Add missing file
vbauzys Jul 15, 2019
e247d25
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Jul 15, 2019
cf1e7c2
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Jul 23, 2019
be6790f
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Jul 24, 2019
6f4c5cb
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Jul 25, 2019
c73d402
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Jul 26, 2019
261d142
git push origin master
vbauzys Jul 29, 2019
c431d43
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Aug 1, 2019
414b3bf
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Aug 15, 2019
8b03ab8
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Aug 22, 2019
36c5487
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Sep 3, 2019
db01eec
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Sep 9, 2019
331e895
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Sep 12, 2019
a85d555
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Sep 19, 2019
e1996e3
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Sep 24, 2019
9c63eec
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Sep 27, 2019
5073f6c
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Oct 7, 2019
f0bdef3
git push origin master
vbauzys Oct 23, 2019
24f169d
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Oct 24, 2019
06b36d1
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Oct 24, 2019
30d6a79
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
vbauzys Oct 24, 2019
0ca001f
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Oct 24, 2019
8c9c7c4
git push origin master
vbauzys Oct 25, 2019
4c8d081
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Oct 30, 2019
206bc9f
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Oct 31, 2019
48970bc
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Nov 4, 2019
e7ef092
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Nov 7, 2019
cb5659a
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Nov 8, 2019
1e097fd
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Nov 11, 2019
ae2d955
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Nov 12, 2019
67f9230
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Nov 14, 2019
867b991
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Dec 2, 2019
7ec2137
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Dec 6, 2019
3f3798b
Merge
vbauzys Dec 19, 2019
ec131aa
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Dec 19, 2019
e985ac6
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Jan 14, 2020
7bac78e
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Jan 27, 2020
2b81637
git push origin master
vbauzys Feb 10, 2020
2b82082
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Feb 12, 2020
aa2198d
git push origin master
vbauzys Feb 20, 2020
cb7bb97
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Feb 24, 2020
b6091e4
git push origin master
vbauzys Mar 6, 2020
8717ffa
git push origin masterMerge branch 'master' of github.com:terraform-p…
vbauzys Mar 9, 2020
e1f94cc
Added possibility to reference vapp routed network in VM.network
vbauzys Mar 9, 2020
760ec38
Improvements
vbauzys Mar 10, 2020
403342e
Add changelog
vbauzys Mar 10, 2020
ff428e1
Fix
vbauzys Mar 10, 2020
9b22758
improve comments
vbauzys Mar 10, 2020
edae5b3
improve changelog
vbauzys Mar 10, 2020
4b1fd6b
Removed as don't work with org user and other tests
vbauzys Mar 10, 2020
79b13df
Removed as don't work with org user and other tests
vbauzys Mar 10, 2020
8d66cae
Add test improvement - removed dependency on existing network
vbauzys Mar 10, 2020
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
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_vapp_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestAccVcdVappNetworkDS(t *testing.T) {
"Org": testConfig.VCD.Org,
"VDC": testConfig.VCD.Vdc,
"vappName": "TestAccVcdVappNetworkDS",
"FuncName": "TestVappNetworkDS",
"FuncName": "TestAccVcdVappNetworkDS",
"vappNetworkName": networkName,
"description": description,
"gateway": gateway,
Expand Down
14 changes: 6 additions & 8 deletions vcd/datasource_vcd_vapp_org_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ import (

// TestAccVcdVappOrgNetworkDS tests a vApp org network data source if a vApp is found in the VDC
func TestAccVcdVappOrgNetworkDS(t *testing.T) {
// This test requires access to the vCD before filling templates
// Thus it won't run in the short test
if vcdShortTest {
t.Skip(acceptanceTestsSkipped)
return
}

err := getAvailableNetworks()

if err != nil {
Expand Down Expand Up @@ -52,11 +45,16 @@ func TestAccVcdVappOrgNetworkDS(t *testing.T) {
"natEnabled": natEnabled,
"retainIpMacEnabled": retainIpMacEnabled,
"isFenced": "true",
"FuncName": "TestVappOrgNetworkDS",
"FuncName": "TestAccVcdVappOrgNetworkDS",
}
configText := templateFill(datasourceTestVappOrgNetwork, params)
debugPrintf("#[DEBUG] CONFIGURATION: %s", configText)

if vcdShortTest {
t.Skip(acceptanceTestsSkipped)
return
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down
2 changes: 1 addition & 1 deletion vcd/resource_vcd_vapp_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func resourceVcdVappNetworkImport(d *schema.ResourceData, meta interface{}) ([]*
}

if vappNetworkToImport.Configuration.FenceMode == types.FenceModeBridged ||
(vappNetworkToImport.Configuration.FenceMode == types.FenceModeNAT && vappNetworkToImport.Configuration.Features.DhcpService == nil) {
(vappNetworkToImport.Configuration.FenceMode == types.FenceModeNAT && vappNetworkToImport.Configuration.IPScopes.IPScope[0].IsInherited == true) {
lvirbalas marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for vappNetworkToImport.Configuration.IPScopes to be not nil , and for vappNetworkToImport.Configuration.IPScopes.IPScope to have elements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it always return, but added

return nil, fmt.Errorf("found vApp org network, not vApp network: %s", networkName)
}

Expand Down
2 changes: 1 addition & 1 deletion vcd/resource_vcd_vapp_org_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func resourceVcdVappOrgNetworkImport(d *schema.ResourceData, meta interface{}) (
}

if vappNetworkToImport.Configuration.FenceMode == types.FenceModeIsolated ||
(vappNetworkToImport.Configuration.FenceMode == types.FenceModeNAT && vappNetworkToImport.Configuration.Features.DhcpService != nil) {
(vappNetworkToImport.Configuration.FenceMode == types.FenceModeNAT && vappNetworkToImport.Configuration.IPScopes.IPScope[0].IsInherited == false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for vappNetworkToImport.Configuration.IPScopes to be not nil , and for vappNetworkToImport.Configuration.IPScopes.IPScope to have elements

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wondering what is the impact (or maybe none) of NetworkConfiguration.ParentNetwork

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it always return, but added

return nil, fmt.Errorf("found vApp network, not vApp org network: %s", networkName)
}

Expand Down
2 changes: 1 addition & 1 deletion vcd/resource_vcd_vapp_org_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ resource "vcd_network_routed" "{{.NetworkName}}" {
resource "vcd_vapp_org_network" "{{.resourceName}}" {
org = "{{.Org}}"
vdc = "{{.Vdc}}"
vapp_name = "{{.vappName}}"
vapp_name = vcd_vapp.{{.vappName}}.name
Didainius marked this conversation as resolved.
Show resolved Hide resolved
org_network_name = "{{.orgNetwork}}"

is_fenced = "{{.isFenced}}"
Expand Down
27 changes: 24 additions & 3 deletions vcd/resource_vcd_vapp_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,28 @@ func addVdcNetwork(networkNameToAdd string, vdc *govcd.Vdc, vapp govcd.VApp, vcd
return vdcNetwork, nil
}

// isItVappNetwork checks if it is a genuine vApp network (not only attached to vApp)
// isItVappNetwork checks if it is a vApp network (not vApp Org Network)
func isItVappNetwork(vAppNetworkName string, vapp govcd.VApp) (bool, error) {
vAppNetworkConfig, err := vapp.GetNetworkConfig()
if err != nil {
return false, fmt.Errorf("error getting vApp networks: %s", err)
}

for _, networkConfig := range vAppNetworkConfig.NetworkConfig {
if networkConfig.NetworkName == vAppNetworkName &&
networkConfig.Configuration.FenceMode == types.FenceModeIsolated ||
(networkConfig.Configuration.FenceMode == types.FenceModeNAT &&
networkConfig.Configuration.IPScopes.IPScope[0].IsInherited == false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for networkConfig.Configuration.IPScopes to be not nil , and for networkConfig.Configuration.IPScopes.IPScope to have elements

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and also this check needs an explanation comment, explaining what is the meaning of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it always return, but added

log.Printf("[TRACE] vApp network found: %s", vAppNetworkName)
return true, nil
}
}

return false, fmt.Errorf("configured vApp network isn't found: %s", vAppNetworkName)
}

// isItIsolatedVappNetwork checks if it is a isolated vApp network (not only attached to vApp)
Didainius marked this conversation as resolved.
Show resolved Hide resolved
func isItIsolatedVappNetwork(vAppNetworkName string, vapp govcd.VApp) (bool, error) {

vAppNetworkConfig, err := vapp.GetNetworkConfig()
if err != nil {
Expand Down Expand Up @@ -1565,7 +1585,7 @@ func getVmNicIndexesWithDhcpEnabled(networkConnectionSection *types.NetworkConne
// TODO v3.0 remove this function once 'network_name', 'vapp_network_name', 'ip' are deprecated
func deprecatedNetworksToConfig(network_name, vapp_network_name, ip string, vdc *govcd.Vdc, vapp govcd.VApp, vcdClient *VCDClient) (types.NetworkConnectionSection, error) {
if vapp_network_name != "" {
isVappNetwork, err := isItVappNetwork(vapp_network_name, vapp)
isVappNetwork, err := isItIsolatedVappNetwork(vapp_network_name, vapp)
if err != nil {
return types.NetworkConnectionSection{}, fmt.Errorf("unable to find vApp network %s: %s", vapp_network_name, err)
}
Expand Down Expand Up @@ -1670,7 +1690,8 @@ func readNetworks(d *schema.ResourceData, vm govcd.VM, vapp govcd.VApp) ([]map[s
switch {
case netConfig.NetworkName == types.NoneNetwork:
vAppNetworkTypes[netConfig.NetworkName] = types.NoneNetwork
case netConfig.Configuration.ParentNetwork == nil && netConfig.Configuration.FenceMode == "isolated":
case netConfig.Configuration.FenceMode == types.FenceModeIsolated ||
(netConfig.Configuration.FenceMode == types.FenceModeNAT && netConfig.Configuration.IPScopes.IPScope[0].IsInherited == false):
vAppNetworkTypes[netConfig.NetworkName] = "vapp"
default:
vAppNetworkTypes[netConfig.NetworkName] = "org"
Expand Down
93 changes: 87 additions & 6 deletions vcd/resource_vcd_vapp_vm_multinetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ func TestAccVcdVAppVmMultiNIC(t *testing.T) {
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.6.ip", "192.168.2.51"),
resource.TestCheckResourceAttrSet("vcd_vapp_vm."+netVmName1, "network.6.mac"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.6.adapter_type", "VMXNET3"),

resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.7.name", "vapp-routed-net"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.7.type", "vapp"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.7.is_primary", "false"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.7.ip_allocation_mode", "MANUAL"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.7.ip", "192.168.2.2"),

resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.8.name", "multinic-net"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.8.type", "org"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.8.is_primary", "false"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.8.ip_allocation_mode", "POOL"),

resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.9.name", "multinic-net2"),
Didainius marked this conversation as resolved.
Show resolved Hide resolved
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.9.type", "org"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.9.is_primary", "false"),
resource.TestCheckResourceAttr("vcd_vapp_vm."+netVmName1, "network.9.ip_allocation_mode", "POOL"),
),
},
// Step 1 - update
Expand Down Expand Up @@ -222,7 +238,7 @@ resource "vcd_vapp" "{{.VAppName}}" {
depends_on = ["vcd_network_routed.net", "vcd_network_routed.net2"]
}

resource "vcd_vapp_network" "vappNet" {
resource "vcd_vapp_network" "vappIsolatedNet" {
org = "{{.Org}}"
vdc = "{{.Vdc}}"

Expand All @@ -238,8 +254,6 @@ resource "vcd_vapp_network" "vappNet" {
start_address = "192.168.2.51"
end_address = "192.168.2.100"
}

depends_on = ["vcd_vapp.{{.VAppName}}"]
}

resource "vcd_network_routed" "net" {
Expand All @@ -261,6 +275,35 @@ resource "vcd_network_routed" "net" {
}
}

resource "vcd_vapp_org_network" "vappAttachedNet" {
org = "{{.Org}}"
vdc = "{{.Vdc}}"

vapp_name = vcd_vapp.{{.VAppName}}.name
org_network_name = vcd_network_routed.net.name
}

resource "vcd_vapp_org_network" "vappAttachedRoutedNet2" {
org = "{{.Org}}"
vdc = "{{.Vdc}}"

vapp_name = vcd_vapp.{{.VAppName}}.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This HCL block is not formatted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update

org_network_name = vcd_network_routed.net2.name
is_fenced = true
}

resource "vcd_vapp_network" "vappRoutedNet" {
org = "{{.Org}}"
vdc = "{{.Vdc}}"

name = "vapp-routed-net"
vapp_name = vcd_vapp.{{.VAppName}}.name
gateway = "192.168.2.1"
netmask = "255.255.255.0"
org_network_name = vcd_network_routed.net.name
}


resource "vcd_network_routed" "net2" {
org = "{{.Org}}"
vdc = "{{.Vdc}}"
Expand Down Expand Up @@ -336,11 +379,30 @@ resource "vcd_vapp_vm" "{{.VMName}}" {

network {
type = "vapp"
name = vcd_vapp_network.vappNet.name
name = vcd_vapp_network.vappIsolatedNet.name
ip_allocation_mode = "POOL"
adapter_type = "VMXNET3"
}
}

network {
type = "vapp"
name = vcd_vapp_network.vappRoutedNet.name
ip_allocation_mode = "MANUAL"
ip = "192.168.2.2"
}

network {
type = "org"
name = vcd_vapp_org_network.vappAttachedNet.org_network_name
ip_allocation_mode = "POOL"
}

network {
type = "org"
name = vcd_vapp_org_network.vappAttachedRoutedNet2.org_network_name
ip_allocation_mode = "POOL"
}
}
`

const testAccCheckVcdVAppVmNetworkVmStep1 = testAccCheckVcdVAppVmNetworkShared + `
Expand Down Expand Up @@ -386,6 +448,25 @@ resource "vcd_vapp_vm" "{{.VMName}}" {
is_primary = false
mac = "00:00:00:11:11:11"
}

network {
type = "vapp"
name = vcd_vapp_network.vappRoutedNet.name
lvirbalas marked this conversation as resolved.
Show resolved Hide resolved
ip_allocation_mode = "MANUAL"
ip = "192.168.2.2"
}

network {
type = "org"
name = vcd_vapp_org_network.vappAttachedNet.org_network_name
ip_allocation_mode = "POOL"
}

network {
type = "org"
name = vcd_vapp_org_network.vappAttachedRoutedNet2.org_network_name
ip_allocation_mode = "POOL"
}
}
`

Expand Down Expand Up @@ -426,7 +507,7 @@ resource "vcd_vapp_vm" "{{.VMName}}" {

network {
type = "vapp"
name = vcd_vapp_network.vappNet.name
name = vcd_vapp_network.vappIsolatedNet.name
ip_allocation_mode = "POOL"
is_primary = true
}
Expand Down