-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore the metal_project datasource name filter (#554)
Closes #549 When the Metal project data source was migrated to `equinix-sdk-go`, finding a project by name was broken in some cases. To ensure that the data source can always find the named project (assuming it really exists), we have to use the `ExecuteWithPagination()` function to load all pages of projects instead of `Execute()` which only loads one page. As a minor optimization, this uses the `Name()` filter to reduce the number of results that are returned by the API. I've also taken the opportunity to move the Metal project resource and data source to a separate package.
- Loading branch information
Showing
6 changed files
with
152 additions
and
97 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package project_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 TestAccDataSourceMetalProject_byId(t *testing.T) { | ||
var project packngo.Project | ||
rn := acctest.RandStringFromCharSet(12, "abcdef0123456789") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.TestAccPreCheck(t) }, | ||
ExternalProviders: acceptance.TestExternalProviders, | ||
Providers: acceptance.TestAccProviders, | ||
CheckDestroy: testAccMetalProjectCheckDestroyed, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceMetalProject_byId(rn), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccMetalProjectExists("equinix_metal_project.foobar", &project), | ||
resource.TestCheckResourceAttr( | ||
"equinix_metal_project.foobar", "name", fmt.Sprintf("tfacc-project-%s", rn)), | ||
resource.TestCheckResourceAttr( | ||
"equinix_metal_project.foobar", "bgp_config.0.md5", | ||
"2SFsdfsg43"), | ||
resource.TestCheckResourceAttrPair( | ||
"equinix_metal_project.foobar", "id", | ||
"data.equinix_metal_project.test", "id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceMetalProject_byId(r string) string { | ||
return fmt.Sprintf(` | ||
terraform { | ||
provider_meta "equinix" { | ||
module_name = "test" | ||
} | ||
} | ||
resource "equinix_metal_project" "foobar" { | ||
name = "tfacc-project-%s" | ||
bgp_config { | ||
deployment_type = "local" | ||
md5 = "2SFsdfsg43" | ||
asn = 65000 | ||
} | ||
} | ||
data equinix_metal_project "test" { | ||
project_id = equinix_metal_project.foobar.id | ||
} | ||
`, r) | ||
} | ||
|
||
func TestAccDataSourceMetalProject_byName(t *testing.T) { | ||
var project packngo.Project | ||
rn := acctest.RandStringFromCharSet(12, "abcdef0123456789") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.TestAccPreCheck(t) }, | ||
ExternalProviders: acceptance.TestExternalProviders, | ||
Providers: acceptance.TestAccProviders, | ||
CheckDestroy: testAccMetalProjectCheckDestroyed, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceMetalProject_byName(rn), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccMetalProjectExists("equinix_metal_project.foobar", &project), | ||
resource.TestCheckResourceAttr( | ||
"equinix_metal_project.foobar", "name", fmt.Sprintf("tfacc-project-%s", rn)), | ||
resource.TestCheckResourceAttr( | ||
"equinix_metal_project.foobar", "bgp_config.0.md5", | ||
"2SFsdfsg43"), | ||
resource.TestCheckResourceAttrPair( | ||
"equinix_metal_project.foobar", "id", | ||
"data.equinix_metal_project.test", "id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceMetalProject_byName(r string) string { | ||
return fmt.Sprintf(` | ||
terraform { | ||
provider_meta "equinix" { | ||
module_name = "test" | ||
} | ||
} | ||
resource "equinix_metal_project" "foobar" { | ||
name = "tfacc-project-%s" | ||
bgp_config { | ||
deployment_type = "local" | ||
md5 = "2SFsdfsg43" | ||
asn = 65000 | ||
} | ||
} | ||
data equinix_metal_project "test" { | ||
name = equinix_metal_project.foobar.name | ||
} | ||
`, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.