From ebb6cceb8b5394f71a5ae2db6d262668f944b069 Mon Sep 17 00:00:00 2001 From: Charles Treatman Date: Mon, 2 Oct 2023 12:34:41 -0500 Subject: [PATCH] use terraform_data resource to stabilize test selections Occasionally, we see metro or facility selections change as a result of capacity changes on the Metal platform side; for example, step 1 of a test deploys to `da`, but when step 2 runs, there are no longer any available servers in `da`, so a different metro is selected and the test generates an unexpected plan. --- .github/workflows/acctest.yml | 2 +- equinix/resource_metal_device_acc_test.go | 35 +++++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/acctest.yml b/.github/workflows/acctest.yml index 0edef9b49..a644ac1a3 100644 --- a/.github/workflows/acctest.yml +++ b/.github/workflows/acctest.yml @@ -71,7 +71,7 @@ jobs: version: - stable terraform: - - '1.1.5' + - '1.5' steps: - name: Check out code into the Go module directory diff --git a/equinix/resource_metal_device_acc_test.go b/equinix/resource_metal_device_acc_test.go index c12d5df59..87adc641d 100644 --- a/equinix/resource_metal_device_acc_test.go +++ b/equinix/resource_metal_device_acc_test.go @@ -118,6 +118,14 @@ resource "random_integer" "plan_idx" { max = length(data.equinix_metal_plans.test.plans) - 1 } +resource "terraform_data" "plan" { + input = data.equinix_metal_plans.test.plans[random_integer.plan_idx.result] + + lifecycle { + ignore_changes = ["input"] + } +} + // Select a metal facility randomly and lock it in // so that we don't pick a different one for // every subsequent terraform plan @@ -126,6 +134,14 @@ resource "random_integer" "facility_idx" { max = length(local.facilities) - 1 } +resource "terraform_data" "facility" { + input = local.facilities[random_integer.facility_idx.result] + + lifecycle { + ignore_changes = ["input"] + } +} + // Select a metal metro randomly and lock it in // so that we don't pick a different one for // every subsequent terraform plan @@ -134,18 +150,25 @@ resource "random_integer" "metro_idx" { max = length(local.metros) - 1 } +resource "terraform_data" "metro" { + input = local.metros[random_integer.metro_idx.result] + + lifecycle { + ignore_changes = ["input"] + } +} + locals { // Select a random plan - selected_plan = data.equinix_metal_plans.test.plans[random_integer.plan_idx.result] - plan = local.selected_plan.slug + plan = terraform_data.plan.output.slug // Select a random facility from the facilities in which the selected plan is available, excluding decommed facilities - facilities = sort(tolist(setsubtract(local.selected_plan.available_in, ["nrt1", "dfw2", "ewr1", "ams1", "sjc1", "ld7", "sy4", "ny6"]))) - facility = local.facilities[random_integer.facility_idx.result] + facilities = sort(tolist(setsubtract(terraform_data.plan.output.available_in, ["nrt1", "dfw2", "ewr1", "ams1", "sjc1", "ld7", "sy4", "ny6"]))) + facility = terraform_data.facility.output // Select a random metro from the metros in which the selected plan is available - metros = sort(tolist(local.selected_plan.available_in_metros)) - metro = local.metros[random_integer.metro_idx.result] + metros = sort(tolist(terraform_data.plan.output.available_in_metros)) + metro = terraform_data.metro.output os = [%s][0] }