From 5889852a9b648c4dfd72795c2f96673949519dfb Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 6 Jun 2023 12:45:17 -0700 Subject: [PATCH] Add iam policy details for datascan (#8069) (#14828) * add iam policy details for datascan * Use lower case for examples resource name Signed-off-by: Modular Magician --- .changelog/8069.txt | 3 + google/iam_dataplex_datascan.go | 245 ++++++++++++++ .../iam_dataplex_datascan_generated_test.go | 303 ++++++++++++++++++ google/provider.go | 8 +- ...dataplex_datascan_iam_policy.html.markdown | 53 +++ .../r/dataplex_datascan_iam.html.markdown | 154 +++++++++ 6 files changed, 764 insertions(+), 2 deletions(-) create mode 100644 .changelog/8069.txt create mode 100644 google/iam_dataplex_datascan.go create mode 100644 google/iam_dataplex_datascan_generated_test.go create mode 100644 website/docs/d/dataplex_datascan_iam_policy.html.markdown create mode 100644 website/docs/r/dataplex_datascan_iam.html.markdown diff --git a/.changelog/8069.txt b/.changelog/8069.txt new file mode 100644 index 00000000000..7f1c46307cf --- /dev/null +++ b/.changelog/8069.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_dataplex_datascan_iam_*` +``` diff --git a/google/iam_dataplex_datascan.go b/google/iam_dataplex_datascan.go new file mode 100644 index 00000000000..b79a5fe6cb1 --- /dev/null +++ b/google/iam_dataplex_datascan.go @@ -0,0 +1,245 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + + "github.com/hashicorp/errwrap" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "google.golang.org/api/cloudresourcemanager/v1" + + "github.com/hashicorp/terraform-provider-google/google/tpgiamresource" + "github.com/hashicorp/terraform-provider-google/google/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" +) + +var DataplexDatascanIamSchema = map[string]*schema.Schema{ + "project": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "location": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "data_scan_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, +} + +type DataplexDatascanIamUpdater struct { + project string + location string + dataScanId string + d tpgresource.TerraformResourceData + Config *transport_tpg.Config +} + +func DataplexDatascanIamUpdaterProducer(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (tpgiamresource.ResourceIamUpdater, error) { + values := make(map[string]string) + + project, _ := getProject(d, config) + if project != "" { + if err := d.Set("project", project); err != nil { + return nil, fmt.Errorf("Error setting project: %s", err) + } + } + values["project"] = project + location, _ := getLocation(d, config) + if location != "" { + if err := d.Set("location", location); err != nil { + return nil, fmt.Errorf("Error setting location: %s", err) + } + } + values["location"] = location + if v, ok := d.GetOk("data_scan_id"); ok { + values["data_scan_id"] = v.(string) + } + + // We may have gotten either a long or short name, so attempt to parse long name if possible + m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/dataScans/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("data_scan_id").(string)) + if err != nil { + return nil, err + } + + for k, v := range m { + values[k] = v + } + + u := &DataplexDatascanIamUpdater{ + project: values["project"], + location: values["location"], + dataScanId: values["data_scan_id"], + d: d, + Config: config, + } + + if err := d.Set("project", u.project); err != nil { + return nil, fmt.Errorf("Error setting project: %s", err) + } + if err := d.Set("location", u.location); err != nil { + return nil, fmt.Errorf("Error setting location: %s", err) + } + if err := d.Set("data_scan_id", u.GetResourceId()); err != nil { + return nil, fmt.Errorf("Error setting data_scan_id: %s", err) + } + + return u, nil +} + +func DataplexDatascanIdParseFunc(d *schema.ResourceData, config *transport_tpg.Config) error { + values := make(map[string]string) + + project, _ := getProject(d, config) + if project != "" { + values["project"] = project + } + + location, _ := getLocation(d, config) + if location != "" { + values["location"] = location + } + + m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/dataScans/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Id()) + if err != nil { + return err + } + + for k, v := range m { + values[k] = v + } + + u := &DataplexDatascanIamUpdater{ + project: values["project"], + location: values["location"], + dataScanId: values["data_scan_id"], + d: d, + Config: config, + } + if err := d.Set("data_scan_id", u.GetResourceId()); err != nil { + return fmt.Errorf("Error setting data_scan_id: %s", err) + } + d.SetId(u.GetResourceId()) + return nil +} + +func (u *DataplexDatascanIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { + url, err := u.qualifyDatascanUrl("getIamPolicy") + if err != nil { + return nil, err + } + + project, err := tpgresource.GetProject(u.d, u.Config) + if err != nil { + return nil, err + } + var obj map[string]interface{} + + userAgent, err := tpgresource.GenerateUserAgentString(u.d, u.Config.UserAgent) + if err != nil { + return nil, err + } + + policy, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: u.Config, + Method: "GET", + Project: project, + RawURL: url, + UserAgent: userAgent, + Body: obj, + }) + if err != nil { + return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err) + } + + out := &cloudresourcemanager.Policy{} + err = tpgresource.Convert(policy, out) + if err != nil { + return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{err}}", err) + } + + return out, nil +} + +func (u *DataplexDatascanIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error { + json, err := tpgresource.ConvertToMap(policy) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + obj["policy"] = json + + url, err := u.qualifyDatascanUrl("setIamPolicy") + if err != nil { + return err + } + project, err := tpgresource.GetProject(u.d, u.Config) + if err != nil { + return err + } + + userAgent, err := tpgresource.GenerateUserAgentString(u.d, u.Config.UserAgent) + if err != nil { + return err + } + + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: u.Config, + Method: "POST", + Project: project, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: u.d.Timeout(schema.TimeoutCreate), + }) + if err != nil { + return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err) + } + + return nil +} + +func (u *DataplexDatascanIamUpdater) qualifyDatascanUrl(methodIdentifier string) (string, error) { + urlTemplate := fmt.Sprintf("{{DataplexBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", u.project, u.location, u.dataScanId), methodIdentifier) + url, err := tpgresource.ReplaceVars(u.d, u.Config, urlTemplate) + if err != nil { + return "", err + } + return url, nil +} + +func (u *DataplexDatascanIamUpdater) GetResourceId() string { + return fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", u.project, u.location, u.dataScanId) +} + +func (u *DataplexDatascanIamUpdater) GetMutexKey() string { + return fmt.Sprintf("iam-dataplex-datascan-%s", u.GetResourceId()) +} + +func (u *DataplexDatascanIamUpdater) DescribeResource() string { + return fmt.Sprintf("dataplex datascan %q", u.GetResourceId()) +} diff --git a/google/iam_dataplex_datascan_generated_test.go b/google/iam_dataplex_datascan_generated_test.go new file mode 100644 index 00000000000..e78f697b51c --- /dev/null +++ b/google/iam_dataplex_datascan_generated_test.go @@ -0,0 +1,303 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +func TestAccDataplexDatascanIamBindingGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": RandString(t, 10), + "role": "roles/viewer", + "project_name": acctest.GetTestProjectFromEnv(), + } + + VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccDataplexDatascanIamBinding_basicGenerated(context), + }, + { + ResourceName: "google_dataplex_datascan_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s roles/viewer", acctest.GetTestProjectFromEnv(), acctest.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-datascan%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + // Test Iam Binding update + Config: testAccDataplexDatascanIamBinding_updateGenerated(context), + }, + { + ResourceName: "google_dataplex_datascan_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s roles/viewer", acctest.GetTestProjectFromEnv(), acctest.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-datascan%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccDataplexDatascanIamMemberGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": RandString(t, 10), + "role": "roles/viewer", + "project_name": acctest.GetTestProjectFromEnv(), + } + + VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + // Test Iam Member creation (no update for member, no need to test) + Config: testAccDataplexDatascanIamMember_basicGenerated(context), + }, + { + ResourceName: "google_dataplex_datascan_iam_member.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s roles/viewer user:admin@hashicorptest.com", acctest.GetTestProjectFromEnv(), acctest.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-datascan%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccDataplexDatascanIamPolicyGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": RandString(t, 10), + "role": "roles/viewer", + "project_name": acctest.GetTestProjectFromEnv(), + } + + VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccDataplexDatascanIamPolicy_basicGenerated(context), + Check: resource.TestCheckResourceAttrSet("data.google_dataplex_datascan_iam_policy.foo", "policy_data"), + }, + { + ResourceName: "google_dataplex_datascan_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", acctest.GetTestProjectFromEnv(), acctest.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-datascan%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDataplexDatascanIamPolicy_emptyBinding(context), + }, + { + ResourceName: "google_dataplex_datascan_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", acctest.GetTestProjectFromEnv(), acctest.GetTestRegionFromEnv(), fmt.Sprintf("tf-test-datascan%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccDataplexDatascanIamMember_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataplex_datascan" "basic_profile" { + location = "us-central1" + data_scan_id = "tf-test-datascan%{random_suffix}" + + data { + resource = "//bigquery.googleapis.com/projects/bigquery-public-data/datasets/samples/tables/shakespeare" + } + + execution_spec { + trigger { + on_demand {} + } + } + + data_profile_spec { + } + + project = "%{project_name}" +} + +resource "google_dataplex_datascan_iam_member" "foo" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id + role = "%{role}" + member = "user:admin@hashicorptest.com" +} +`, context) +} + +func testAccDataplexDatascanIamPolicy_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataplex_datascan" "basic_profile" { + location = "us-central1" + data_scan_id = "tf-test-datascan%{random_suffix}" + + data { + resource = "//bigquery.googleapis.com/projects/bigquery-public-data/datasets/samples/tables/shakespeare" + } + + execution_spec { + trigger { + on_demand {} + } + } + + data_profile_spec { + } + + project = "%{project_name}" +} + +data "google_iam_policy" "foo" { + binding { + role = "%{role}" + members = ["user:admin@hashicorptest.com"] + } +} + +resource "google_dataplex_datascan_iam_policy" "foo" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id + policy_data = data.google_iam_policy.foo.policy_data +} + +data "google_dataplex_datascan_iam_policy" "foo" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id + depends_on = [ + google_dataplex_datascan_iam_policy.foo + ] +} +`, context) +} + +func testAccDataplexDatascanIamPolicy_emptyBinding(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataplex_datascan" "basic_profile" { + location = "us-central1" + data_scan_id = "tf-test-datascan%{random_suffix}" + + data { + resource = "//bigquery.googleapis.com/projects/bigquery-public-data/datasets/samples/tables/shakespeare" + } + + execution_spec { + trigger { + on_demand {} + } + } + + data_profile_spec { + } + + project = "%{project_name}" +} + +data "google_iam_policy" "foo" { +} + +resource "google_dataplex_datascan_iam_policy" "foo" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id + policy_data = data.google_iam_policy.foo.policy_data +} +`, context) +} + +func testAccDataplexDatascanIamBinding_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataplex_datascan" "basic_profile" { + location = "us-central1" + data_scan_id = "tf-test-datascan%{random_suffix}" + + data { + resource = "//bigquery.googleapis.com/projects/bigquery-public-data/datasets/samples/tables/shakespeare" + } + + execution_spec { + trigger { + on_demand {} + } + } + + data_profile_spec { + } + + project = "%{project_name}" +} + +resource "google_dataplex_datascan_iam_binding" "foo" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id + role = "%{role}" + members = ["user:admin@hashicorptest.com"] +} +`, context) +} + +func testAccDataplexDatascanIamBinding_updateGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataplex_datascan" "basic_profile" { + location = "us-central1" + data_scan_id = "tf-test-datascan%{random_suffix}" + + data { + resource = "//bigquery.googleapis.com/projects/bigquery-public-data/datasets/samples/tables/shakespeare" + } + + execution_spec { + trigger { + on_demand {} + } + } + + data_profile_spec { + } + + project = "%{project_name}" +} + +resource "google_dataplex_datascan_iam_binding" "foo" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id + role = "%{role}" + members = ["user:admin@hashicorptest.com", "user:gterraformtest1@gmail.com"] +} +`, context) +} diff --git a/google/provider.go b/google/provider.go index f3009889c0b..3cdb152cc5e 100644 --- a/google/provider.go +++ b/google/provider.go @@ -769,6 +769,7 @@ func DatasourceMapWithErrors() (map[string]*schema.Resource, error) { "google_data_catalog_taxonomy_iam_policy": tpgiamresource.DataSourceIamPolicy(DataCatalogTaxonomyIamSchema, DataCatalogTaxonomyIamUpdaterProducer), "google_data_fusion_instance_iam_policy": tpgiamresource.DataSourceIamPolicy(DataFusionInstanceIamSchema, DataFusionInstanceIamUpdaterProducer), "google_dataplex_asset_iam_policy": tpgiamresource.DataSourceIamPolicy(DataplexAssetIamSchema, DataplexAssetIamUpdaterProducer), + "google_dataplex_datascan_iam_policy": tpgiamresource.DataSourceIamPolicy(DataplexDatascanIamSchema, DataplexDatascanIamUpdaterProducer), "google_dataplex_lake_iam_policy": tpgiamresource.DataSourceIamPolicy(DataplexLakeIamSchema, DataplexLakeIamUpdaterProducer), "google_dataplex_zone_iam_policy": tpgiamresource.DataSourceIamPolicy(DataplexZoneIamSchema, DataplexZoneIamUpdaterProducer), "google_dataproc_autoscaling_policy_iam_policy": tpgiamresource.DataSourceIamPolicy(DataprocAutoscalingPolicyIamSchema, DataprocAutoscalingPolicyIamUpdaterProducer), @@ -826,8 +827,8 @@ func DatasourceMapWithErrors() (map[string]*schema.Resource, error) { } // Generated resources: 288 -// Generated IAM resources: 189 -// Total generated resources: 477 +// Generated IAM resources: 192 +// Total generated resources: 480 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -1087,6 +1088,9 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_dataplex_asset_iam_member": tpgiamresource.ResourceIamMember(DataplexAssetIamSchema, DataplexAssetIamUpdaterProducer, DataplexAssetIdParseFunc), "google_dataplex_asset_iam_policy": tpgiamresource.ResourceIamPolicy(DataplexAssetIamSchema, DataplexAssetIamUpdaterProducer, DataplexAssetIdParseFunc), "google_dataplex_datascan": ResourceDataplexDatascan(), + "google_dataplex_datascan_iam_binding": tpgiamresource.ResourceIamBinding(DataplexDatascanIamSchema, DataplexDatascanIamUpdaterProducer, DataplexDatascanIdParseFunc), + "google_dataplex_datascan_iam_member": tpgiamresource.ResourceIamMember(DataplexDatascanIamSchema, DataplexDatascanIamUpdaterProducer, DataplexDatascanIdParseFunc), + "google_dataplex_datascan_iam_policy": tpgiamresource.ResourceIamPolicy(DataplexDatascanIamSchema, DataplexDatascanIamUpdaterProducer, DataplexDatascanIdParseFunc), "google_dataplex_lake_iam_binding": tpgiamresource.ResourceIamBinding(DataplexLakeIamSchema, DataplexLakeIamUpdaterProducer, DataplexLakeIdParseFunc), "google_dataplex_lake_iam_member": tpgiamresource.ResourceIamMember(DataplexLakeIamSchema, DataplexLakeIamUpdaterProducer, DataplexLakeIdParseFunc), "google_dataplex_lake_iam_policy": tpgiamresource.ResourceIamPolicy(DataplexLakeIamSchema, DataplexLakeIamUpdaterProducer, DataplexLakeIdParseFunc), diff --git a/website/docs/d/dataplex_datascan_iam_policy.html.markdown b/website/docs/d/dataplex_datascan_iam_policy.html.markdown new file mode 100644 index 00000000000..e0adc74ac65 --- /dev/null +++ b/website/docs/d/dataplex_datascan_iam_policy.html.markdown @@ -0,0 +1,53 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +subcategory: "Dataplex" +description: |- + A datasource to retrieve the IAM policy state for Dataplex Datascan +--- + + +# `google_dataplex_datascan_iam_policy` +Retrieves the current IAM policy data for datascan + + + +## example + +```hcl +data "google_dataplex_datascan_iam_policy" "policy" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `location` - (Required) The location where the data scan should reside. + Used to find the parent resource to bind the IAM policy to + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the project will be parsed from the identifier of the parent resource. If no project is provided in the parent identifier and no project is specified, the provider project is used. + +## Attributes Reference + +The attributes are exported: + +* `etag` - (Computed) The etag of the IAM policy. + +* `policy_data` - (Required only by `google_dataplex_datascan_iam_policy`) The policy data generated by + a `google_iam_policy` data source. diff --git a/website/docs/r/dataplex_datascan_iam.html.markdown b/website/docs/r/dataplex_datascan_iam.html.markdown new file mode 100644 index 00000000000..ce2f64a90b0 --- /dev/null +++ b/website/docs/r/dataplex_datascan_iam.html.markdown @@ -0,0 +1,154 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +subcategory: "Dataplex" +description: |- + Collection of resources to manage IAM policy for Dataplex Datascan +--- + +# IAM policy for Dataplex Datascan +Three different resources help you manage your IAM policy for Dataplex Datascan. Each of these resources serves a different use case: + +* `google_dataplex_datascan_iam_policy`: Authoritative. Sets the IAM policy for the datascan and replaces any existing policy already attached. +* `google_dataplex_datascan_iam_binding`: Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the datascan are preserved. +* `google_dataplex_datascan_iam_member`: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the datascan are preserved. + +A data source can be used to retrieve policy data in advent you do not need creation + +* `google_dataplex_datascan_iam_policy`: Retrieves the IAM policy for the datascan + +~> **Note:** `google_dataplex_datascan_iam_policy` **cannot** be used in conjunction with `google_dataplex_datascan_iam_binding` and `google_dataplex_datascan_iam_member` or they will fight over what your policy should be. + +~> **Note:** `google_dataplex_datascan_iam_binding` resources **can be** used in conjunction with `google_dataplex_datascan_iam_member` resources **only if** they do not grant privilege to the same role. + + + + +## google\_dataplex\_datascan\_iam\_policy + +```hcl +data "google_iam_policy" "admin" { + binding { + role = "roles/viewer" + members = [ + "user:jane@example.com", + ] + } +} + +resource "google_dataplex_datascan_iam_policy" "policy" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id + policy_data = data.google_iam_policy.admin.policy_data +} +``` + +## google\_dataplex\_datascan\_iam\_binding + +```hcl +resource "google_dataplex_datascan_iam_binding" "binding" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id + role = "roles/viewer" + members = [ + "user:jane@example.com", + ] +} +``` + +## google\_dataplex\_datascan\_iam\_member + +```hcl +resource "google_dataplex_datascan_iam_member" "member" { + project = google_dataplex_datascan.basic_profile.project + location = google_dataplex_datascan.basic_profile.location + data_scan_id = google_dataplex_datascan.basic_profile.data_scan_id + role = "roles/viewer" + member = "user:jane@example.com" +} +``` + + +## Argument Reference + +The following arguments are supported: + +* `location` - (Required) The location where the data scan should reside. + Used to find the parent resource to bind the IAM policy to + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the project will be parsed from the identifier of the parent resource. If no project is provided in the parent identifier and no project is specified, the provider project is used. + +* `member/members` - (Required) Identities that will be granted the privilege in `role`. + Each entry can have one of the following values: + * **allUsers**: A special identifier that represents anyone who is on the internet; with or without a Google account. + * **allAuthenticatedUsers**: A special identifier that represents anyone who is authenticated with a Google account or a service account. + * **user:{emailid}**: An email address that represents a specific Google account. For example, alice@gmail.com or joe@example.com. + * **serviceAccount:{emailid}**: An email address that represents a service account. For example, my-other-app@appspot.gserviceaccount.com. + * **group:{emailid}**: An email address that represents a Google group. For example, admins@example.com. + * **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com. + * **projectOwner:projectid**: Owners of the given project. For example, "projectOwner:my-example-project" + * **projectEditor:projectid**: Editors of the given project. For example, "projectEditor:my-example-project" + * **projectViewer:projectid**: Viewers of the given project. For example, "projectViewer:my-example-project" + +* `role` - (Required) The role that should be applied. Only one + `google_dataplex_datascan_iam_binding` can be used per role. Note that custom roles must be of the format + `[projects|organizations]/{parent-name}/roles/{role-name}`. + +* `policy_data` - (Required only by `google_dataplex_datascan_iam_policy`) The policy data generated by + a `google_iam_policy` data source. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are +exported: + +* `etag` - (Computed) The etag of the IAM policy. + +## Import + +For all import syntaxes, the "resource in question" can take any of the following forms: + +* projects/{{project}}/locations/{{location}}/dataScans/{{data_scan_id}} +* {{project}}/{{location}}/{{data_scan_id}} +* {{location}}/{{data_scan_id}} +* {{data_scan_id}} + +Any variables not passed in the import command will be taken from the provider configuration. + +Dataplex datascan IAM resources can be imported using the resource identifiers, role, and member. + +IAM member imports use space-delimited identifiers: the resource in question, the role, and the member identity, e.g. +``` +$ terraform import google_dataplex_datascan_iam_member.editor "projects/{{project}}/locations/{{location}}/dataScans/{{data_scan_id}} roles/viewer user:jane@example.com" +``` + +IAM binding imports use space-delimited identifiers: the resource in question and the role, e.g. +``` +$ terraform import google_dataplex_datascan_iam_binding.editor "projects/{{project}}/locations/{{location}}/dataScans/{{data_scan_id}} roles/viewer" +``` + +IAM policy imports use the identifier of the resource in question, e.g. +``` +$ terraform import google_dataplex_datascan_iam_policy.editor projects/{{project}}/locations/{{location}}/dataScans/{{data_scan_id}} +``` + +-> **Custom Roles**: If you're importing a IAM resource with a custom role, make sure to use the + full name of the custom role, e.g. `[projects/my-project|organizations/my-org]/roles/my-custom-role`. + +## User Project Overrides + +This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).