Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for access_context_manager_access_level #149

Merged
merged 1 commit into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions google-beta/provider_accesscontextmanager_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ import "github.com/hashicorp/terraform/helper/schema"

var GeneratedAccessContextManagerResourcesMap = map[string]*schema.Resource{
"google_access_context_manager_access_policy": resourceAccessContextManagerAccessPolicy(),
"google_access_context_manager_access_level": resourceAccessContextManagerAccessLevel(),
}
154 changes: 154 additions & 0 deletions google-beta/resource_access_context_manager_access_level_test.go
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:test@google.com", "user:test2@google.com"]
negate = false
device_policy {
require_screen_lock = false
os_constraints {
os_type = "IOS"
}
}
}
}
}
`, org, policyTitle, levelTitleName, levelTitleName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (
"github.com/hashicorp/terraform/terraform"
)

// We can only have a single test as long as we are using a single organization
// Access Context Manager tests need to run serially
func TestAccAccessContextManagerAccessPolicy_basic(t *testing.T) {
t.Parallel()

org := getTestOrgFromEnv(t)

resource.Test(t, resource.TestCase{
Expand Down
Loading