From ccc8cdf9fb182c4357d6dd0ff025a32fb57977e5 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 15 Nov 2023 08:08:31 -0800 Subject: [PATCH] Adding IAM support in Terraform for Dataform Repository resource (#9457) (#6648) * Adding IAM support in Terraform for Dataform Repository resource * Adding primary_resource_name property to Example * Adding min-version: beta to IAM policy of repository resource * Update import id used in acceptance tests --------- [upstream:d7adf2e72dfaa14737ed4d1881bf1ac4af916bdf] Signed-off-by: Modular Magician --- .changelog/9457.txt | 3 + google-beta/provider/provider.go | 8 +- .../dataform/iam_dataform_repository.go | 245 +++++++++++ .../iam_dataform_repository_generated_test.go | 399 ++++++++++++++++++ ...taform_repository_iam_policy.html.markdown | 58 +++ .../r/dataform_repository_iam.html.markdown | 162 +++++++ 6 files changed, 873 insertions(+), 2 deletions(-) create mode 100644 .changelog/9457.txt create mode 100644 google-beta/services/dataform/iam_dataform_repository.go create mode 100644 google-beta/services/dataform/iam_dataform_repository_generated_test.go create mode 100644 website/docs/d/dataform_repository_iam_policy.html.markdown create mode 100644 website/docs/r/dataform_repository_iam.html.markdown diff --git a/.changelog/9457.txt b/.changelog/9457.txt new file mode 100644 index 0000000000..da426f6b72 --- /dev/null +++ b/.changelog/9457.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +dataform: added `google_dataform_repository_iam_*` IAM resources (beta) +``` diff --git a/google-beta/provider/provider.go b/google-beta/provider/provider.go index 09d4879545..c8798d21ef 100644 --- a/google-beta/provider/provider.go +++ b/google-beta/provider/provider.go @@ -1072,6 +1072,7 @@ func DatasourceMapWithErrors() (map[string]*schema.Resource, error) { "google_data_catalog_policy_tag_iam_policy": tpgiamresource.DataSourceIamPolicy(datacatalog.DataCatalogPolicyTagIamSchema, datacatalog.DataCatalogPolicyTagIamUpdaterProducer), "google_data_catalog_tag_template_iam_policy": tpgiamresource.DataSourceIamPolicy(datacatalog.DataCatalogTagTemplateIamSchema, datacatalog.DataCatalogTagTemplateIamUpdaterProducer), "google_data_catalog_taxonomy_iam_policy": tpgiamresource.DataSourceIamPolicy(datacatalog.DataCatalogTaxonomyIamSchema, datacatalog.DataCatalogTaxonomyIamUpdaterProducer), + "google_dataform_repository_iam_policy": tpgiamresource.DataSourceIamPolicy(dataform.DataformRepositoryIamSchema, dataform.DataformRepositoryIamUpdaterProducer), "google_data_fusion_instance_iam_policy": tpgiamresource.DataSourceIamPolicy(datafusion.DataFusionInstanceIamSchema, datafusion.DataFusionInstanceIamUpdaterProducer), "google_dataplex_asset_iam_policy": tpgiamresource.DataSourceIamPolicy(dataplex.DataplexAssetIamSchema, dataplex.DataplexAssetIamUpdaterProducer), "google_dataplex_datascan_iam_policy": tpgiamresource.DataSourceIamPolicy(dataplex.DataplexDatascanIamSchema, dataplex.DataplexDatascanIamUpdaterProducer), @@ -1146,8 +1147,8 @@ func DatasourceMapWithErrors() (map[string]*schema.Resource, error) { } // Generated resources: 396 -// Generated IAM resources: 240 -// Total generated resources: 636 +// Generated IAM resources: 243 +// Total generated resources: 639 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -1441,6 +1442,9 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_data_catalog_taxonomy_iam_member": tpgiamresource.ResourceIamMember(datacatalog.DataCatalogTaxonomyIamSchema, datacatalog.DataCatalogTaxonomyIamUpdaterProducer, datacatalog.DataCatalogTaxonomyIdParseFunc), "google_data_catalog_taxonomy_iam_policy": tpgiamresource.ResourceIamPolicy(datacatalog.DataCatalogTaxonomyIamSchema, datacatalog.DataCatalogTaxonomyIamUpdaterProducer, datacatalog.DataCatalogTaxonomyIdParseFunc), "google_dataform_repository": dataform.ResourceDataformRepository(), + "google_dataform_repository_iam_binding": tpgiamresource.ResourceIamBinding(dataform.DataformRepositoryIamSchema, dataform.DataformRepositoryIamUpdaterProducer, dataform.DataformRepositoryIdParseFunc), + "google_dataform_repository_iam_member": tpgiamresource.ResourceIamMember(dataform.DataformRepositoryIamSchema, dataform.DataformRepositoryIamUpdaterProducer, dataform.DataformRepositoryIdParseFunc), + "google_dataform_repository_iam_policy": tpgiamresource.ResourceIamPolicy(dataform.DataformRepositoryIamSchema, dataform.DataformRepositoryIamUpdaterProducer, dataform.DataformRepositoryIdParseFunc), "google_dataform_repository_release_config": dataform.ResourceDataformRepositoryReleaseConfig(), "google_dataform_repository_workflow_config": dataform.ResourceDataformRepositoryWorkflowConfig(), "google_data_fusion_instance": datafusion.ResourceDataFusionInstance(), diff --git a/google-beta/services/dataform/iam_dataform_repository.go b/google-beta/services/dataform/iam_dataform_repository.go new file mode 100644 index 0000000000..36edfbd7d5 --- /dev/null +++ b/google-beta/services/dataform/iam_dataform_repository.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 dataform + +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-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 DataformRepositoryIamSchema = map[string]*schema.Schema{ + "project": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "region": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "repository": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + }, +} + +type DataformRepositoryIamUpdater struct { + project string + region string + repository string + d tpgresource.TerraformResourceData + Config *transport_tpg.Config +} + +func DataformRepositoryIamUpdaterProducer(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 + region, _ := tpgresource.GetRegion(d, config) + if region != "" { + if err := d.Set("region", region); err != nil { + return nil, fmt.Errorf("Error setting region: %s", err) + } + } + values["region"] = region + if v, ok := d.GetOk("repository"); ok { + values["repository"] = 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[^/]+)/repositories/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("repository").(string)) + if err != nil { + return nil, err + } + + for k, v := range m { + values[k] = v + } + + u := &DataformRepositoryIamUpdater{ + project: values["project"], + region: values["region"], + repository: values["repository"], + 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("region", u.region); err != nil { + return nil, fmt.Errorf("Error setting region: %s", err) + } + if err := d.Set("repository", u.GetResourceId()); err != nil { + return nil, fmt.Errorf("Error setting repository: %s", err) + } + + return u, nil +} + +func DataformRepositoryIdParseFunc(d *schema.ResourceData, config *transport_tpg.Config) error { + values := make(map[string]string) + + project, _ := tpgresource.GetProject(d, config) + if project != "" { + values["project"] = project + } + + region, _ := tpgresource.GetRegion(d, config) + if region != "" { + values["region"] = region + } + + m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/repositories/(?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 := &DataformRepositoryIamUpdater{ + project: values["project"], + region: values["region"], + repository: values["repository"], + d: d, + Config: config, + } + if err := d.Set("repository", u.GetResourceId()); err != nil { + return fmt.Errorf("Error setting repository: %s", err) + } + d.SetId(u.GetResourceId()) + return nil +} + +func (u *DataformRepositoryIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { + url, err := u.qualifyRepositoryUrl("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 *DataformRepositoryIamUpdater) 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.qualifyRepositoryUrl("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 *DataformRepositoryIamUpdater) qualifyRepositoryUrl(methodIdentifier string) (string, error) { + urlTemplate := fmt.Sprintf("{{DataformBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/repositories/%s", u.project, u.region, u.repository), methodIdentifier) + url, err := tpgresource.ReplaceVars(u.d, u.Config, urlTemplate) + if err != nil { + return "", err + } + return url, nil +} + +func (u *DataformRepositoryIamUpdater) GetResourceId() string { + return fmt.Sprintf("projects/%s/locations/%s/repositories/%s", u.project, u.region, u.repository) +} + +func (u *DataformRepositoryIamUpdater) GetMutexKey() string { + return fmt.Sprintf("iam-dataform-repository-%s", u.GetResourceId()) +} + +func (u *DataformRepositoryIamUpdater) DescribeResource() string { + return fmt.Sprintf("dataform repository %q", u.GetResourceId()) +} diff --git a/google-beta/services/dataform/iam_dataform_repository_generated_test.go b/google-beta/services/dataform/iam_dataform_repository_generated_test.go new file mode 100644 index 0000000000..f65c6706df --- /dev/null +++ b/google-beta/services/dataform/iam_dataform_repository_generated_test.go @@ -0,0 +1,399 @@ +// 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 dataform_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" +) + +func TestAccDataformRepositoryIamBindingGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + "role": "roles/viewer", + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccDataformRepositoryIamBinding_basicGenerated(context), + }, + { + ResourceName: "google_dataform_repository_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_dataform_repository%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + // Test Iam Binding update + Config: testAccDataformRepositoryIamBinding_updateGenerated(context), + }, + { + ResourceName: "google_dataform_repository_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s roles/viewer", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_dataform_repository%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccDataformRepositoryIamMemberGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + "role": "roles/viewer", + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + Steps: []resource.TestStep{ + { + // Test Iam Member creation (no update for member, no need to test) + Config: testAccDataformRepositoryIamMember_basicGenerated(context), + }, + { + ResourceName: "google_dataform_repository_iam_member.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_dataform_repository%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccDataformRepositoryIamPolicyGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + "role": "roles/viewer", + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccDataformRepositoryIamPolicy_basicGenerated(context), + Check: resource.TestCheckResourceAttrSet("data.google_dataform_repository_iam_policy.foo", "policy_data"), + }, + { + ResourceName: "google_dataform_repository_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_dataform_repository%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDataformRepositoryIamPolicy_emptyBinding(context), + }, + { + ResourceName: "google_dataform_repository_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/repositories/%s", envvar.GetTestProjectFromEnv(), envvar.GetTestRegionFromEnv(), fmt.Sprintf("tf_test_dataform_repository%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccDataformRepositoryIamMember_basicGenerated(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_sourcerepo_repository" "git_repository" { + provider = google-beta + name = "my/repository%{random_suffix}" +} + +resource "google_secret_manager_secret" "secret" { + provider = google-beta + secret_id = "tf-test-my-secret%{random_suffix}" + + replication { + auto {} + } +} + +resource "google_secret_manager_secret_version" "secret_version" { + provider = google-beta + secret = google_secret_manager_secret.secret.id + + secret_data = "tf-test-secret-data%{random_suffix}" +} + +resource "google_dataform_repository" "dataform_respository" { + provider = google-beta + name = "tf_test_dataform_repository%{random_suffix}" + + git_remote_settings { + url = google_sourcerepo_repository.git_repository.url + default_branch = "main" + authentication_token_secret_version = google_secret_manager_secret_version.secret_version.id + } + + workspace_compilation_overrides { + default_database = "database" + schema_suffix = "_suffix" + table_prefix = "prefix_" + } +} + +resource "google_dataform_repository_iam_member" "foo" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name + role = "%{role}" + member = "user:admin@hashicorptest.com" +} +`, context) +} + +func testAccDataformRepositoryIamPolicy_basicGenerated(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_sourcerepo_repository" "git_repository" { + provider = google-beta + name = "my/repository%{random_suffix}" +} + +resource "google_secret_manager_secret" "secret" { + provider = google-beta + secret_id = "tf-test-my-secret%{random_suffix}" + + replication { + auto {} + } +} + +resource "google_secret_manager_secret_version" "secret_version" { + provider = google-beta + secret = google_secret_manager_secret.secret.id + + secret_data = "tf-test-secret-data%{random_suffix}" +} + +resource "google_dataform_repository" "dataform_respository" { + provider = google-beta + name = "tf_test_dataform_repository%{random_suffix}" + + git_remote_settings { + url = google_sourcerepo_repository.git_repository.url + default_branch = "main" + authentication_token_secret_version = google_secret_manager_secret_version.secret_version.id + } + + workspace_compilation_overrides { + default_database = "database" + schema_suffix = "_suffix" + table_prefix = "prefix_" + } +} + +data "google_iam_policy" "foo" { + provider = google-beta + binding { + role = "%{role}" + members = ["user:admin@hashicorptest.com"] + } +} + +resource "google_dataform_repository_iam_policy" "foo" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name + policy_data = data.google_iam_policy.foo.policy_data +} + +data "google_dataform_repository_iam_policy" "foo" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name + depends_on = [ + google_dataform_repository_iam_policy.foo + ] +} +`, context) +} + +func testAccDataformRepositoryIamPolicy_emptyBinding(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_sourcerepo_repository" "git_repository" { + provider = google-beta + name = "my/repository%{random_suffix}" +} + +resource "google_secret_manager_secret" "secret" { + provider = google-beta + secret_id = "tf-test-my-secret%{random_suffix}" + + replication { + auto {} + } +} + +resource "google_secret_manager_secret_version" "secret_version" { + provider = google-beta + secret = google_secret_manager_secret.secret.id + + secret_data = "tf-test-secret-data%{random_suffix}" +} + +resource "google_dataform_repository" "dataform_respository" { + provider = google-beta + name = "tf_test_dataform_repository%{random_suffix}" + + git_remote_settings { + url = google_sourcerepo_repository.git_repository.url + default_branch = "main" + authentication_token_secret_version = google_secret_manager_secret_version.secret_version.id + } + + workspace_compilation_overrides { + default_database = "database" + schema_suffix = "_suffix" + table_prefix = "prefix_" + } +} + +data "google_iam_policy" "foo" { + provider = google-beta +} + +resource "google_dataform_repository_iam_policy" "foo" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name + policy_data = data.google_iam_policy.foo.policy_data +} +`, context) +} + +func testAccDataformRepositoryIamBinding_basicGenerated(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_sourcerepo_repository" "git_repository" { + provider = google-beta + name = "my/repository%{random_suffix}" +} + +resource "google_secret_manager_secret" "secret" { + provider = google-beta + secret_id = "tf-test-my-secret%{random_suffix}" + + replication { + auto {} + } +} + +resource "google_secret_manager_secret_version" "secret_version" { + provider = google-beta + secret = google_secret_manager_secret.secret.id + + secret_data = "tf-test-secret-data%{random_suffix}" +} + +resource "google_dataform_repository" "dataform_respository" { + provider = google-beta + name = "tf_test_dataform_repository%{random_suffix}" + + git_remote_settings { + url = google_sourcerepo_repository.git_repository.url + default_branch = "main" + authentication_token_secret_version = google_secret_manager_secret_version.secret_version.id + } + + workspace_compilation_overrides { + default_database = "database" + schema_suffix = "_suffix" + table_prefix = "prefix_" + } +} + +resource "google_dataform_repository_iam_binding" "foo" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name + role = "%{role}" + members = ["user:admin@hashicorptest.com"] +} +`, context) +} + +func testAccDataformRepositoryIamBinding_updateGenerated(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_sourcerepo_repository" "git_repository" { + provider = google-beta + name = "my/repository%{random_suffix}" +} + +resource "google_secret_manager_secret" "secret" { + provider = google-beta + secret_id = "tf-test-my-secret%{random_suffix}" + + replication { + auto {} + } +} + +resource "google_secret_manager_secret_version" "secret_version" { + provider = google-beta + secret = google_secret_manager_secret.secret.id + + secret_data = "tf-test-secret-data%{random_suffix}" +} + +resource "google_dataform_repository" "dataform_respository" { + provider = google-beta + name = "tf_test_dataform_repository%{random_suffix}" + + git_remote_settings { + url = google_sourcerepo_repository.git_repository.url + default_branch = "main" + authentication_token_secret_version = google_secret_manager_secret_version.secret_version.id + } + + workspace_compilation_overrides { + default_database = "database" + schema_suffix = "_suffix" + table_prefix = "prefix_" + } +} + +resource "google_dataform_repository_iam_binding" "foo" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name + role = "%{role}" + members = ["user:admin@hashicorptest.com", "user:gterraformtest1@gmail.com"] +} +`, context) +} diff --git a/website/docs/d/dataform_repository_iam_policy.html.markdown b/website/docs/d/dataform_repository_iam_policy.html.markdown new file mode 100644 index 0000000000..f3e9303e58 --- /dev/null +++ b/website/docs/d/dataform_repository_iam_policy.html.markdown @@ -0,0 +1,58 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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: "Dataform" +description: |- + A datasource to retrieve the IAM policy state for Dataform Repository +--- + + +# `google_dataform_repository_iam_policy` +Retrieves the current IAM policy data for repository +~> **Warning:** This datasource is in beta, and should be used with the terraform-provider-google-beta provider. +See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources. + + + +## example + +```hcl +data "google_dataform_repository_iam_policy" "policy" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name +} +``` + +## Argument Reference + +The following arguments are supported: + +* `repository` - (Required) Used to find the parent resource to bind the IAM policy to +* `region` - (Optional) A reference to the region 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 region is provided in the parent identifier and no + region is specified, it is taken from the provider configuration. + +* `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_dataform_repository_iam_policy`) The policy data generated by + a `google_iam_policy` data source. diff --git a/website/docs/r/dataform_repository_iam.html.markdown b/website/docs/r/dataform_repository_iam.html.markdown new file mode 100644 index 0000000000..8207c8fac7 --- /dev/null +++ b/website/docs/r/dataform_repository_iam.html.markdown @@ -0,0 +1,162 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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: "Dataform" +description: |- + Collection of resources to manage IAM policy for Dataform Repository +--- + +# IAM policy for Dataform Repository +Three different resources help you manage your IAM policy for Dataform Repository. Each of these resources serves a different use case: + +* `google_dataform_repository_iam_policy`: Authoritative. Sets the IAM policy for the repository and replaces any existing policy already attached. +* `google_dataform_repository_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 repository are preserved. +* `google_dataform_repository_iam_member`: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the repository are preserved. + +A data source can be used to retrieve policy data in advent you do not need creation + +* `google_dataform_repository_iam_policy`: Retrieves the IAM policy for the repository + +~> **Note:** `google_dataform_repository_iam_policy` **cannot** be used in conjunction with `google_dataform_repository_iam_binding` and `google_dataform_repository_iam_member` or they will fight over what your policy should be. + +~> **Note:** `google_dataform_repository_iam_binding` resources **can be** used in conjunction with `google_dataform_repository_iam_member` resources **only if** they do not grant privilege to the same role. + + +~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider. +See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources. + + +## google\_dataform\_repository\_iam\_policy + +```hcl +data "google_iam_policy" "admin" { + provider = google-beta + binding { + role = "roles/viewer" + members = [ + "user:jane@example.com", + ] + } +} + +resource "google_dataform_repository_iam_policy" "policy" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name + policy_data = data.google_iam_policy.admin.policy_data +} +``` + +## google\_dataform\_repository\_iam\_binding + +```hcl +resource "google_dataform_repository_iam_binding" "binding" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name + role = "roles/viewer" + members = [ + "user:jane@example.com", + ] +} +``` + +## google\_dataform\_repository\_iam\_member + +```hcl +resource "google_dataform_repository_iam_member" "member" { + provider = google-beta + project = google_dataform_repository.dataform_respository.project + region = google_dataform_repository.dataform_respository.region + repository = google_dataform_repository.dataform_respository.name + role = "roles/viewer" + member = "user:jane@example.com" +} +``` + + +## Argument Reference + +The following arguments are supported: + +* `repository` - (Required) Used to find the parent resource to bind the IAM policy to +* `region` - (Optional) A reference to the region 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 region is provided in the parent identifier and no + region is specified, it is taken from the provider configuration. + +* `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_dataform_repository_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_dataform_repository_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/{{region}}/repositories/{{name}} +* {{project}}/{{region}}/{{name}} +* {{region}}/{{name}} +* {{name}} + +Any variables not passed in the import command will be taken from the provider configuration. + +Dataform repository 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_dataform_repository_iam_member.editor "projects/{{project}}/locations/{{region}}/repositories/{{repository}} 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_dataform_repository_iam_binding.editor "projects/{{project}}/locations/{{region}}/repositories/{{repository}} roles/viewer" +``` + +IAM policy imports use the identifier of the resource in question, e.g. +``` +$ terraform import google_dataform_repository_iam_policy.editor projects/{{project}}/locations/{{region}}/repositories/{{repository}} +``` + +-> **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).