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

Enhance EdgeGateway datasource by returning interface information. #351

Closed
jamiejarmstrong opened this issue Oct 17, 2019 · 1 comment
Closed
Assignees

Comments

@jamiejarmstrong
Copy link

jamiejarmstrong commented Oct 17, 2019

Version:
2.5

Scenario
In our environment when a new Edge Gateway is attached to an External Network, the subnet info (netmask, ip, gateway) for the Edge's uplink interface is assigned at random after creation.

Problem:
Currently, the Edge Gateway data source does not return interface(s) subnet information beyond the "uplink" name (which is returned in the "external_networks" list). This prevents us being able to create new D/SNAT rules for an Edge as the IP of the uplink must be known, and cannot be retrieved after EGW creation using the data source or resource.

Proposed Solution:
Add new elements to datasource_vcd_edgegateway.go Schema that contain netmask, ip, gateway for each interface on the EGW. These values are available in the existing SubnetParticipation type, and just need to be mapped to a new element on the data source. I'm not that familiar with the inner workings of the provider yet, so I'm not sure if this change would/could also apply to the resource itself, as shown below I'm just using the data source for now. A nested set/map of each interface's subnet info would be ideal, however simply adding new lists for external_netmask, external_ip, external_gateway would suffice as we could use the index of external_networks to lookup the corresponding subnet info.

Current Workaround
I'm currently able to achieve what I want by duplicating the "external_networks" element, and its associated logic; I tried a more robust method but struggled with the XML Types and nesting maps/sets in Go (I'm fairly new to both!).

resource_vcd_edgegateway.go - line 323

	var networks []string
	var external_ips []string //My new string array
	for _, net := range egw.EdgeGateway.Configuration.GatewayInterfaces.GatewayInterface {
		if net.InterfaceType == "uplink" {
			networks = append(networks, net.Network.Name)
			gateways[net.SubnetParticipation.Gateway] = net.Network.Name
			external_ips = append(external_ips, net.SubnetParticipation.IPAddress) //Add gateway interface IP to array
		}
	}
	err = d.Set("external_networks", networks)
	err = d.Set("external_ips", external_ips)` //set value on object

Schema addition in datasource_vcd_edgegateway.go

"external_ips": &schema.Schema{
				Type:        schema.TypeList,
				Computed:	true,
				Description: "A list of external ips used by the edge gateway",
				Elem: &schema.Schema{
					Type: schema.TypeString,
				},
			},

I can then retrieve the external_ip of a gateway resource using the below:

data "vcd_edgegateway" "mygw" {
    name = "Edge_LAN1"
    org = "TEST"
    vdc = "TESTVDC"
}

output "test1" {
  value = data.vcd_edgegateway.mygw.external_ips
}
@jamiejarmstrong jamiejarmstrong changed the title Enhance EdgeGateway data resource by returning interface information. Enhance EdgeGateway dataource by returning interface information. Oct 17, 2019
@jamiejarmstrong jamiejarmstrong changed the title Enhance EdgeGateway dataource by returning interface information. Enhance EdgeGateway datasource by returning interface information. Oct 17, 2019
@jamiejarmstrong
Copy link
Author

Duplicate of #308

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