Skip to content

Commit

Permalink
use terraform_data resource to stabilize test selections
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ctreatma committed Oct 2, 2023
1 parent 77ecefd commit ebb6cce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/acctest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
version:
- stable
terraform:
- '1.1.5'
- '1.5'
steps:

- name: Check out code into the Go module directory
Expand Down
35 changes: 29 additions & 6 deletions equinix/resource_metal_device_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
}
Expand Down

0 comments on commit ebb6cce

Please sign in to comment.