From 2484a8b512bf2ac88c7daf56c44231f7448ea327 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 2 Jun 2026 18:47:09 +0000 Subject: [PATCH] Iam support dataplex data product (#17775) [upstream:22c66af552093e78b8745ba948629e0d27b20f6d] Signed-off-by: Modular Magician --- .changelog/17775.txt | 7 + .../dataplex/iam_dataplex_data_product.go | 295 +++++++++++++++ ...am_dataplex_data_product_generated_test.go | 347 ++++++++++++++++++ .../iam_dataplex_data_product_test.go | 83 +++++ .../resource_dataplex_data_product.go | 92 +++++ ..._dataplex_data_product_generated_meta.yaml | 2 + ...ce_dataplex_data_product_generated_test.go | 4 + ...plex_data_product_iam_policy.html.markdown | 59 +++ .../r/dataplex_data_product.html.markdown | 18 + .../r/dataplex_data_product_iam.html.markdown | 160 ++++++++ 10 files changed, 1067 insertions(+) create mode 100644 .changelog/17775.txt create mode 100644 google-beta/services/dataplex/iam_dataplex_data_product.go create mode 100644 google-beta/services/dataplex/iam_dataplex_data_product_generated_test.go create mode 100644 google-beta/services/dataplex/iam_dataplex_data_product_test.go create mode 100644 website/docs/d/dataplex_data_product_iam_policy.html.markdown create mode 100644 website/docs/r/dataplex_data_product_iam.html.markdown diff --git a/.changelog/17775.txt b/.changelog/17775.txt new file mode 100644 index 00000000000..0e964c6f4bf --- /dev/null +++ b/.changelog/17775.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +dataplex: added IAM support for `google_dataplex_data_product` (iam_policy, iam_binding, iam_member) +``` + +```release-note:enhancement +dataplex: added `access_approval_config` field to `google_dataplex_data_product` +``` \ No newline at end of file diff --git a/google-beta/services/dataplex/iam_dataplex_data_product.go b/google-beta/services/dataplex/iam_dataplex_data_product.go new file mode 100644 index 00000000000..ea2b683694f --- /dev/null +++ b/google-beta/services/dataplex/iam_dataplex_data_product.go @@ -0,0 +1,295 @@ +// Copyright IBM Corp. 2014, 2026 +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This code is generated by Magic Modules using the following: +// +// Configuration: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/dataplex/DataProduct.yaml +// Template: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/iam_policy.go.tmpl +// +// DO NOT EDIT this file directly. Any changes made to this file will be +// overwritten during the next generation cycle. +// +// ---------------------------------------------------------------------------- + +package dataplex + +import ( + "fmt" + "regexp" + "strings" + + "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-beta/google-beta/registry" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgiamresource" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" +) + +var ( + _ = regexp.Match + _ = strings.Trim + _ = errwrap.Wrap + _ = schema.Noop +) + +func init() { + registry.Schema{ + Name: "google_dataplex_data_product_iam_binding", + ProductName: "Dataplex", + Type: registry.SchemaTypeIAMResource, + Schema: tpgiamresource.ResourceIamBinding(DataplexDataProductIamSchema, DataplexDataProductIamUpdaterProducer, DataplexDataProductIdParseFunc), + }.Register() + registry.Schema{ + Name: "google_dataplex_data_product_iam_member", + ProductName: "Dataplex", + Type: registry.SchemaTypeIAMResource, + Schema: tpgiamresource.ResourceIamMember(DataplexDataProductIamSchema, DataplexDataProductIamUpdaterProducer, DataplexDataProductIdParseFunc, tpgiamresource.IamWithParentResourceIdentity(DataplexDataProductIamParentParentResourceIdentityParser)), + }.Register() + registry.Schema{ + Name: "google_dataplex_data_product_iam_policy", + ProductName: "Dataplex", + Type: registry.SchemaTypeIAMResource, + Schema: tpgiamresource.ResourceIamPolicy(DataplexDataProductIamSchema, DataplexDataProductIamUpdaterProducer, DataplexDataProductIdParseFunc), + }.Register() + registry.Schema{ + Name: "google_dataplex_data_product_iam_policy", + ProductName: "Dataplex", + Type: registry.SchemaTypeIAMDataSource, + Schema: tpgiamresource.DataSourceIamPolicy(DataplexDataProductIamSchema, DataplexDataProductIamUpdaterProducer), + }.Register() +} + +var DataplexDataProductIamSchema = 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_product_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + }, +} + +type DataplexDataProductIamUpdater struct { + project string + location string + dataProductId string + d tpgresource.TerraformResourceData + Config *transport_tpg.Config +} + +func DataplexDataProductIamUpdaterProducer(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (tpgiamresource.ResourceIamUpdater, error) { + values := make(map[string]string) + + project, _ := tpgresource.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, _ := tpgresource.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_product_id"); ok { + values["data_product_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[^/]+)/dataProducts/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("data_product_id").(string)) + if err != nil { + return nil, err + } + + for k, v := range m { + values[k] = v + } + + u := &DataplexDataProductIamUpdater{ + project: values["project"], + location: values["location"], + dataProductId: values["data_product_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_product_id", u.GetResourceId()); err != nil { + return nil, fmt.Errorf("Error setting data_product_id: %s", err) + } + + return u, nil +} + +func DataplexDataProductIdParseFunc(d *schema.ResourceData, config *transport_tpg.Config) error { + values := make(map[string]string) + + project, _ := tpgresource.GetProject(d, config) + if project != "" { + values["project"] = project + } + + location, _ := tpgresource.GetLocation(d, config) + if location != "" { + values["location"] = location + } + + m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/dataProducts/(?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 := &DataplexDataProductIamUpdater{ + project: values["project"], + location: values["location"], + dataProductId: values["data_product_id"], + d: d, + Config: config, + } + if err := d.Set("data_product_id", u.GetResourceId()); err != nil { + return fmt.Errorf("Error setting data_product_id: %s", err) + } + d.SetId(u.GetResourceId()) + return nil +} + +func (u *DataplexDataProductIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { + url, err := u.qualifyDataProductUrl("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, fmt.Errorf("Error retrieving IAM policy for %s: %w", u.DescribeResource(), err) + } + + out := &cloudresourcemanager.Policy{} + err = tpgresource.Convert(policy, out) + if err != nil { + return nil, fmt.Errorf("Cannot convert a policy to a resource manager policy: %w", err) + } + + return out, nil +} + +func (u *DataplexDataProductIamUpdater) 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.qualifyDataProductUrl("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 fmt.Errorf("Error setting IAM policy for %s: %w", u.DescribeResource(), err) + } + + return nil +} + +func (u *DataplexDataProductIamUpdater) qualifyDataProductUrl(methodIdentifier string) (string, error) { + urlTemplate := fmt.Sprintf("{{DataplexBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/dataProducts/%s", u.project, u.location, u.dataProductId), methodIdentifier) + url, err := tpgresource.ReplaceVars(u.d, u.Config, urlTemplate) + if err != nil { + return "", err + } + return url, nil +} + +func (u *DataplexDataProductIamUpdater) GetResourceId() string { + return fmt.Sprintf("projects/%s/locations/%s/dataProducts/%s", u.project, u.location, u.dataProductId) +} + +func DataplexDataProductIamParentParentResourceIdentityParser(d *schema.ResourceData, identity *schema.IdentityData, transportConfig *transport_tpg.Config) (string, error) { + return tpgiamresource.ParseIamResourceIdentity(d, identity, transportConfig, tpgiamresource.IamResourceIdentityConfig{ + Params: []tpgiamresource.IamIdentityParam{ + {Key: "project", IdentityKey: "project"}, + {Key: "location", IdentityKey: "location"}, + {Key: "dataProductId", IdentityKey: "data_product_id"}, + }, + UriFormat: "projects/%s/locations/%s/dataProducts/%s", + }) +} + +func (u *DataplexDataProductIamUpdater) GetMutexKey() string { + return fmt.Sprintf("iam-dataplex-dataproduct-%s", u.GetResourceId()) +} + +func (u *DataplexDataProductIamUpdater) DescribeResource() string { + return fmt.Sprintf("dataplex dataproduct %q", u.GetResourceId()) +} diff --git a/google-beta/services/dataplex/iam_dataplex_data_product_generated_test.go b/google-beta/services/dataplex/iam_dataplex_data_product_generated_test.go new file mode 100644 index 00000000000..3e09c0abdeb --- /dev/null +++ b/google-beta/services/dataplex/iam_dataplex_data_product_generated_test.go @@ -0,0 +1,347 @@ +// Copyright IBM Corp. 2014, 2026 +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This code is generated by Magic Modules using the following: +// +// Configuration: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/dataplex/DataProduct.yaml +// Template: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/samples/base_configs/iam_test_file.go.tmpl +// +// DO NOT EDIT this file directly. Any changes made to this file will be +// overwritten during the next generation cycle. +// +// ---------------------------------------------------------------------------- + +package dataplex_test + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" + _ "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/dataplex" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" +) + +var ( + _ = fmt.Sprintf + _ = strings.Trim + _ = envvar.TestEnvVar + _ = tpgresource.SetLabels +) + +func TestAccDataplexDataProductIamBindingGenerated(t *testing.T) { + t.Parallel() + + randomSuffix := acctest.RandString(t, 10) + + context := map[string]interface{}{ + "random_suffix": randomSuffix, + "role": "roles/viewer", + "project_name": envvar.GetTestProjectFromEnv(), + + "data_product_id": fmt.Sprintf("tf-test-dp%s", acctest.RandString(t, 10)), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccDataplexDataProductIamBinding_basicGenerated(context), + }, + { + // Test Iam Binding update + Config: testAccDataplexDataProductIamBinding_updateGenerated(context), + }, + }, + }) +} + +func TestAccDataplexDataProductIamMemberGenerated(t *testing.T) { + t.Parallel() + + randomSuffix := acctest.RandString(t, 10) + + context := map[string]interface{}{ + "random_suffix": randomSuffix, + "role": "roles/viewer", + "project_name": envvar.GetTestProjectFromEnv(), + + "data_product_id": fmt.Sprintf("tf-test-dp%s", acctest.RandString(t, 10)), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + // Test Iam Member creation (no update for member, no need to test) + Config: testAccDataplexDataProductIamMember_basicGenerated(context), + }, + }, + }) +} +func TestAccDataplexDataProductIamPolicyGenerated(t *testing.T) { + t.Parallel() + + randomSuffix := acctest.RandString(t, 10) + + context := map[string]interface{}{ + "random_suffix": randomSuffix, + "role": "roles/viewer", + "project_name": envvar.GetTestProjectFromEnv(), + + "data_product_id": fmt.Sprintf("tf-test-dp%s", acctest.RandString(t, 10)), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccDataplexDataProductIamPolicy_basicGenerated(context), + Check: resource.TestCheckResourceAttrSet("data.google_dataplex_data_product_iam_policy.foo", "policy_data"), + }, + { + Config: testAccDataplexDataProductIamPolicy_emptyBinding(context), + }, + }, + }) +} + +func testAccDataplexDataProductIamMember_basicGenerated(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_dataplex_data_product" "example" { + project = "%{project_name}" + location = "us-central1" + data_product_id = "%{data_product_id}" + display_name = "terraform data product" + + owner_emails = ["gterraformtestuser@gmail.com"] + + access_groups { + id = "analyst" + group_id = "analyst" + display_name = "Data Analyst" + principal { + google_group = "tf-test-analysts-%{random_suffix}@example.com" + } + } + +} + +resource "google_dataplex_data_product_iam_member" "foo" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id + role = "%{role}" + member = "user:admin@hashicorptest.com" +} +`, context) +} + +func testAccDataplexDataProductIamPolicy_basicGenerated(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_dataplex_data_product" "example" { + project = "%{project_name}" + location = "us-central1" + data_product_id = "%{data_product_id}" + display_name = "terraform data product" + + owner_emails = ["gterraformtestuser@gmail.com"] + + access_groups { + id = "analyst" + group_id = "analyst" + display_name = "Data Analyst" + principal { + google_group = "tf-test-analysts-%{random_suffix}@example.com" + } + } + +} + +data "google_iam_policy" "foo" { + binding { + role = "%{role}" + members = ["user:admin@hashicorptest.com"] + } +} + +resource "google_dataplex_data_product_iam_policy" "foo" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id + policy_data = data.google_iam_policy.foo.policy_data +} + +data "google_dataplex_data_product_iam_policy" "foo" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id + depends_on = [ + google_dataplex_data_product_iam_policy.foo + ] +} +`, context) +} + +func testAccDataplexDataProductIamPolicy_emptyBinding(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_dataplex_data_product" "example" { + project = "%{project_name}" + location = "us-central1" + data_product_id = "%{data_product_id}" + display_name = "terraform data product" + + owner_emails = ["gterraformtestuser@gmail.com"] + + access_groups { + id = "analyst" + group_id = "analyst" + display_name = "Data Analyst" + principal { + google_group = "tf-test-analysts-%{random_suffix}@example.com" + } + } + +} + +data "google_iam_policy" "foo" { +} + +resource "google_dataplex_data_product_iam_policy" "foo" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id + policy_data = data.google_iam_policy.foo.policy_data +} +`, context) +} + +func testAccDataplexDataProductIamBinding_basicGenerated(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_dataplex_data_product" "example" { + project = "%{project_name}" + location = "us-central1" + data_product_id = "%{data_product_id}" + display_name = "terraform data product" + + owner_emails = ["gterraformtestuser@gmail.com"] + + access_groups { + id = "analyst" + group_id = "analyst" + display_name = "Data Analyst" + principal { + google_group = "tf-test-analysts-%{random_suffix}@example.com" + } + } + +} + +resource "google_dataplex_data_product_iam_binding" "foo" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id + role = "%{role}" + members = ["user:admin@hashicorptest.com"] +} +`, context) +} + +func testAccDataplexDataProductIamBinding_updateGenerated(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_dataplex_data_product" "example" { + project = "%{project_name}" + location = "us-central1" + data_product_id = "%{data_product_id}" + display_name = "terraform data product" + + owner_emails = ["gterraformtestuser@gmail.com"] + + access_groups { + id = "analyst" + group_id = "analyst" + display_name = "Data Analyst" + principal { + google_group = "tf-test-analysts-%{random_suffix}@example.com" + } + } + +} + +resource "google_dataplex_data_product_iam_binding" "foo" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id + role = "%{role}" + members = ["user:admin@hashicorptest.com", "user:gterraformtest1@gmail.com"] +} +`, context) +} + +func generateDataplexDataProductIAMPolicyStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_product_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_product_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataProducts/%s", project, location, data_product_id), "", "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexDataProductIAMBindingStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_product_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_product_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataProducts/%s", project, location, data_product_id), rawState["role"], "", rawState["condition.0.title"]), nil + } +} + +func generateDataplexDataProductIAMMemberStateID(iamResourceAddr string) func(*terraform.State) (string, error) { + return func(state *terraform.State) (string, error) { + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[iamResourceAddr]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s\n", rawState) + project := tpgresource.GetResourceNameFromSelfLink(rawState["project"]) + location := tpgresource.GetResourceNameFromSelfLink(rawState["location"]) + data_product_id := tpgresource.GetResourceNameFromSelfLink(rawState["data_product_id"]) + return acctest.BuildIAMImportId(fmt.Sprintf("projects/%s/locations/%s/dataProducts/%s", project, location, data_product_id), rawState["role"], rawState["member"], rawState["condition.0.title"]), nil + } +} diff --git a/google-beta/services/dataplex/iam_dataplex_data_product_test.go b/google-beta/services/dataplex/iam_dataplex_data_product_test.go new file mode 100644 index 00000000000..b4740651894 --- /dev/null +++ b/google-beta/services/dataplex/iam_dataplex_data_product_test.go @@ -0,0 +1,83 @@ +// Copyright IBM Corp. 2014, 2026 +// SPDX-License-Identifier: MPL-2.0 +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: Handwritten *** +// +// ---------------------------------------------------------------------------- +// +// This code is generated by Magic Modules using the following: +// +// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/dataplex/iam_dataplex_data_product_test.go +// +// DO NOT EDIT this file directly. Any changes made to this file will be +// overwritten during the next generation cycle. +// +// ---------------------------------------------------------------------------- +package dataplex_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" +) + +func TestAccDataplexDataProductIamMember_basic(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "data_product_id": "tf-test-dp-" + acctest.RandString(t, 10), + "role": "roles/dataplex.dataProductsViewer", + "member": "user:okvidhi@google.com", + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccDataplexDataProductIamMember_basic(context), + }, + { + ResourceName: "google_dataplex_data_product_iam_member.member", + ImportState: true, + ImportStateVerify: true, + // FIX: Added function to construct the space-separated import ID + ImportStateIdFunc: testAccDataplexDataProductIamMemberImportStateId("google_dataplex_data_product_iam_member.member"), + }, + }, + }) +} + +// Helper to build the "resource_name role member" string required for import +func testAccDataplexDataProductIamMemberImportStateId(resourceName string) func(*terraform.State) (string, error) { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("Not found: %s", resourceName) + } + + return fmt.Sprintf("%s %s %s", rs.Primary.Attributes["data_product_id"], rs.Primary.Attributes["role"], rs.Primary.Attributes["member"]), nil + } +} + +func testAccDataplexDataProductIamMember_basic(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_dataplex_data_product" "example" { + location = "us-central1" + data_product_id = "%{data_product_id}" + display_name = "iam test product" + owner_emails = ["terraform-test@google.com"] +} + +resource "google_dataplex_data_product_iam_member" "member" { + # Passes the parent's full .name attribute to satisfy Dataplex identity rules + data_product_id = google_dataplex_data_product.example.name + role = "%{role}" + member = "%{member}" +} +`, context) +} diff --git a/google-beta/services/dataplex/resource_dataplex_data_product.go b/google-beta/services/dataplex/resource_dataplex_data_product.go index 41492b8bafc..a805029c645 100644 --- a/google-beta/services/dataplex/resource_dataplex_data_product.go +++ b/google-beta/services/dataplex/resource_dataplex_data_product.go @@ -168,6 +168,24 @@ func ResourceDataplexDataProduct() *schema.Resource { Type: schema.TypeString, }, }, + "access_approval_config": { + Type: schema.TypeList, + Optional: true, + Description: `Configuration for access approval for the data product.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "approver_emails": { + Type: schema.TypeList, + Optional: true, + Description: `Specifies the email addresses of users who are potential approvers.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, "access_groups": { Type: schema.TypeSet, Optional: true, @@ -251,6 +269,11 @@ Please refer to the field 'effective_labels' for all of the labels present on th Computed: true, Description: `Checksum for concurrency control.`, }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: `The relative resource name of the data product.`, + }, "terraform_labels": { Type: schema.TypeMap, Computed: true, @@ -299,6 +322,12 @@ func resourceDataplexDataProductCreate(d *schema.ResourceData, meta interface{}) } obj := make(map[string]interface{}) + accessApprovalConfigProp, err := expandDataplexDataProductAccessApprovalConfig(d.Get("access_approval_config"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("access_approval_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(accessApprovalConfigProp)) && (ok || !reflect.DeepEqual(v, accessApprovalConfigProp)) { + obj["accessApprovalConfig"] = accessApprovalConfigProp + } displayNameProp, err := expandDataplexDataProductDisplayName(d.Get("display_name"), d, config) if err != nil { return err @@ -545,6 +574,12 @@ func resourceDataplexDataProductUpdate(d *schema.ResourceData, meta interface{}) billingProject = project obj := make(map[string]interface{}) + accessApprovalConfigProp, err := expandDataplexDataProductAccessApprovalConfig(d.Get("access_approval_config"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("access_approval_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, accessApprovalConfigProp)) { + obj["accessApprovalConfig"] = accessApprovalConfigProp + } displayNameProp, err := expandDataplexDataProductDisplayName(d.Get("display_name"), d, config) if err != nil { return err @@ -585,6 +620,10 @@ func resourceDataplexDataProductUpdate(d *schema.ResourceData, meta interface{}) headers := make(http.Header) updateMask := []string{} + if d.HasChange("access_approval_config") { + updateMask = append(updateMask, "accessApprovalConfig") + } + if d.HasChange("display_name") { updateMask = append(updateMask, "displayName") } @@ -729,10 +768,31 @@ func resourceDataplexDataProductImport(d *schema.ResourceData, meta interface{}) return []*schema.ResourceData{d}, nil } +func flattenDataplexDataProductName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenDataplexDataProductUid(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } +func flattenDataplexDataProductAccessApprovalConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["approver_emails"] = + flattenDataplexDataProductAccessApprovalConfigApproverEmails(original["approverEmails"], d, config) + return []interface{}{transformed} +} +func flattenDataplexDataProductAccessApprovalConfigApproverEmails(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenDataplexDataProductDisplayName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } @@ -861,6 +921,32 @@ func flattenDataplexDataProductEffectiveLabels(v interface{}, d *schema.Resource return v } +func expandDataplexDataProductAccessApprovalConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + if v == nil { + return nil, nil + } + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedApproverEmails, err := expandDataplexDataProductAccessApprovalConfigApproverEmails(original["approver_emails"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedApproverEmails); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["approverEmails"] = transformedApproverEmails + } + + return transformed, nil +} + +func expandDataplexDataProductAccessApprovalConfigApproverEmails(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandDataplexDataProductDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { return v, nil } @@ -982,9 +1068,15 @@ func expandDataplexDataProductEffectiveLabels(v interface{}, d tpgresource.Terra func ResourceDataplexDataProductFlatten(d *schema.ResourceData, meta interface{}, res map[string]interface{}, config *transport_tpg.Config, project string, userAgent string, billingProject string, url string, headers http.Header) error { var err error + if err = d.Set("name", flattenDataplexDataProductName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error reading DataProduct: %s", err) + } if err = d.Set("uid", flattenDataplexDataProductUid(res["uid"], d, config)); err != nil { return fmt.Errorf("Error reading DataProduct: %s", err) } + if err = d.Set("access_approval_config", flattenDataplexDataProductAccessApprovalConfig(res["accessApprovalConfig"], d, config)); err != nil { + return fmt.Errorf("Error reading DataProduct: %s", err) + } if err = d.Set("display_name", flattenDataplexDataProductDisplayName(res["displayName"], d, config)); err != nil { return fmt.Errorf("Error reading DataProduct: %s", err) } diff --git a/google-beta/services/dataplex/resource_dataplex_data_product_generated_meta.yaml b/google-beta/services/dataplex/resource_dataplex_data_product_generated_meta.yaml index fe77e4f595a..74b06e1798c 100644 --- a/google-beta/services/dataplex/resource_dataplex_data_product_generated_meta.yaml +++ b/google-beta/services/dataplex/resource_dataplex_data_product_generated_meta.yaml @@ -7,6 +7,7 @@ api_service_name: dataplex.googleapis.com api_version: v1 api_resource_type_kind: DataProduct fields: + - api_field: accessApprovalConfig.approverEmails - api_field: accessGroups.key field: access_groups.id - api_field: accessGroups.value.description @@ -31,6 +32,7 @@ fields: - api_field: labels - field: location provider_only: true + - api_field: name - api_field: ownerEmails - field: terraform_labels provider_only: true diff --git a/google-beta/services/dataplex/resource_dataplex_data_product_generated_test.go b/google-beta/services/dataplex/resource_dataplex_data_product_generated_test.go index 7d9268e6014..6d56bc7e4dd 100644 --- a/google-beta/services/dataplex/resource_dataplex_data_product_generated_test.go +++ b/google-beta/services/dataplex/resource_dataplex_data_product_generated_test.go @@ -164,6 +164,10 @@ resource "google_dataplex_data_product" "example" { owner_emails = ["gterraformtestuser@gmail.com"] + access_approval_config { + approver_emails = ["gterraformtestuser@gmail.com"] + } + labels = { env = "manual-test" } diff --git a/website/docs/d/dataplex_data_product_iam_policy.html.markdown b/website/docs/d/dataplex_data_product_iam_policy.html.markdown new file mode 100644 index 00000000000..fcbbf84739f --- /dev/null +++ b/website/docs/d/dataplex_data_product_iam_policy.html.markdown @@ -0,0 +1,59 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This code is generated by Magic Modules using the following: +# +# Configuration: https:#github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/dataplex/DataProduct.yaml +# Template: https:#github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/datasource_iam.html.markdown.tmpl +# +# DO NOT EDIT this file directly. Any changes made to this file will be +# overwritten during the next generation cycle. +# +# ---------------------------------------------------------------------------- +subcategory: "Dataplex" +description: |- + A datasource to retrieve the IAM policy state for Dataplex DataProduct +--- + + +# google_dataplex_data_product_iam_policy + +Retrieves the current IAM policy data for dataproduct + + +## Example Usage + + +```hcl +data "google_dataplex_data_product_iam_policy" "policy" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `location` - (Optional) The location for the data product. + Used to find the parent resource to bind the IAM policy to. If not specified, + the value will be parsed from the identifier of the parent resource. If no location is provided in the parent identifier and no + location is specified, it is taken from the provider configuration. +* `data_product_id` - (Required) 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_data_product_iam_policy`) The policy data generated by + a `google_iam_policy` data source. diff --git a/website/docs/r/dataplex_data_product.html.markdown b/website/docs/r/dataplex_data_product.html.markdown index 9426100b0f3..694367a286d 100644 --- a/website/docs/r/dataplex_data_product.html.markdown +++ b/website/docs/r/dataplex_data_product.html.markdown @@ -75,6 +75,10 @@ resource "google_dataplex_data_product" "example" { owner_emails = ["gterraformtestuser@gmail.com"] + access_approval_config { + approver_emails = ["gterraformtestuser@gmail.com"] + } + labels = { env = "manual-test" } @@ -123,6 +127,11 @@ The following arguments are supported: The ID of the data product. +* `access_approval_config` - + (Optional) + Configuration for access approval for the data product. + Structure is [documented below](#nested_access_approval_config). + * `labels` - (Optional) User-defined labels. @@ -149,6 +158,12 @@ The following arguments are supported: When set to "DELETE", deleting the resource is allowed. +The `access_approval_config` block supports: + +* `approver_emails` - + (Optional) + Specifies the email addresses of users who are potential approvers. + The `access_groups` block supports: * `id` - (Required) The identifier for this object. Format specified above. @@ -187,6 +202,9 @@ In addition to the arguments listed above, the following computed attributes are * `id` - an identifier for the resource with format `projects/{{project}}/locations/{{location}}/dataProducts/{{data_product_id}}` +* `name` - + The relative resource name of the data product. + * `uid` - System generated unique ID. diff --git a/website/docs/r/dataplex_data_product_iam.html.markdown b/website/docs/r/dataplex_data_product_iam.html.markdown new file mode 100644 index 00000000000..5e90a123045 --- /dev/null +++ b/website/docs/r/dataplex_data_product_iam.html.markdown @@ -0,0 +1,160 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This code is generated by Magic Modules using the following: +# +# Configuration: https:#github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/dataplex/DataProduct.yaml +# Template: https:#github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/resource_iam.html.markdown.tmpl +# +# DO NOT EDIT this file directly. Any changes made to this file will be +# overwritten during the next generation cycle. +# +# ---------------------------------------------------------------------------- +subcategory: "Dataplex" +description: |- + Collection of resources to manage IAM policy for Dataplex DataProduct +--- + +# IAM policy for Dataplex DataProduct + +Three different resources help you manage your IAM policy for Dataplex DataProduct. Each of these resources serves a different use case: + +* `google_dataplex_data_product_iam_policy`: Authoritative. Sets the IAM policy for the dataproduct and replaces any existing policy already attached. +* `google_dataplex_data_product_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 dataproduct are preserved. +* `google_dataplex_data_product_iam_member`: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the dataproduct are preserved. + +A data source can be used to retrieve policy data in advent you do not need creation + +* `google_dataplex_data_product_iam_policy`: Retrieves the IAM policy for the dataproduct + +~> **Note:** `google_dataplex_data_product_iam_policy` **cannot** be used in conjunction with `google_dataplex_data_product_iam_binding` and `google_dataplex_data_product_iam_member` or they will fight over what your policy should be. + +~> **Note:** `google_dataplex_data_product_iam_binding` resources **can be** used in conjunction with `google_dataplex_data_product_iam_member` resources **only if** they do not grant privilege to the same role. + + + +## google_dataplex_data_product_iam_policy + +```hcl +data "google_iam_policy" "admin" { + binding { + role = "roles/viewer" + members = [ + "user:jane@example.com", + ] + } +} + +resource "google_dataplex_data_product_iam_policy" "policy" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id + policy_data = data.google_iam_policy.admin.policy_data +} +``` + +## google_dataplex_data_product_iam_binding + +```hcl +resource "google_dataplex_data_product_iam_binding" "binding" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id + role = "roles/viewer" + members = [ + "user:jane@example.com", + ] +} +``` + +## google_dataplex_data_product_iam_member + +```hcl +resource "google_dataplex_data_product_iam_member" "member" { + project = google_dataplex_data_product.example.project + location = google_dataplex_data_product.example.location + data_product_id = google_dataplex_data_product.example.data_product_id + role = "roles/viewer" + member = "user:jane@example.com" +} +``` + + +## Argument Reference + +The following arguments are supported: + +* `location` - (Optional) The location for the data product. + Used to find the parent resource to bind the IAM policy to. If not specified, + the value will be parsed from the identifier of the parent resource. If no location is provided in the parent identifier and no + location is specified, it is taken from the provider configuration. +* `data_product_id` - (Required) 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" + * **Federated identities**: One or more federated identities in a workload or workforce identity pool, workload running on GKE, etc. Refer to the [Principal identifiers documentation](https://cloud.google.com/iam/docs/principal-identifiers#allow) for examples of targets and valid configuration. For example, "principal://iam.googleapis.com/locations/global/workforcePools/example-contractors/subject/joe@example.com" + +* `role` - (Required) The role that should be applied. Only one + `google_dataplex_data_product_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_data_product_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}}/dataProducts/{{data_product_id}} +* {{project}}/{{location}}/{{data_product_id}} +* {{location}}/{{data_product_id}} +* {{data_product_id}} + +Any variables not passed in the import command will be taken from the provider configuration. + +Dataplex dataproduct 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_data_product_iam_member.editor "projects/{{project}}/locations/{{location}}/dataProducts/{{data_product_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_data_product_iam_binding.editor "projects/{{project}}/locations/{{location}}/dataProducts/{{data_product_id}} roles/viewer" +``` + +IAM policy imports use the identifier of the resource in question, e.g. +``` +$ terraform import google_dataplex_data_product_iam_policy.editor projects/{{project}}/locations/{{location}}/dataProducts/{{data_product_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).