From e3db55c5f3b4ff3f6e5a860d267393b85049e3f4 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Thu, 9 Jan 2020 23:48:21 +0000 Subject: [PATCH] Make binding optional for iam_policy data source Signed-off-by: Modular Magician --- google/data_source_google_iam_policy.go | 6 +- ...y_authorization_attestor_generated_test.go | 58 ++++++++++++++ ...functions_cloud_function_generated_test.go | 46 ++++++++++++ .../iam_cloud_run_service_generated_test.go | 41 ++++++++++ google/iam_compute_instance_generated_test.go | 39 ++++++++++ .../iam_compute_subnetwork_generated_test.go | 39 ++++++++++ ...m_iap_app_engine_service_generated_test.go | 75 +++++++++++++++++++ ...m_iap_app_engine_version_generated_test.go | 52 +++++++++++++ ..._iap_web_backend_service_generated_test.go | 34 +++++++++ google/iam_iap_web_generated_test.go | 32 ++++++++ ..._iap_web_type_app_engine_generated_test.go | 38 ++++++++++ ...iam_iap_web_type_compute_generated_test.go | 32 ++++++++ google/iam_pubsub_topic_generated_test.go | 30 ++++++++ ...am_runtime_config_config_generated_test.go | 27 +++++++ ...m_source_repo_repository_generated_test.go | 26 +++++++ google/iam_storage_bucket_generated_test.go | 26 +++++++ 16 files changed, 599 insertions(+), 2 deletions(-) diff --git a/google/data_source_google_iam_policy.go b/google/data_source_google_iam_policy.go index 760f629670c..7a690305733 100644 --- a/google/data_source_google_iam_policy.go +++ b/google/data_source_google_iam_policy.go @@ -29,8 +29,10 @@ func dataSourceGoogleIamPolicy() *schema.Resource { Read: dataSourceGoogleIamPolicyRead, Schema: map[string]*schema.Schema{ "binding": { - Type: schema.TypeSet, - Required: true, + Type: schema.TypeSet, + // Binding is optional because a user may want to set an IAM policy with no bindings + // This allows users to ensure that no bindings were created outside of terraform + Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "role": { diff --git a/google/iam_binary_authorization_attestor_generated_test.go b/google/iam_binary_authorization_attestor_generated_test.go index e7c4aba2e5f..77f2590e648 100644 --- a/google/iam_binary_authorization_attestor_generated_test.go +++ b/google/iam_binary_authorization_attestor_generated_test.go @@ -104,6 +104,15 @@ func TestAccBinaryAuthorizationAttestorIamPolicyGenerated(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccBinaryAuthorizationAttestorIamPolicy_emptyBinding(context), + }, + { + ResourceName: "google_binary_authorization_attestor_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/attestors/%s", getTestProjectFromEnv(), fmt.Sprintf("test-attestor%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -208,6 +217,55 @@ resource "google_binary_authorization_attestor_iam_policy" "foo" { `, context) } +func testAccBinaryAuthorizationAttestorIamPolicy_emptyBinding(context map[string]interface{}) string { + return Nprintf(` +resource "google_binary_authorization_attestor" "attestor" { + name = "test-attestor%{random_suffix}" + attestation_authority_note { + note_reference = google_container_analysis_note.note.name + public_keys { + ascii_armored_pgp_public_key = <