Skip to content

Commit

Permalink
Add support for google_access_context_manager_service_perimeter
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson authored and modular-magician committed Dec 17, 2018
1 parent 51920e5 commit 4ab1cc7
Show file tree
Hide file tree
Showing 4 changed files with 808 additions and 2 deletions.
5 changes: 3 additions & 2 deletions google-beta/provider_accesscontextmanager_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package google
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(),
"google_access_context_manager_access_policy": resourceAccessContextManagerAccessPolicy(),
"google_access_context_manager_access_level": resourceAccessContextManagerAccessLevel(),
"google_access_context_manager_service_perimeter": resourceAccessContextManagerServicePerimeter(),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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 TestAccAccessContextManagerServicePerimeter_basic(t *testing.T) {
org := getTestOrgFromEnv(t)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAccessContextManagerServicePerimeterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAccessContextManagerServicePerimeter_basic(org, "my policy", "level", "perimeter"),
},
{
ResourceName: "google_access_context_manager_service_perimeter.test-access",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckAccessContextManagerServicePerimeterDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_access_context_manager_service_perimeter" {
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("ServicePerimeter still exists at %s", url)
}
}

return nil
}

func testAccAccessContextManagerServicePerimeter_basic(org, policyTitle, levelTitleName, perimeterTitleName 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"]
}
}
}
resource "google_access_context_manager_service_perimeter" "test-access" {
parent = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}"
name = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}/servicePerimeters/%s"
title = "%s"
perimeter_type = "PERIMETER_TYPE_REGULAR"
status {
restricted_services = ["*"]
}
}
`, org, policyTitle, levelTitleName, levelTitleName, perimeterTitleName, perimeterTitleName)
}
Loading

0 comments on commit 4ab1cc7

Please sign in to comment.