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

NSX-T Edge Gateway automatic IP assignment #991

Merged
merged 37 commits into from
Mar 22, 2023
Merged

Conversation

Didainius
Copy link
Collaborator

@Didainius Didainius commented Feb 1, 2023

Closes #743

This PR adds support for 2 new different IP allocation modes in addition to the already existing manual IP range allocation using subnet blocks. Sadly, it was not possible to make all settings available in a single subnet block, because of Terraform schema limitations which are not in control by provider developers. (the main problem with TypeSet blocks is that they would produce inconsistent plan for allocation ranges, when an allocated IP count is increased)

The new modes are:

  • subnet_with_total_ip_count + total_allocated_ip_count -> automatic IP allocation in any of the defined subnets (up to total_allocated_ip_count)
resource "vcd_nsxt_edgegateway" "nsxt-edge" {
  org  = "cloud"
  vdc  = "nsxt-vdc-cloud"
  name = "edge"

  external_network_id = vcd_external_network_v2.ext-net-nsxt.id

  total_allocated_ip_count = 100
  subnet_with_total_ip_count {
    gateway       = tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[0].gateway
    prefix_length = tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[0].prefix_length
    primary_ip    = tolist(tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[0].static_ip_pool)[0].start_address
  }

  subnet_with_total_ip_count {
    gateway       = tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[1].gateway
    prefix_length = tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[1].prefix_length
  }
}

Note. Due to API limitations, the behavior of this function is different when allocating IPs and when deallocating. When allocating - it is sufficient to just use QuickAddAllocatedIPCount field, while deallocation requires manual structure adjustment

  • subnet_with_ip_count -> automatic IP allocation for a per subnet case
resource "vcd_nsxt_edgegateway" "nsxt-edge" {
  org  = "cloud"
  vdc  = "nsxt-vdc-cloud"
  name = "edge"

  external_network_id = vcd_external_network_v2.ext-net-nsxt.id

  subnet_with_ip_count {
    gateway       = tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[0].gateway
    prefix_length = tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[0].prefix_length

    primary_ip         = tolist(tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[0].static_ip_pool)[0].end_address
    allocated_ip_count = "9"
  }

  subnet_with_ip_count {
    gateway            = tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[1].gateway
    prefix_length      = tolist(vcd_external_network_v2.ext-net-nsxt.ip_scope)[1].prefix_length
    allocated_ip_count = "10"
  }
}

Additionally, this PR will add new attributes:

  • used_ip_count - returns the number of IPs that are used by the services in this Edge Gateway
  • unused_ip_count - returns the number of IPs that are allocated, but not yet used by any service in the Edge Gateway
  • total_allocated_ip_count (must be used for subnet_with_total_ip_count however, it will return computed values in other cases as well)

Testing

  • Acceptance tests with tags nsxt and gateway passed on 10.3.0, 10.4.0, 10.4.1.
  • Binary tests with tag gateway passed on 10.4.1
  • Upgrade tests with tag gateway passed on 10.4.1 (also added vcd.ResourceSchema-vcd_nsxt_edgegateway.tf to skip)

Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
@Didainius Didainius force-pushed the 743-is branch 2 times, most recently from a5689df to 9d91bad Compare February 3, 2023 10:35
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
@Didainius Didainius changed the title WIP: NSX-T Edge Gateway automatic IP assignment NSX-T Edge Gateway automatic IP assignment Feb 8, 2023
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
@Didainius Didainius marked this pull request as ready for review February 9, 2023 07:21
@Didainius Didainius requested a review from adezxc February 9, 2023 07:21
@Didainius Didainius marked this pull request as ready for review February 15, 2023 07:58
Copy link
Collaborator

@adambarreiro adambarreiro left a comment

Choose a reason for hiding this comment

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

First scan

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

This PR slipped my attention, sorry... My main question is how could we clarify the auto_subnet vs. auto_allocated_subnet concepts (comment in-line).

website/docs/r/nsxt_edgegateway.html.markdown Outdated Show resolved Hide resolved
website/docs/r/nsxt_edgegateway.html.markdown Outdated Show resolved Hide resolved
Signed-off-by: Dainius Serplis <[email protected]>
…ted_subnet' -> 'subnet_with_ip_count'

Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Copy link

@adezxc adezxc left a comment

Choose a reason for hiding this comment

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

Thanks for this PR!

Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
@Didainius Didainius merged commit 493069c into vmware:main Mar 22, 2023
@Didainius Didainius deleted the 743-is branch March 22, 2023 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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