Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

expose metal_port.vxlan_ids as computed attribute and alternative to vlan_ids #177

Merged
merged 6 commits into from
Sep 29, 2021

Conversation

displague
Copy link
Member

@displague displague commented Aug 18, 2021

I'm using this branch to identify shortcomings of the metal_port as discovered in real integration work.

Some of the changes proposed here may be unnecessary.

  • add metal_port.vxlan_ids
    It may be helpful to refer to vxlan_ids because the user can know these in advance (they are user-configurable). These ids can be sent to userdata to get OS networking configured properly. Depending on the UUID makes need for more boilerplate.
    I was converting a vlan_attachment resource to metal_port and accidentally used the vxlan_id field.
    metal_port.vlan_ids initially accepted the "1000" value, but on a refresh, Terraform wanted to reset this to the UUID.

    Terraform detected the following changes made outside of Terraform since the last "terraform apply":
    
    # module.backend.metal_port.port[0] has been changed
    ~ resource "metal_port" "port" {
         id                = "d95fe575-c7f1-4d07-98f3-a3fa2c604481"
         name              = "bond0"
       ~ vlan_ids          = [
           - "1000",
           - "1001",
           + "2fb1a61d-70b8-47c1-b7bd-81a7d99b8460",
           + "84dbfaea-53ef-4476-9ed7-8ac97e6a2be0",
         ]
         # (6 unchanged attributes hidden)
     }
    

    Will it be problematic to have a computed vlan_ids and vxlan_ids? Does this prevent new settings from taking effect or does this prevent unwanted VLANs from being detected and detached by Terraform?

@displague displague marked this pull request as ready for review September 7, 2021 13:27
@displague
Copy link
Member Author

This PR needs tests

@t0mk
Copy link
Contributor

t0mk commented Sep 27, 2021

Note to myself, check error

panic: Invalid address to set: []string{"vxlan_ids"}

home/runner/work/terraform-provider-metal/terraform-provider-metal/metal/resource_metal_port.go:194

EDIT: fixed, it was because vxlan_ids were missing frmo metal_port datasource

@displague
Copy link
Member Author

In ac70dc0:

=== RUN   TestAccMetalPort_HybridBondedVxlan
2021/09/28 08:42:18 [DEBUG] POST https://api.equinix.com/metal/v1/projects
2021/09/28 08:42:18 [DEBUG] GET https://api.equinix.com/metal/v1/projects/45863fd5-b767-4d9b-b1e4-e4eb643c651f
2021/09/28 08:42:18 [DEBUG] GET https://api.equinix.com/metal/v1/projects/45863fd5-b767-4d9b-b1e4-e4eb643c651f/bgp-config
2021/09/28 08:42:18 [DEBUG] POST https://api.equinix.com/metal/v1/projects/45863fd5-b767-4d9b-b1e4-e4eb643c651f/virtual-networks
2021/09/28 08:42:18 [DEBUG] POST https://api.equinix.com/metal/v1/projects/45863fd5-b767-4d9b-b1e4-e4eb643c651f/virtual-networks
2021/09/28 08:42:18 [DEBUG] POST https://api.equinix.com/metal/v1/projects/45863fd5-b767-4d9b-b1e4-e4eb643c651f/devices
2021/09/28 08:42:18 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/26773120-b1ff-4b2d-9bb2-3b4c231f0ad9?include=assigned_to
2021/09/28 08:42:18 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/b7fb5de0-2dea-47a6-9bed-1baa78a50a86?include=assigned_to
2021/09/28 08:42:31 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:42:35 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:42:41 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:42:51 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:43:01 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:43:11 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:43:22 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:43:33 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:43:43 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:43:53 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:44:04 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:44:14 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:44:24 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cfacility
2021/09/28 08:44:25 [DEBUG] GET https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40?include=project%2Cmetro%2Cfacility%2Chardware_reservation
2021/09/28 08:44:26 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5?include=native_virtual_network%2Cvirtual_networks
2021/09/28 08:44:26 [DEBUG] POST https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5/vlan-assignments/batches
2021/09/28 08:44:32 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5/vlan-assignments/batches/7a40425d-93ee-4539-b334-fa9d100a2dae
2021/09/28 08:44:37 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5/vlan-assignments/batches/7a40425d-93ee-4539-b334-fa9d100a2dae
2021/09/28 08:44:42 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5/vlan-assignments/batches/7a40425d-93ee-4539-b334-fa9d100a2dae
2021/09/28 08:44:42 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5?include=native_virtual_network%2Cvirtual_networks
    resource_metal_port_test.go:155: Step 1/5 error: Check failed: Check 7/8 error: metal_port.bond0: Attribute 'vxlan_ids.0' expected "1001", got "1000"
2021/09/28 08:44:43 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5?include=native_virtual_network%2Cvirtual_networks
2021/09/28 08:44:43 [DEBUG] POST https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5/vlan-assignments/batches
2021/09/28 08:44:48 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5/vlan-assignments/batches/3f1d713b-7fd7-462d-83ef-cede43b0c57a
2021/09/28 08:44:53 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5/vlan-assignments/batches/3f1d713b-7fd7-462d-83ef-cede43b0c57a
2021/09/28 08:44:58 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5/vlan-assignments/batches/3f1d713b-7fd7-462d-83ef-cede43b0c57a
2021/09/28 08:44:58 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/b7fb5de0-2dea-47a6-9bed-1baa78a50a86?include=instances%2Cinstances.network_ports.virtual_networks%2Cinternet_gateway
2021/09/28 08:44:58 [DEBUG] GET https://api.equinix.com/metal/v1/virtual-networks/26773120-b1ff-4b2d-9bb2-3b4c231f0ad9?include=instances%2Cinstances.network_ports.virtual_networks%2Cinternet_gateway
2021/09/28 08:44:58 [DEBUG] DELETE https://api.equinix.com/metal/v1/devices/c9ebe6f5-2ed1-41bf-94e0-4e5c89f61d40
2021/09/28 08:44:59 [DEBUG] DELETE https://api.equinix.com/metal/v1/virtual-networks/b7fb5de0-2dea-47a6-9bed-1baa78a50a86
2021/09/28 08:44:59 [DEBUG] DELETE https://api.equinix.com/metal/v1/virtual-networks/26773120-b1ff-4b2d-9bb2-3b4c231f0ad9
2021/09/28 08:45:01 [DEBUG] DELETE https://api.equinix.com/metal/v1/projects/45863fd5-b767-4d9b-b1e4-e4eb643c651f
2021/09/28 08:45:01 [DEBUG] GET https://api.equinix.com/metal/v1/ports/8965420c-5188-4443-b7ee-3369414416d5
    testing_new.go:70: Error running post-test destroy, there may be dangling resources: Error getting port 8965420c-5188-4443-b7ee-3369414416d5 during destroy check
--- FAIL: TestAccMetalPort_HybridBondedVxlan (165.37s)

@displague
Copy link
Member Author

Is the API sorting the vlans in a way that we don't expect? Maybe that's not a real problem and the tests and documentation should reflect it?

@displague
Copy link
Member Author

On the other hand, maybe we should just reorder the indexes on these tests: (0 -> test1, 1 -> test2)

					resource.TestCheckResourceAttrPair("metal_port.bond0", "vxlan_ids.0",
						"metal_vlan.test2", "vxlan"),
					resource.TestCheckResourceAttrPair("metal_port.bond0", "vxlan_ids.1",
						"metal_vlan.test1", "vxlan"),

@t0mk
Copy link
Contributor

t0mk commented Sep 28, 2021

@displague the problem was with the destroy check GETting a port in process of removal, returning 403 instead of 404. I added additional test step which removes the vlans first.

I changed the vxland_ids check to

	Check: resource.ComposeTestCheckFunc(
		resource.TestCheckResourceAttr("metal_port.bond0", "vxlan_ids.#", "2"),
		resource.TestMatchResourceAttr("metal_port.bond0", "vxlan_ids.0",
			regexp.MustCompile("1001|1002")),
		resource.TestMatchResourceAttr("metal_port.bond0", "vxlan_ids.1",
			regexp.MustCompile("1001|1002")),
		),

.. because I think the test should be independent on the order of the VLANs in the API resource.

@t0mk
Copy link
Contributor

t0mk commented Sep 28, 2021

@displague this is ready for review

@displague displague merged commit 2d7fb2c into main Sep 29, 2021
@displague displague deleted the port_vxlan_ids branch September 29, 2021 12:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants