Skip to content

Commit

Permalink
Fix test for Ingress Policy (hashicorp#7762) (hashicorp#14361)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and SarahFrench committed Apr 20, 2023
1 parent 0720a38 commit da00084
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .changelog/7762.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
accesscontextmanager: fixed test for `google_access_context_manager_ingress_policy`
```
4 changes: 2 additions & 2 deletions google/resource_access_context_manager_ingress_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func resourceAccessContextManagerIngressPolicyCreate(d *schema.ResourceData, met
}

// Store the ID now
id, err := ReplaceVars(d, config, "{{ingress_policy_name}}{{resource}}")
id, err := ReplaceVars(d, config, "{{ingress_policy_name}}/{{resource}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func resourceAccessContextManagerIngressPolicyCreate(d *schema.ResourceData, met
}

// This may have caused the ID to update - update it if so.
id, err = ReplaceVars(d, config, "{{ingress_policy_name}}{{resource}}")
id, err = ReplaceVars(d, config, "{{ingress_policy_name}}/{{resource}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
Expand Down
20 changes: 5 additions & 15 deletions google/resource_access_context_manager_ingress_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,22 @@ func testAccAccessContextManagerIngressPolicy_basicTest(t *testing.T) {
// Multiple fine-grained resources
SkipIfVcr(t)
org := GetTestOrgFromEnv(t)
projects := BootstrapServicePerimeterProjects(t, 2)
projects := BootstrapServicePerimeterProjects(t, 1)
policyTitle := RandString(t, 10)
perimeterTitle := RandString(t, 10)
perimeterTitle := "perimeter"

VcrTest(t, resource.TestCase{
PreCheck: func() { AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccAccessContextManagerIngressPolicy_basic(org, policyTitle, perimeterTitle, projects[0].ProjectNumber, projects[1].ProjectNumber),
Config: testAccAccessContextManagerIngressPolicy_basic(org, policyTitle, perimeterTitle, projects[0].ProjectNumber),
},
{
ResourceName: "google_access_context_manager_ingress_policy.test-access1",
ImportState: true,
ImportStateVerify: true,
},
{
ResourceName: "google_access_context_manager_ingress_policy.test-access2",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAccessContextManagerIngressPolicy_destroy(org, policyTitle, perimeterTitle),
Check: testAccCheckAccessContextManagerIngressPolicyDestroyProducer(t),
Expand Down Expand Up @@ -86,7 +81,7 @@ func testAccCheckAccessContextManagerIngressPolicyDestroyProducer(t *testing.T)
}
}

func testAccAccessContextManagerIngressPolicy_basic(org, policyTitle, perimeterTitleName string, projectNumber1, projectNumber2 int64) string {
func testAccAccessContextManagerIngressPolicy_basic(org, policyTitle, perimeterTitleName string, projectNumber1 int64) string {
return fmt.Sprintf(`
%s
Expand All @@ -95,12 +90,7 @@ resource "google_access_context_manager_ingress_policy" "test-access1" {
resource = "projects/%d"
}
resource "google_access_context_manager_ingress_policy" "test-access2" {
ingress_policy_name = google_access_context_manager_service_perimeter.test-access.name
resource = "projects/%d"
}
`, testAccAccessContextManagerIngressPolicy_destroy(org, policyTitle, perimeterTitleName), projectNumber1, projectNumber2)
`, testAccAccessContextManagerIngressPolicy_destroy(org, policyTitle, perimeterTitleName), projectNumber1)
}

func testAccAccessContextManagerIngressPolicy_destroy(org, policyTitle, perimeterTitleName string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The following arguments are supported:

In addition to the arguments listed above, the following computed attributes are exported:

* `id` - an identifier for the resource with format `{{ingress_policy_name}}{{resource}}`
* `id` - an identifier for the resource with format `{{ingress_policy_name}}/{{resource}}`


## Timeouts
Expand All @@ -73,5 +73,4 @@ IngressPolicy can be imported using any of these accepted formats:

```
$ terraform import google_access_context_manager_ingress_policy.default {{ingress_policy_name}}/{{resource}}
$ terraform import google_access_context_manager_ingress_policy.default {{ingress_policy_name}}{{resource}}
```

0 comments on commit da00084

Please sign in to comment.