-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for access_context_manager_access_level
- Loading branch information
1 parent
2f8767a
commit a0265ca
Showing
7 changed files
with
1,092 additions
and
6 deletions.
There are no files selected for viewing
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
154 changes: 154 additions & 0 deletions
154
google-beta/resource_access_context_manager_access_level_test.go
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,154 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
// Access Context Manager tests need to run serially | ||
func TestAccAccessContextManagerAccessLevel_basic(t *testing.T) { | ||
org := getTestOrgFromEnv(t) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAccessContextManagerAccessLevelDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAccessContextManagerAccessLevel_basic(org, "my policy", "level"), | ||
}, | ||
{ | ||
ResourceName: "google_access_context_manager_access_level.test-access", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccAccessContextManagerAccessLevel_basicUpdated(org, "my new policy", "level"), | ||
}, | ||
{ | ||
ResourceName: "google_access_context_manager_access_level.test-access", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAccessContextManagerAccessLevel_full(t *testing.T) { | ||
org := getTestOrgFromEnv(t) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAccessContextManagerAccessLevelDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAccessContextManagerAccessLevel_full(org, "my policy", "level"), | ||
}, | ||
{ | ||
ResourceName: "google_access_context_manager_access_level.test-access", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAccessContextManagerAccessLevelDestroy(s *terraform.State) error { | ||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "google_access_context_manager_access_level" { | ||
continue | ||
} | ||
|
||
config := testAccProvider.Meta().(*Config) | ||
|
||
url, err := replaceVarsForTest(rs, "https://accesscontextmanager.googleapis.com/v1beta/{{name}}") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = sendRequest(config, "GET", url, nil) | ||
if err == nil { | ||
return fmt.Errorf("AccessLevel still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccAccessContextManagerAccessLevel_basic(org, policyTitle, levelTitleName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_access_context_manager_access_policy" "test-access" { | ||
parent = "organizations/%s" | ||
title = "%s" | ||
} | ||
resource "google_access_context_manager_access_level" "test-access" { | ||
parent = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}" | ||
name = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}/accessLevels/%s" | ||
title = "%s" | ||
description = "hello" | ||
basic { | ||
combining_function = "AND" | ||
conditions { | ||
ip_subnetworks = ["192.0.4.0/24"] | ||
} | ||
} | ||
} | ||
`, org, policyTitle, levelTitleName, levelTitleName) | ||
} | ||
|
||
func testAccAccessContextManagerAccessLevel_basicUpdated(org, policyTitle, levelTitleName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_access_context_manager_access_policy" "test-access" { | ||
parent = "organizations/%s" | ||
title = "%s" | ||
} | ||
resource "google_access_context_manager_access_level" "test-access" { | ||
parent = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}" | ||
name = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}/accessLevels/%s" | ||
title = "%s" | ||
description = "hello" | ||
basic { | ||
combining_function = "OR" | ||
conditions { | ||
ip_subnetworks = ["192.0.2.0/24"] | ||
} | ||
} | ||
} | ||
`, org, policyTitle, levelTitleName, levelTitleName) | ||
} | ||
|
||
func testAccAccessContextManagerAccessLevel_full(org, policyTitle, levelTitleName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_access_context_manager_access_policy" "test-access" { | ||
parent = "organizations/%s" | ||
title = "%s" | ||
} | ||
resource "google_access_context_manager_access_level" "test-access" { | ||
parent = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}" | ||
name = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}/accessLevels/%s" | ||
title = "%s" | ||
description = "hello" | ||
basic { | ||
combining_function = "AND" | ||
conditions { | ||
ip_subnetworks = ["192.0.4.0/24"] | ||
members = ["user:[email protected]", "user:[email protected]"] | ||
negate = false | ||
device_policy { | ||
require_screen_lock = false | ||
os_constraints { | ||
os_type = "IOS" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, org, policyTitle, levelTitleName, levelTitleName) | ||
} |
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.