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

Add vapp network resource #155

Merged
merged 22 commits into from
Feb 12, 2019
Merged

Add vapp network resource #155

merged 22 commits into from
Feb 12, 2019

Conversation

vbauzys
Copy link
Contributor

@vbauzys vbauzys commented Jan 31, 2019

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

New capability to create vapp network which will be isolated.
Example of usage:

resource "vcd_vapp_network" "terraform1" {
  name = "terraform1"

  vapp_name          = "vApp_system_1"
  gateway            = "192.168.2.1"
  netmask            = "255.255.255.0"
  dns1               = "192.168.2.1"
  dns2               = "192.168.2.2"
  dns_suffix         = "mano.biz"
  guest_vlan_allowed = true

  static_ip_pool {
    start_address = "192.168.2.5"
    end_address   = "192.168.2.10"
  }
}

@spengilley
Copy link
Contributor

I'm waiting on this with relish :)

@vbauzys
Copy link
Contributor Author

vbauzys commented Feb 1, 2019

You may try and provide feedback :)

Signed-off-by: Vaidotas Bauzys <[email protected]>
@lvirbalas
Copy link
Collaborator

The overall implementation looks quite nice. Three open (all related) conceptual questions though:

1.) Should we keep name of the resource vcd_vapp_network or vcd_vapp_network_isolated?

As a reference, we have three types for Org VDC networks:

  • vcd_network_direct
  • vcd_network_isolated
  • vcd_network_routed

2.) How would you suggest modelling (in .tf) a vApp network which is connected to an Org VDC Network?

screen shot 2019-02-01 at 14 51 39

3.) How would you suggest modelling (in .tf) vApp network's services (DHCP, Firewall, NAT, Static Routing)?

screen shot 2019-02-01 at 14 53 56

@vbauzys
Copy link
Contributor Author

vbauzys commented Feb 4, 2019

Answers:

  1. According vApp UI you can have isolated(when create adding new vapp network), natRouted when use connection dropdown and bridged when add exisitng org vdc network. So I recommend to stick with isolated for name.

  2. There are a few possibilities:

  • vcd_vapp_network Resource allows to configure connection with parent network and DHCP, NAT, Firewall, static routing - as such makes it very complex.
  • vcd_vapp_network Resource allows to configure connection with parent network and additional resources or resources configure DHCP, NAT, Firewall, static routing for that network
  1. I suggest to use existing configuration principles which we have already for DHCP, Firewall, NAT in other places

@lvirbalas
Copy link
Collaborator

We came to the following summary. In this PR:

  1. Have a single vcd_vapp_network resource. This implements the isolated vApp network type.

In further PRs:

  1. Add three new parameters to vcd_vapp_network which allow defining a routed vApp network:
resource "vcd_vapp_network" "VAppNetwork" {
  name         = "vapp-net"
  vapp_name = "vapp-test-net"

  # Parameters (all optional) which allow connecting this vApp network to the Org VDC network
  network = “org-vdc-net1” 
  nat_enabled = truefirewall_enabled = true...
}
  1. Add new resources two manage Firewall, NAT and Static Routing at vApp network level:
  • vcd_vapp_dnat
  • vcd_vapp_snat
  • vcd_vapp_firewall_rule
  • vcd_vapp_static_route

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.

After discussing implementation of isolated vs routed vApp network I realised that the PR is missing the DHCP definition. DHCP configuration applies to both routed and isolated networks. We need that here.

For reference, Org VDC Network has it declared as follows:
https://www.terraform.io/docs/providers/vcd/r/network_routed.html

@spengilley
Copy link
Contributor

My use case is that I have an isolated vApp network, but also I want the vApp connected to 2 other vOrg level networks. That doesn't appear possible in the above solution. Will this PR be done in concert with #74 ?

@lvirbalas
Copy link
Collaborator

@spengilley This PR is for vApp isolated network only. Multiple network support will be handled separately, hopefully, as part of #74

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. Will run a test once all the change requests have been addressed

}

resource "vcd_vapp_network" "{{.resourceName}}" {
org = "{{.Org}}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This snippet is not formatted correctly. The properties should be aligned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -238,6 +210,81 @@ func resourceVcdVAppVmCreate(d *schema.ResourceData, meta interface{}) error {
return resourceVcdVAppVmUpdate(d, meta)
}

// Adds existing org VDC network to VM network configuration
func addVdcNetwork(d *schema.ResourceData, vdc govcd.Vdc, vapp govcd.VApp, vcdClient *VCDClient) ([]*types.OrgVDCNetwork, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this function returning?
Either add the definition of the return values in a comment or use named return types to show what we are returning.
For example:

func addVdcNetwork(d *schema.ResourceData, vdc govcd.Vdc, vapp govcd.VApp, vcdClient *VCDClient) (vdcNetworks []*types.OrgVDCNetwork, networkName string, err error) 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("error waiting from task to complete: %+v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

"waiting from task" -> "waiting for task"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


vAppNetworkConfig, err := vapp.GetNetworkConfig()
if err != nil {
return fmt.Errorf("error getting vAPP networks: %#v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

"vAPP" -> "vApp"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("error waiting from task to complete: %+v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

"waiting from task" -> "waiting for task"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

vcd/resource_vcd_vapp_network_test.go Show resolved Hide resolved
} else {

if netName == "" {
return []*types.OrgVDCNetwork{}, "", fmt.Errorf("'network_name' must be valid when adding VM to raw vapp")
Copy link
Contributor

Choose a reason for hiding this comment

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

"vapp" -> "vApp"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

}

if vAppNetworkName != netName {
return []*types.OrgVDCNetwork{}, "", fmt.Errorf("the VDC network '%s' must be assigned to the vApp. Currently the vApp network date is %s", netName, vAppNetworkName)
Copy link
Contributor

Choose a reason for hiding this comment

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

date ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


for _, networkConfig := range vAppNetworkConfig.NetworkConfig {
if networkConfig.NetworkName == vAppNetworkName {
log.Printf("[TRACE] Vapp network found: %s", vAppNetworkName)
Copy link
Contributor

Choose a reason for hiding this comment

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

"Vapp" -> "vApp"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

}
}

return "", fmt.Errorf("configured vAPP network isn't found: %#v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

"vAPP" -> "vApp"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
@@ -238,6 +210,82 @@ func resourceVcdVAppVmCreate(d *schema.ResourceData, meta interface{}) error {
return resourceVcdVAppVmUpdate(d, meta)
}

// Adds existing org VDC network to VM network configuration
// Returns configured OrgVDCNetwork for Vm, networkName, error if any occur
func addVdcNetwork(d *schema.ResourceData, vdc govcd.Vdc, vapp govcd.VApp, vcdClient *VCDClient) (vdcNetworks []*types.OrgVDCNetwork, networkName string, err error) {
Copy link
Contributor

@dn1s dn1s Feb 5, 2019

Choose a reason for hiding this comment

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

I don't agree with having this function added to this code base it should be in underlying go-vcloud-director library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree regarding this and refactor will happen outside this PR. We will review vapp,vm and network functionality which is quite old code and functionality wise.

return vdcNetworks, netName, nil
}

// Adds existing org vApp network to VM network configuration
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here I don't agree with having this function added to this code base it should be in underlying go-vcloud-director library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This functionality in latest commits was changed and just works as check.

@dn1s
Copy link
Contributor

dn1s commented Feb 5, 2019

Let me propose some changes against your repo @vbauzysvmware which in my opinion would be better.

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
@ghost ghost added size/XXL and removed size/XL labels Feb 11, 2019
@vbauzys
Copy link
Contributor Author

vbauzys commented Feb 11, 2019

Add requested DHCP pool capabilities.
Add support for adding network when already exist others.

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.

Ask to update one comment in docs about the version, and then it's time to get this code to the branch and try everything out!

Provides a vCloud Director vApp isolated Network. This can be used to create and delete internal networks for vApps to connect.
This network is not attached to external networks or routers.

Supported in provider *v2.0+*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that we are following semver, this new feature will bump the minor number, so we can point that in the comment above:
Supported in provider *v2.1+*

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

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
@@ -69,6 +69,7 @@ The following arguments are supported:
* `cpus` - (Optional) The number of virtual CPUs to allocate to the vApp
* `initscript` (Optional) A script to be run only on initial boot
* `network_name` - (Optional) Name of the network this VM should connect to
* `vapp_network_name` - ((Optional; *v2.1*)) Name of the vApp network this VM should connect to
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good addition. However, too many brackets and missing plus. Should be:
(Optional; *v2.1+*)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot, fixed that

Signed-off-by: Vaidotas Bauzys <[email protected]>
@vbauzys vbauzys merged commit 5cab61f into vmware:vmware-stash-while-master-pr-open Feb 12, 2019
@jgreenback
Copy link

The below quote mentioned features that would be great to see for those of us vCD Terraform users who rely heavily on routed vapp networks (Enterprise vCD user). Any estimates on when these features will make it into a release?

We came to the following summary. In this PR:

  1. Have a single vcd_vapp_network resource. This implements the isolated vApp network type.

In further PRs:

  1. Add three new parameters to vcd_vapp_network which allow defining a routed vApp network:
resource "vcd_vapp_network" "VAppNetwork" {
  name         = "vapp-net"
  vapp_name = "vapp-test-net"

  # Parameters (all optional) which allow connecting this vApp network to the Org VDC network**
  network = “org-vdc-net1”
  nat_enabled = truefirewall_enabled = true...
}
  1. Add new resources two manage Firewall, NAT and Static Routing at vApp network level:
  • vcd_vapp_dnat
  • vcd_vapp_snat
  • vcd_vapp_firewall_rule
  • vcd_vapp_static_route

@lvirbalas lvirbalas mentioned this pull request Sep 12, 2019
@lvirbalas
Copy link
Collaborator

Hi @jgreenback , I created a separate issue to track this. Don't hesitate to comment there too:
https://github.com/terraform-providers/terraform-provider-vcd/issues/329

It's not planned for the current release, but is in the backlog as such.
BTW, which company are you coming from?

@vbauzys
Copy link
Contributor Author

vbauzys commented Sep 12, 2019

Hi @jgreenback would be nice if you attach on https://github.com/terraform-providers/terraform-provider-vcd/issues/329 some screenshot which resembles your business need :)

@jgreenback
Copy link

Thanks @lvirbalas / @vbauzysvmware for looking at this; I'll work on additional details as well as provide visuals for: #329

@lvirbalas; coming from Varian Medical Systems Inc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants