terraform-provider-vcd icon indicating copy to clipboard operation
terraform-provider-vcd copied to clipboard

Add support auto assign ip to tier-1 from ip pool of tier-0

Open work423 opened this issue 3 years ago • 3 comments

For example we want to create nsx-t edge( tier1) and automatically assign free ip for this edge from pool of tier-0 Current version of provider requires at least start_address and end_address.

resource "vcd_nsxt_edgegateway" "nsxt-edge" { org = "my-org" vdc = "nsxt-vdc" name = "nsxt-edge" description = "Description"

external_network_id = data.vcd_external_network_v2.nsxt-ext-net.id

subnet { gateway = "10.150.191.253" prefix_length = "19" # primary_ip should fall into defined "allocated_ips" range as otherwise # next apply will report additional range of "allocated_ips" with the range # containing single "primary_ip" and will cause non-empty plan. primary_ip = "10.150.160.137" allocated_ips { start_address = "10.150.160.137" end_address = "10.150.160.138" } } }

work423 avatar Nov 17 '21 11:11 work423

+1 this issue. I have previous used the vcd_edgegateway resource which currently auto assigns from the network pool.

I appreciate that might take some time but if anyone could offer solution in the mean time to work out which IP's are free I would appreciate it. the vcd_external_network_v2 data sources exposes the pool but not what's allocated.

+1

Would be nice to see that. Also, it should be possible to simply add an ip_count key, that defines how many ips are configured as suballocation in this edge (first one should be the primary). On creation you can simply call the quick allocation api call. On Update count the allocated ips, if the ip_count is higher quick allocate the difference. Depends on if the quick allocation is implemented in govcloud.

MarRio81 avatar Aug 10 '22 17:08 MarRio81

Would be nice to see that. Also, it should be possible to simply add an ip_count key, that defines how many ips are configured as suballocation in this edge (first one should be the primary).

Yep. That seems to be the only possible way in Terraform

Didainius avatar Aug 11 '22 06:08 Didainius

Hello @work423 , @username-is-already-taken2 , @MarRio81 ,

I hope this is still the desired thing and I am going to work on it now. The API is a bit complicated to properly handle situation, but I am looking at UI capabilities and trying to adapt it to HCL at first. I have come up with a few use cases to look at.

This is a very early mockup, but I am putting it here so that any responses can be considered while I work on it.

Note. Terraform schema has limitations and I have yet to confirm if exactly such a structure is achievable or it has to be designed differently.

In addition to currently existing IP allocation model (where IP ranges must be specified), here are a few more I have come up with:

Define total allocated IP count number without explicitly dealing with IPs

resource "vcd_nsxt_edgegateway" "nsxt-edge" {
  org         = "my-org"
  vdc         = "nsxt-vdc"
  name        = "nsxt-edge"
  description = "Description"

  external_network_id = data.vcd_external_network_v2.nsxt-ext-net.id

  # "global" parameter for all subnets, mimicking behavior of UI when choosing - "Quick IP Allocation -> Assign IPs from Any Subnet -> ip count"
  # Note. Terraform is a desired state configuration tool therefore there is a difference
  # * UI inputs "additional IP addresses" (adds in addition to already allocated ones). [Total IP count = allocated before operation + additional IP address count]
  # * Terraform declares _TOTAL_ allocated IP count
  allocated_ip_count = 10
  subnet {
    gateway       = "10.10.10.1"
    prefix_length = "24"
  }

  subnet {
    gateway       = "20.10.10.1"
    prefix_length = "24"
  }
}

Define total allocated IP count number without explicitly dealing with IPs, except - explicitly specifying primary_ip

resource "vcd_nsxt_edgegateway" "nsxt-edge" {
  org         = "my-org"
  vdc         = "nsxt-vdc"
  name        = "nsxt-edge"
  description = "Description"

  external_network_id = data.vcd_external_network_v2.nsxt-ext-net.id

  # "global" parameter for all subnets, mimicking behavior of UI when choosing - "Quick IP Allocation -> Assign IPs from Any Subnet -> ip count"
  # Note. Terraform is a desired state configuration tool therefore there is a difference
  # * UI inputs "additional IP addresses" (adds in addition to already allocated ones). [Total IP count = allocated before operation + additional IP address count]
  # * Terraform declares _TOTAL_ allocated IP count
  allocated_ip_count = 10 
  subnet {
    gateway       = "10.10.10.1"
    prefix_length = "24"
    primary_ip = "10.10.10.2"
  }

  subnet {
    gateway       = "20.10.10.1"
    prefix_length = "24"
  }
}

Handle IP allocation for each subnet

resource "vcd_nsxt_edgegateway" "nsxt-edge" {
  org         = "my-org"
  vdc         = "nsxt-vdc"
  name        = "nsxt-edge"
  description = "Description"

  external_network_id = data.vcd_external_network_v2.nsxt-ext-net.id

  # This subnet can be defined with an already existing configuration
  subnet {
    gateway       = "10.10.10.1"
    prefix_length = "24"
    primary_ip = "10.150.160.137"
    
    allocated_ips {
      start_address = "10.10.10.10"
      end_address   = "10.10.10.20"
    }
    
    allocated_ips {
      start_address = "10.10.10.30"
      end_address   = "10.10.10.40"
    }
  }

  # This would give some "automatism" for the operation
  subnet {
    gateway       = "20.0.0.1"
    prefix_length = "24"
    # 
    allocated_ip_count = 10
  }
}

Any feedback is appreciated while I progress on this functionality

Didainius avatar Dec 06 '22 13:12 Didainius

Sadly, the above configurations are not possible due to Terraform schema limitations and the current model will add two new configuration blocks. These options and reasons are in the description of #991.

Didainius avatar Feb 08 '23 13:02 Didainius

@work423 , @username-is-already-taken2 , @MarRio81, As I noted above - the original syntax did not work due to Terraform schema limitations, but schema options are defined in #991. I'd appreciate if you can evaluate if it makes sense for you (and possibly test the provider).

Didainius avatar Feb 09 '23 07:02 Didainius

@work423 , @username-is-already-taken2 , @MarRio81, I have implemented the functionality and it is now in main - would be cool to have any feedback before we release 3.9.0 if you have it.

Thanks

Didainius avatar Mar 22 '23 14:03 Didainius