-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 Context Aware Access UserAccessBinding resource (#4368)
* Added basic GcpUserAccessBinding skeleton * Corrected GcpUserAccessBinding base url and parameters * Updated GcpUserAccessBinding example to include cloud identity group * Exclude GcpUserAccessBinding from inspec * Run gcp user access binding tests as part of access policy tests * Trim groups/ prefix from group id This should make the value match what gcp_user_access_binding expects * Corrected trimprefix usage * Added trimprefix usage to example * Added handling of metadata field by operation waiters * Added explicit self_link of {{name}} * Marked group_key as input: true because it is required and immutable * Switched to camel case for parameter/property names * Use self link for import link Follows pattern of UptimeCheckConfig and others. * Switched custom_import because self_link_as_name expects project in path
- Loading branch information
Showing
17 changed files
with
251 additions
and
13 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
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
47 changes: 47 additions & 0 deletions
47
templates/terraform/examples/access_context_manager_gcp_user_access_binding_basic.tf.erb
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,47 @@ | ||
resource "google_cloud_identity_group" "group" { | ||
display_name = "<%= ctx[:vars]['group_id'] %>" | ||
|
||
parent = "customers/<%= ctx[:test_env_vars]['cust_id'] %>" | ||
|
||
group_key { | ||
id = "<%= ctx[:vars]['group_id'] %>@<%= ctx[:test_env_vars]['org_domain'] %>" | ||
} | ||
|
||
labels = { | ||
"cloudidentity.googleapis.com/groups.discussion_forum" = "" | ||
} | ||
} | ||
|
||
resource "google_access_context_manager_access_level" "<%= ctx[:vars]['access_level_id'] %>" { | ||
parent = "accessPolicies/${google_access_context_manager_access_policy.access-policy.name}" | ||
name = "accessPolicies/${google_access_context_manager_access_policy.access-policy.name}/accessLevels/<%= ctx[:vars]['access_level_name'] %>" | ||
title = "<%= ctx[:vars]['access_level_name'] %>" | ||
basic { | ||
conditions { | ||
device_policy { | ||
require_screen_lock = true | ||
os_constraints { | ||
os_type = "DESKTOP_CHROME_OS" | ||
} | ||
} | ||
regions = [ | ||
"US", | ||
] | ||
} | ||
} | ||
} | ||
|
||
resource "google_access_context_manager_access_policy" "access-policy" { | ||
parent = "organizations/<%= ctx[:test_env_vars]['org_id'] %>" | ||
title = "my policy" | ||
} | ||
|
||
|
||
|
||
resource "google_access_context_manager_gcp_user_access_binding" "<%= ctx[:primary_resource_id] %>" { | ||
organization_id = "<%= ctx[:test_env_vars]['org_id'] %>" | ||
group_key = trimprefix(google_cloud_identity_group.group.id, "groups/") | ||
access_levels = [ | ||
google_access_context_manager_access_level.<%= ctx[:vars]['access_level_id'] %>.name, | ||
] | ||
} |
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
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
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
123 changes: 123 additions & 0 deletions
123
third_party/terraform/tests/resource_access_context_manager_gcp_user_access_binding_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,123 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
// Since each test here is acting on the same organization and only one AccessPolicy | ||
// can exist, they need to be run serially. See AccessPolicy for the test runner. | ||
|
||
func testAccAccessContextManagerGcpUserAccessBinding_basicTest(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"org_id": getTestOrgFromEnv(t), | ||
"org_domain": getTestOrgDomainFromEnv(t), | ||
"cust_id": getTestCustIdFromEnv(t), | ||
"random_suffix": randString(t, 10), | ||
} | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
ExternalProviders: map[string]resource.ExternalProvider{ | ||
"random": {}, | ||
}, | ||
CheckDestroy: testAccCheckAccessContextManagerGcpUserAccessBindingDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAccessContextManagerGcpUserAccessBinding_accessContextManagerGcpUserAccessBindingBasicExample(context), | ||
}, | ||
{ | ||
ResourceName: "google_access_context_manager_gcp_user_access_binding.gcp_user_access_binding", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"organization_id"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAccessContextManagerGcpUserAccessBinding_accessContextManagerGcpUserAccessBindingBasicExample(context map[string]interface{}) string { | ||
return Nprintf(` | ||
resource "google_cloud_identity_group" "group" { | ||
display_name = "tf-test-my-identity-group%{random_suffix}" | ||
parent = "customers/%{cust_id}" | ||
group_key { | ||
id = "tf-test-my-identity-group%{random_suffix}@%{org_domain}" | ||
} | ||
labels = { | ||
"cloudidentity.googleapis.com/groups.discussion_forum" = "" | ||
} | ||
} | ||
resource "google_access_context_manager_access_level" "tf_test_access_level_id_for_user_access_binding%{random_suffix}" { | ||
parent = "accessPolicies/${google_access_context_manager_access_policy.access-policy.name}" | ||
name = "accessPolicies/${google_access_context_manager_access_policy.access-policy.name}/accessLevels/tf_test_chromeos_no_lock%{random_suffix}" | ||
title = "tf_test_chromeos_no_lock%{random_suffix}" | ||
basic { | ||
conditions { | ||
device_policy { | ||
require_screen_lock = true | ||
os_constraints { | ||
os_type = "DESKTOP_CHROME_OS" | ||
} | ||
} | ||
regions = [ | ||
"US", | ||
] | ||
} | ||
} | ||
} | ||
resource "google_access_context_manager_access_policy" "access-policy" { | ||
parent = "organizations/%{org_id}" | ||
title = "my policy" | ||
} | ||
resource "google_access_context_manager_gcp_user_access_binding" "gcp_user_access_binding" { | ||
organization_id = "%{org_id}" | ||
group_key = trimprefix(google_cloud_identity_group.group.id, "groups/") | ||
access_levels = [ | ||
google_access_context_manager_access_level.tf_test_access_level_id_for_user_access_binding%{random_suffix}.name, | ||
] | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccCheckAccessContextManagerGcpUserAccessBindingDestroyProducer(t *testing.T) func(s *terraform.State) error { | ||
return func(s *terraform.State) error { | ||
for name, rs := range s.RootModule().Resources { | ||
if rs.Type != "google_access_context_manager_gcp_user_access_binding" { | ||
continue | ||
} | ||
if strings.HasPrefix(name, "data.") { | ||
continue | ||
} | ||
|
||
config := googleProviderConfig(t) | ||
|
||
url, err := replaceVarsForTest(config, rs, "{{AccessContextManagerBasePath}}organizations/{{organization_id}}/gcpUserAccessBindings/{{name}}") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = sendRequest(config, "GET", "", url, config.userAgent, nil) | ||
if err == nil { | ||
return fmt.Errorf("AccessContextManagerGcpUserAccessBinding still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
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
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