From 0ecc8e2d64040ac3b64d35e153a7c382e6dd80a9 Mon Sep 17 00:00:00 2001 From: Charles Treatman Date: Fri, 10 Jan 2025 13:55:31 -0600 Subject: [PATCH] chore(ci): remove tests that cover or rely on creating Metal orgs (#838) As part of the end-of-sale for Equinix Metal, creation of new Equinix Metal organizations has been disabled across the board. Due to that change, tests that use the `equinix_metal_organization` resource are guaranteed to fail. This PR removes all impacted tests. --- .../metal/organization/datasource_test.go | 72 ------ .../metal/organization/resource_test.go | 213 ------------------ .../organization_member/resource_test.go | 158 ------------- .../resources/metal/project/resource_test.go | 45 ---- 4 files changed, 488 deletions(-) delete mode 100644 internal/resources/metal/organization/datasource_test.go delete mode 100644 internal/resources/metal/organization/resource_test.go delete mode 100644 internal/resources/metal/organization_member/resource_test.go diff --git a/internal/resources/metal/organization/datasource_test.go b/internal/resources/metal/organization/datasource_test.go deleted file mode 100644 index 99c7f3ea8..000000000 --- a/internal/resources/metal/organization/datasource_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package organization_test - -import ( - "fmt" - "testing" - - "github.com/equinix/terraform-provider-equinix/internal/acceptance" - "github.com/hashicorp/terraform-plugin-testing/helper/acctest" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/packethost/packngo" -) - -func TestAccDataSourceOrganizations_basic(t *testing.T) { - var org packngo.Organization - rInt := acctest.RandInt() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.TestAccPreCheckMetal(t); acceptance.TestAccPreCheckProviderConfigured(t) }, - ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, - CheckDestroy: testAccMetalOrganizationCheckDestroyed, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceMetalOrganizationConfig_basic(rInt), - Check: resource.ComposeTestCheckFunc( - testAccMetalOrganizationExists("equinix_metal_organization.test", &org), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "name", - fmt.Sprintf("tfacc-datasource-org-%d", rInt)), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "description", "quux"), - resource.TestCheckResourceAttr( - "data.equinix_metal_organization.test", "name", - fmt.Sprintf("tfacc-datasource-org-%d", rInt)), - resource.TestCheckResourceAttrPair( - "equinix_metal_organization.test", "address.0.address", - "data.equinix_metal_organization.test", "address.0.address", - ), - resource.TestCheckResourceAttrPair( - "equinix_metal_organization.test", "address.0.city", - "data.equinix_metal_organization.test", "address.0.city", - ), - resource.TestCheckResourceAttrPair( - "equinix_metal_organization.test", "address.0.country", - "data.equinix_metal_organization.test", "address.0.country", - ), - resource.TestCheckResourceAttrPair( - "equinix_metal_organization.test", "address.0.zip_code", - "data.equinix_metal_organization.test", "address.0.zip_code", - ), - ), - }, - }, - }) -} - -func testAccDataSourceMetalOrganizationConfig_basic(r int) string { - return fmt.Sprintf(` -resource "equinix_metal_organization" "test" { - name = "tfacc-datasource-org-%d" - description = "quux" - address { - address = "tfacc org street" - city = "london" - zip_code = "12345" - country = "GB" - } -} - -data "equinix_metal_organization" "test" { - organization_id = equinix_metal_organization.test.id -} -`, r) -} diff --git a/internal/resources/metal/organization/resource_test.go b/internal/resources/metal/organization/resource_test.go deleted file mode 100644 index a9d830cb8..000000000 --- a/internal/resources/metal/organization/resource_test.go +++ /dev/null @@ -1,213 +0,0 @@ -package organization_test - -import ( - "fmt" - "testing" - "time" - - "github.com/equinix/terraform-provider-equinix/internal/acceptance" - "github.com/equinix/terraform-provider-equinix/internal/config" - - "github.com/hashicorp/terraform-plugin-testing/helper/acctest" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/plancheck" - "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/packethost/packngo" -) - -func TestAccMetalOrganization_create(t *testing.T) { - var org, org2 packngo.Organization - rInt := acctest.RandInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.TestAccPreCheckMetal(t); acceptance.TestAccPreCheckProviderConfigured(t) }, - ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, - CheckDestroy: testAccMetalOrganizationCheckDestroyed, - Steps: []resource.TestStep{ - { - Config: testAccMetalOrganizationConfig_basic(rInt), - Check: resource.ComposeTestCheckFunc( - testAccMetalOrganizationExists("equinix_metal_organization.test", &org), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "name", fmt.Sprintf("tfacc-org-%d", rInt)), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "description", "quux"), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "address.0.city", "London"), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "address.0.state", ""), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "address.0.zip_code", "12345"), - ), - }, - { - PreConfig: testAccMetalWaitForOrganization, - Config: testAccMetalOrganizationConfig_basicUpdate(rInt), - Check: resource.ComposeTestCheckFunc( - testAccMetalOrganizationExists("equinix_metal_organization.test", &org2), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "name", fmt.Sprintf("tfacc-org-%d", rInt)), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "description", "baz"), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "address.0.city", "Madrid"), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "address.0.state", "Madrid"), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "twitter", "@Equinix"), - testAccMetalSameOrganization(t, &org, &org2), - ), - }, - }, - }) -} - -func TestAccMetalOrganization_importBasic(t *testing.T) { - rInt := acctest.RandInt() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.TestAccPreCheckMetal(t); acceptance.TestAccPreCheckProviderConfigured(t) }, - ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, - CheckDestroy: testAccMetalOrganizationCheckDestroyed, - Steps: []resource.TestStep{ - { - Config: testAccMetalOrganizationConfig_basic(rInt), - }, - { - ResourceName: "equinix_metal_organization.test", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -// Test to verify that switching from SDKv2 to the Framework has not affected provider's behavior -func TestAccMetalOrganization_upgradeFromVersion(t *testing.T) { - var org packngo.Organization - rInt := acctest.RandInt() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.TestAccPreCheckMetal(t); acceptance.TestAccPreCheckProviderConfigured(t) }, - CheckDestroy: testAccMetalOrganizationCheckDestroyed, - Steps: []resource.TestStep{ - { - ExternalProviders: map[string]resource.ExternalProvider{ - "equinix": { - VersionConstraint: "1.29.0", // latest version with resource defined on SDKv2 - Source: "equinix/equinix", - }, - }, - Config: testAccMetalOrganizationConfig_basic(rInt), - Check: resource.ComposeTestCheckFunc( - testAccMetalOrganizationExists("equinix_metal_organization.test", &org), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "name", fmt.Sprintf("tfacc-org-%d", rInt)), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "description", "quux"), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "address.0.city", "London"), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "address.0.state", ""), - resource.TestCheckResourceAttr( - "equinix_metal_organization.test", "address.0.zip_code", "12345"), - ), - }, - { - ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, - Config: testAccMetalOrganizationConfig_basic(rInt), - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - }, - }, - }, - }) -} - -func testAccMetalSameOrganization(t *testing.T, before, after *packngo.Organization) resource.TestCheckFunc { - return func(s *terraform.State) error { - if before.ID != after.ID { - t.Fatalf("Expected organization to be the same, but it was recreated: %s -> %s", before.ID, after.ID) - } - return nil - } -} - -func testAccMetalWaitForOrganization() { - // Some aspect of organization creation takes a while - // to propagate; updating an organization too soon after - // create causes test failures and probably doesn't - // reflect real-world usage. - time.Sleep(5 * time.Minute) -} - -func testAccMetalOrganizationCheckDestroyed(s *terraform.State) error { - client := acceptance.TestAccProvider.Meta().(*config.Config).Metal - - for _, rs := range s.RootModule().Resources { - if rs.Type != "equinix_metal_organization" { - continue - } - if _, _, err := client.Organizations.Get(rs.Primary.ID, nil); err == nil { - return fmt.Errorf("Metal Organization still exists") - } - } - - return nil -} - -func testAccMetalOrganizationExists(n string, org *packngo.Organization) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - if rs.Primary.ID == "" { - return fmt.Errorf("No Record ID is set") - } - - client := acceptance.TestAccProvider.Meta().(*config.Config).Metal - - foundOrg, _, err := client.Organizations.Get(rs.Primary.ID, &packngo.GetOptions{Includes: []string{"address", "primary_owner"}}) - if err != nil { - return err - } - if foundOrg.ID != rs.Primary.ID { - return fmt.Errorf("Record not found: %v - %v", rs.Primary.ID, foundOrg) - } - - *org = *foundOrg - - return nil - } -} - -func testAccMetalOrganizationConfig_basic(r int) string { - return fmt.Sprintf(` -resource "equinix_metal_organization" "test" { - name = "tfacc-org-%d" - description = "quux" - address { - address = "tfacc org street" - city = "London" - zip_code = "12345" - country = "GB" - } -}`, r) -} - -func testAccMetalOrganizationConfig_basicUpdate(r int) string { - return fmt.Sprintf(` -resource "equinix_metal_organization" "test" { - name = "tfacc-org-%d" - description = "baz" - address { - address = "tfacc org street" - city = "Madrid" - zip_code = "28108" - country = "ES" - state = "Madrid" - } - twitter = "@Equinix" -}`, r) -} diff --git a/internal/resources/metal/organization_member/resource_test.go b/internal/resources/metal/organization_member/resource_test.go deleted file mode 100644 index 86913adda..000000000 --- a/internal/resources/metal/organization_member/resource_test.go +++ /dev/null @@ -1,158 +0,0 @@ -package organizationmember_test - -import ( - "fmt" - "testing" - - "github.com/equinix/terraform-provider-equinix/internal/acceptance" - "github.com/equinix/terraform-provider-equinix/internal/config" - "github.com/hashicorp/terraform-plugin-testing/helper/acctest" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/packethost/packngo" -) - -func TestAccResourceMetalOrganizationMember_owner(t *testing.T) { - rInt := acctest.RandInt() - org := &packngo.Organization{} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.TestAccPreCheckMetal(t); acceptance.TestAccPreCheckProviderConfigured(t) }, - ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, - CheckDestroy: testAccMetalOrganizationCheckDestroyed, - Steps: []resource.TestStep{ - { - Config: testAccResourceMetalOrganizationMember_basic(rInt), - Check: resource.ComposeTestCheckFunc( - testAccMetalOrganizationExists("equinix_metal_organization.test", org), - ), - }, - { - ResourceName: "equinix_metal_organization_member.owner", - Config: testAccResourceMetalOrganizationMember_basic(rInt) + testAccResourceMetalOrganizationMember_owner(), - ImportStateIdFunc: resource.ImportStateIdFunc(func(s *terraform.State) (string, error) { - return fmt.Sprintf("%s:%s", org.PrimaryOwner.Email, org.ID), nil - }), - ImportState: true, - }, - { - Config: testAccResourceMetalOrganizationMember_basic(rInt), - }, - }, - }) -} - -func TestAccResourceMetalOrganizationMember_basic(t *testing.T) { - rInt := acctest.RandInt() - org := &packngo.Organization{} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.TestAccPreCheckMetal(t); acceptance.TestAccPreCheckProviderConfigured(t) }, - ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, - CheckDestroy: testAccMetalOrganizationCheckDestroyed, - Steps: []resource.TestStep{ - { - Config: testAccResourceMetalOrganizationMember_basic(rInt), - Check: resource.ComposeTestCheckFunc( - testAccMetalOrganizationExists("equinix_metal_organization.test", org), - ), - }, - { - ResourceName: "equinix_metal_organization_member.member", - Config: testAccResourceMetalOrganizationMember_basic(rInt) + testAccResourceMetalOrganizationMember_member(), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "equinix_metal_organization_member.member", "state", - "invited"), - ), - ImportStateVerify: true, - }, - { - Config: testAccResourceMetalOrganizationMember_basic(rInt), - Destroy: true, - }, - }, - }) -} - -func testAccResourceMetalOrganizationMember_basic(r int) string { - return fmt.Sprintf(` -resource "equinix_metal_organization" "test" { - name = "tfacc-resource-org-member-%d" - description = "tfacc-resource-org-member-desc" - address { - address = "tfacc org street" - city = "london" - zip_code = "12345" - country = "GB" - } -} - -resource "equinix_metal_project" "test" { - organization_id = equinix_metal_organization.test.id - name = "tfacc-resource-project-%d" -} -`, r, r) -} - -func testAccResourceMetalOrganizationMember_owner() string { - return ` - resource "equinix_metal_organization_member" "owner" { - invitee = "/* TODO: Add org owner email or token owner email here */" - roles = ["owner"] - projects_ids = [] - organization_id = equinix_metal_organization.test.id - } - ` -} - -func testAccResourceMetalOrganizationMember_member() string { - return ` -resource "equinix_metal_organization_member" "member" { - invitee = "tfacc.testing.member@equinixmetal.com" - roles = ["limited_collaborator"] - projects_ids = [equinix_metal_project.test.id] - organization_id = equinix_metal_organization.test.id - message = "This invitation was sent by the github.com/equinix/terraform-provider-equinix acceptance tests to test equinix_metal_organization_member resources." -} -` -} - -func testAccMetalOrganizationCheckDestroyed(s *terraform.State) error { - client := acceptance.TestAccProvider.Meta().(*config.Config).Metal - - for _, rs := range s.RootModule().Resources { - if rs.Type != "equinix_metal_organization" { - continue - } - if _, _, err := client.Organizations.Get(rs.Primary.ID, nil); err == nil { - return fmt.Errorf("Metal Organization still exists") - } - } - - return nil -} - -func testAccMetalOrganizationExists(n string, org *packngo.Organization) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - if rs.Primary.ID == "" { - return fmt.Errorf("No Record ID is set") - } - - client := acceptance.TestAccProvider.Meta().(*config.Config).Metal - - foundOrg, _, err := client.Organizations.Get(rs.Primary.ID, &packngo.GetOptions{Includes: []string{"address", "primary_owner"}}) - if err != nil { - return err - } - if foundOrg.ID != rs.Primary.ID { - return fmt.Errorf("Record not found: %v - %v", rs.Primary.ID, foundOrg) - } - - *org = *foundOrg - - return nil - } -} diff --git a/internal/resources/metal/project/resource_test.go b/internal/resources/metal/project/resource_test.go index acf933338..3bb334f15 100644 --- a/internal/resources/metal/project/resource_test.go +++ b/internal/resources/metal/project/resource_test.go @@ -365,51 +365,6 @@ resource "equinix_metal_project" "foobar" { }`, r, pass) } -func testAccMetalProjectConfig_organization(r string) string { - return fmt.Sprintf(` -resource "equinix_metal_organization" "test" { - name = "tfacc-project-%s" - address { - address = "tfacc org street" - city = "london" - zip_code = "12345" - country = "GB" - } -} - -resource "equinix_metal_project" "foobar" { - name = "tfacc-project-%s" - organization_id = "${equinix_metal_organization.test.id}" -}`, r, r) -} - -func TestAccMetalProject_organization(t *testing.T) { - var project metalv1.Project - rn := acctest.RandStringFromCharSet(12, "abcdef0123456789") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.TestAccPreCheck(t) }, - ExternalProviders: acceptance.TestExternalProviders, - ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, - CheckDestroy: testAccMetalProjectCheckDestroyed, - Steps: []resource.TestStep{ - { - Config: testAccMetalProjectConfig_organization(rn), - Check: resource.ComposeTestCheckFunc( - testAccMetalProjectExists("equinix_metal_project.foobar", &project), - resource.TestCheckResourceAttr( - "equinix_metal_project.foobar", "name", fmt.Sprintf("tfacc-project-%s", rn)), - ), - }, - { - ResourceName: "equinix_metal_project.foobar", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - func TestAccMetalProject_importBasic(t *testing.T) { rInt := acctest.RandInt()