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

Improved VM network to allow reference vApp routed network #472

merged 52 commits into from
Mar 10, 2020

Conversation

vbauzys
Copy link
Contributor

@vbauzys vbauzys commented Mar 9, 2020

Ref: https://github.com/terraform-providers/terraform-provider-vcd/issues/471

  • Improved check to allow reference not only isolated vApp network, but routed vApp network too
  • Improved tests
  • Improved import verifying if vApp network type

vbauzys added 30 commits July 15, 2019 15:39
Signed-off-by: Vaidotas Bauzys <[email protected]>
Merge branch 'master' of github.com:terraform-providers/terraform-provider-vcd
Merge branch 'master' of github.com:terraform-providers/terraform-provider-vcd
Merge branch 'master' of github.com:terraform-providers/terraform-provider-vcd
@vbauzys vbauzys self-assigned this Mar 9, 2020
@ghost ghost added the size/M label Mar 9, 2020
@vbauzys vbauzys changed the title Vm vapp netw fix Improved VM network to allow reference vApp routed network Mar 9, 2020
@vbauzys vbauzys requested review from dataclouder, Didainius and lvirbalas and removed request for dataclouder and Didainius March 9, 2020 16:22
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

First pass.

vcd/resource_vcd_vapp_network.go Outdated Show resolved Hide resolved
vcd/resource_vcd_vapp_vm_multinetwork_test.go Show resolved Hide resolved
@lvirbalas
Copy link
Collaborator

I confirm that with this fix I was able to update VM config to add vApp routed network!

  # vcd_vapp_vm.demo_vm_wordpress will be updated in-place
  ~ resource "vcd_vapp_vm" "demo_vm_wordpress" {
       
        # ...

        network {
            adapter_type       = "PCNet32"
            ip                 = "192.168.2.150"
            ip_allocation_mode = "DHCP"
            is_primary         = true
            mac                = "00:50:56:29:00:bb"
            name               = "demo-net-web"
            type               = "org"
        }
        network {
            adapter_type       = "E1000"
            ip                 = "192.168.2.51"
            ip_allocation_mode = "POOL"
            is_primary         = false
            mac                = "00:50:56:29:00:bc"
            name               = "demo-vapp-net-isolated"
            type               = "vapp"
        }
      + network {
          + ip_allocation_mode = "DHCP"
          + name               = "demo-vapp-net-w-org"
          + type               = "vapp"
        }

        override_template_disk {
            bus_number      = 0
            bus_type        = "parallel"
            iops            = 0
            size_in_mb      = 11112
            storage_profile = "*"
            unit_number     = 0
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

data.vcd_vapp.demo_vapp: Refreshing state...
data.vcd_edgegateway.demo-gw: Refreshing state...
vcd_vapp_vm.demo_vm_wordpress: Modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 10s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 20s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 30s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 40s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 50s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 1m0s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 1m10s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 1m20s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 1m30s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 1m40s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 1m50s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 2m0s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 2m10s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 2m20s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 2m30s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 2m40s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 2m50s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Still modifying... [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a, 3m0s elapsed]
vcd_vapp_vm.demo_vm_wordpress: Modifications complete after 3m10s [id=urn:vcloud:vm:bc7b07c4-9013-4b02-8c70-46aaf331693a]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

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

Some changes required

@@ -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) {
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

@@ -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

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

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

Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

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

Good one :) Also changelog needs a note or at least mentioning this PR on the other attachment resources.

vcd/resource_vcd_vapp_network.go Outdated Show resolved Hide resolved
@@ -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
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

vcd/resource_vcd_vapp_org_network_test.go Show resolved Hide resolved
vcd/resource_vcd_vapp_vm_multinetwork_test.go Show resolved Hide resolved
vcd/resource_vcd_vapp_vm.go Outdated Show resolved Hide resolved
if networkConfig.NetworkName == vAppNetworkName &&
networkConfig.Configuration.FenceMode == types.FenceModeIsolated ||
(networkConfig.Configuration.FenceMode == types.FenceModeNAT &&
networkConfig.Configuration.IPScopes.IPScope[0].IsInherited == false) {
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.

Signed-off-by: Vaidotas Bauzys <[email protected]>
@ghost ghost added size/L and removed size/M labels Mar 10, 2020
vbauzys added 2 commits March 10, 2020 07:52
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
CHANGELOG.md Outdated
Comment on lines 30 to 31
* `vcd_vapp_vm` allows to add routed vApp network, not only isolated one. `network.name` can be reference
`vcd_vapp_network.name` [GH-472]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* `vcd_vapp_vm` allows to add routed vApp network, not only isolated one. `network.name` can be reference
`vcd_vapp_network.name` [GH-472]
* `vcd_vapp_vm` allows to add routed vApp network, not only isolated one. `network.name` can reference
`vcd_vapp_network.name` of a vApp network with `org_network_name` set [GH-472]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

vcd/resource_vcd_vapp_org_network.go Outdated Show resolved Hide resolved
vcd/resource_vcd_vapp_org_network.go Show resolved Hide resolved
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

Thank you for a quick & needed addition!

Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

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

LGTM

@vbauzys vbauzys merged commit a1a3384 into vmware:master Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants