From 4f0e4faec0522594b1364c205d23a3c4fca96d68 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 1 Jul 2022 10:00:18 -0700 Subject: [PATCH] Dataproc ASP iam (#6209) (#12008) Signed-off-by: Modular Magician --- .changelog/6209.txt | 9 + google/iam_dataproc_autoscaling_policy.go | 222 ++++++++++++++ ...aproc_autoscaling_policy_generated_test.go | 275 ++++++++++++++++++ google/provider.go | 7 +- ...aproc_autoscaling_policy_generated_test.go | 47 +++ ...aproc_autoscaling_policy_iam.html.markdown | 157 ++++++++++ website/google.erb | 4 + 7 files changed, 719 insertions(+), 2 deletions(-) create mode 100644 .changelog/6209.txt create mode 100644 google/iam_dataproc_autoscaling_policy.go create mode 100644 google/iam_dataproc_autoscaling_policy_generated_test.go create mode 100644 website/docs/r/dataproc_autoscaling_policy_iam.html.markdown diff --git a/.changelog/6209.txt b/.changelog/6209.txt new file mode 100644 index 00000000000..025c420ed8c --- /dev/null +++ b/.changelog/6209.txt @@ -0,0 +1,9 @@ +```release-note:new-resource +google_dataproc_autoscaling_policy_iam_member +``` +```release-note:new-resource +google_dataproc_autoscaling_policy_iam_binding +``` +```release-note:new-resource +google_dataproc_autoscaling_policy_iam_policy +``` diff --git a/google/iam_dataproc_autoscaling_policy.go b/google/iam_dataproc_autoscaling_policy.go new file mode 100644 index 00000000000..85a7ab87019 --- /dev/null +++ b/google/iam_dataproc_autoscaling_policy.go @@ -0,0 +1,222 @@ +// ---------------------------------------------------------------------------- +// +// *** 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" +) + +var DataprocAutoscalingPolicyIamSchema = map[string]*schema.Schema{ + "project": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "location": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "policy_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, +} + +type DataprocAutoscalingPolicyIamUpdater struct { + project string + location string + policyId string + d TerraformResourceData + Config *Config +} + +func DataprocAutoscalingPolicyIamUpdaterProducer(d TerraformResourceData, config *Config) (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("policy_id"); ok { + values["policy_id"] = v.(string) + } + + // We may have gotten either a long or short name, so attempt to parse long name if possible + m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/autoscalingPolicies/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("policy_id").(string)) + if err != nil { + return nil, err + } + + for k, v := range m { + values[k] = v + } + + u := &DataprocAutoscalingPolicyIamUpdater{ + project: values["project"], + location: values["location"], + policyId: values["policy_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("policy_id", u.GetResourceId()); err != nil { + return nil, fmt.Errorf("Error setting policy_id: %s", err) + } + + return u, nil +} + +func DataprocAutoscalingPolicyIdParseFunc(d *schema.ResourceData, config *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 := getImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/autoscalingPolicies/(?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 := &DataprocAutoscalingPolicyIamUpdater{ + project: values["project"], + location: values["location"], + policyId: values["policy_id"], + d: d, + Config: config, + } + if err := d.Set("policy_id", u.GetResourceId()); err != nil { + return fmt.Errorf("Error setting policy_id: %s", err) + } + d.SetId(u.GetResourceId()) + return nil +} + +func (u *DataprocAutoscalingPolicyIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { + url, err := u.qualifyAutoscalingPolicyUrl("getIamPolicy") + if err != nil { + return nil, err + } + + project, err := getProject(u.d, u.Config) + if err != nil { + return nil, err + } + var obj map[string]interface{} + + userAgent, err := generateUserAgentString(u.d, u.Config.userAgent) + if err != nil { + return nil, err + } + + policy, err := sendRequest(u.Config, "POST", project, url, userAgent, obj) + if err != nil { + return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err) + } + + out := &cloudresourcemanager.Policy{} + err = 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 *DataprocAutoscalingPolicyIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error { + json, err := ConvertToMap(policy) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + obj["policy"] = json + + url, err := u.qualifyAutoscalingPolicyUrl("setIamPolicy") + if err != nil { + return err + } + project, err := getProject(u.d, u.Config) + if err != nil { + return err + } + + userAgent, err := generateUserAgentString(u.d, u.Config.userAgent) + if err != nil { + return err + } + + _, err = sendRequestWithTimeout(u.Config, "POST", project, url, userAgent, obj, 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 *DataprocAutoscalingPolicyIamUpdater) qualifyAutoscalingPolicyUrl(methodIdentifier string) (string, error) { + urlTemplate := fmt.Sprintf("{{DataprocBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", u.project, u.location, u.policyId), methodIdentifier) + url, err := replaceVars(u.d, u.Config, urlTemplate) + if err != nil { + return "", err + } + return url, nil +} + +func (u *DataprocAutoscalingPolicyIamUpdater) GetResourceId() string { + return fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", u.project, u.location, u.policyId) +} + +func (u *DataprocAutoscalingPolicyIamUpdater) GetMutexKey() string { + return fmt.Sprintf("iam-dataproc-autoscalingpolicy-%s", u.GetResourceId()) +} + +func (u *DataprocAutoscalingPolicyIamUpdater) DescribeResource() string { + return fmt.Sprintf("dataproc autoscalingpolicy %q", u.GetResourceId()) +} diff --git a/google/iam_dataproc_autoscaling_policy_generated_test.go b/google/iam_dataproc_autoscaling_policy_generated_test.go new file mode 100644 index 00000000000..8016b08331b --- /dev/null +++ b/google/iam_dataproc_autoscaling_policy_generated_test.go @@ -0,0 +1,275 @@ +// ---------------------------------------------------------------------------- +// +// *** 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" +) + +func TestAccDataprocAutoscalingPolicyIamBindingGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "role": "roles/viewer", + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataprocAutoscalingPolicyIamBinding_basicGenerated(context), + }, + { + ResourceName: "google_dataproc_autoscaling_policy_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s roles/viewer", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + // Test Iam Binding update + Config: testAccDataprocAutoscalingPolicyIamBinding_updateGenerated(context), + }, + { + ResourceName: "google_dataproc_autoscaling_policy_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s roles/viewer", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccDataprocAutoscalingPolicyIamMemberGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "role": "roles/viewer", + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + // Test Iam Member creation (no update for member, no need to test) + Config: testAccDataprocAutoscalingPolicyIamMember_basicGenerated(context), + }, + { + ResourceName: "google_dataproc_autoscaling_policy_iam_member.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s roles/viewer user:admin@hashicorptest.com", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccDataprocAutoscalingPolicyIamPolicyGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "role": "roles/viewer", + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataprocAutoscalingPolicyIamPolicy_basicGenerated(context), + }, + { + ResourceName: "google_dataproc_autoscaling_policy_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDataprocAutoscalingPolicyIamPolicy_emptyBinding(context), + }, + { + ResourceName: "google_dataproc_autoscaling_policy_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/autoscalingPolicies/%s", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-dataproc-policy%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccDataprocAutoscalingPolicyIamMember_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataproc_autoscaling_policy" "basic" { + policy_id = "tf-test-dataproc-policy%{random_suffix}" + location = "us-central1" + + worker_config { + max_instances = 3 + } + + basic_algorithm { + yarn_config { + graceful_decommission_timeout = "30s" + + scale_up_factor = 0.5 + scale_down_factor = 0.5 + } + } +} + +resource "google_dataproc_autoscaling_policy_iam_member" "foo" { + project = google_dataproc_autoscaling_policy.basic.project + location = google_dataproc_autoscaling_policy.basic.location + policy_id = google_dataproc_autoscaling_policy.basic.policy_id + role = "%{role}" + member = "user:admin@hashicorptest.com" +} +`, context) +} + +func testAccDataprocAutoscalingPolicyIamPolicy_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataproc_autoscaling_policy" "basic" { + policy_id = "tf-test-dataproc-policy%{random_suffix}" + location = "us-central1" + + worker_config { + max_instances = 3 + } + + basic_algorithm { + yarn_config { + graceful_decommission_timeout = "30s" + + scale_up_factor = 0.5 + scale_down_factor = 0.5 + } + } +} + +data "google_iam_policy" "foo" { + binding { + role = "%{role}" + members = ["user:admin@hashicorptest.com"] + } +} + +resource "google_dataproc_autoscaling_policy_iam_policy" "foo" { + project = google_dataproc_autoscaling_policy.basic.project + location = google_dataproc_autoscaling_policy.basic.location + policy_id = google_dataproc_autoscaling_policy.basic.policy_id + policy_data = data.google_iam_policy.foo.policy_data +} +`, context) +} + +func testAccDataprocAutoscalingPolicyIamPolicy_emptyBinding(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataproc_autoscaling_policy" "basic" { + policy_id = "tf-test-dataproc-policy%{random_suffix}" + location = "us-central1" + + worker_config { + max_instances = 3 + } + + basic_algorithm { + yarn_config { + graceful_decommission_timeout = "30s" + + scale_up_factor = 0.5 + scale_down_factor = 0.5 + } + } +} + +data "google_iam_policy" "foo" { +} + +resource "google_dataproc_autoscaling_policy_iam_policy" "foo" { + project = google_dataproc_autoscaling_policy.basic.project + location = google_dataproc_autoscaling_policy.basic.location + policy_id = google_dataproc_autoscaling_policy.basic.policy_id + policy_data = data.google_iam_policy.foo.policy_data +} +`, context) +} + +func testAccDataprocAutoscalingPolicyIamBinding_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataproc_autoscaling_policy" "basic" { + policy_id = "tf-test-dataproc-policy%{random_suffix}" + location = "us-central1" + + worker_config { + max_instances = 3 + } + + basic_algorithm { + yarn_config { + graceful_decommission_timeout = "30s" + + scale_up_factor = 0.5 + scale_down_factor = 0.5 + } + } +} + +resource "google_dataproc_autoscaling_policy_iam_binding" "foo" { + project = google_dataproc_autoscaling_policy.basic.project + location = google_dataproc_autoscaling_policy.basic.location + policy_id = google_dataproc_autoscaling_policy.basic.policy_id + role = "%{role}" + members = ["user:admin@hashicorptest.com"] +} +`, context) +} + +func testAccDataprocAutoscalingPolicyIamBinding_updateGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataproc_autoscaling_policy" "basic" { + policy_id = "tf-test-dataproc-policy%{random_suffix}" + location = "us-central1" + + worker_config { + max_instances = 3 + } + + basic_algorithm { + yarn_config { + graceful_decommission_timeout = "30s" + + scale_up_factor = 0.5 + scale_down_factor = 0.5 + } + } +} + +resource "google_dataproc_autoscaling_policy_iam_binding" "foo" { + project = google_dataproc_autoscaling_policy.basic.project + location = google_dataproc_autoscaling_policy.basic.location + policy_id = google_dataproc_autoscaling_policy.basic.policy_id + role = "%{role}" + members = ["user:admin@hashicorptest.com", "user:gterraformtest1@gmail.com"] +} +`, context) +} diff --git a/google/provider.go b/google/provider.go index 3223b8efe93..ec2bda26568 100644 --- a/google/provider.go +++ b/google/provider.go @@ -847,8 +847,8 @@ func Provider() *schema.Provider { } // Generated resources: 222 -// Generated IAM resources: 114 -// Total generated resources: 336 +// Generated IAM resources: 117 +// Total generated resources: 339 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -1028,6 +1028,9 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_data_loss_prevention_stored_info_type": resourceDataLossPreventionStoredInfoType(), "google_data_loss_prevention_deidentify_template": resourceDataLossPreventionDeidentifyTemplate(), "google_dataproc_autoscaling_policy": resourceDataprocAutoscalingPolicy(), + "google_dataproc_autoscaling_policy_iam_binding": ResourceIamBinding(DataprocAutoscalingPolicyIamSchema, DataprocAutoscalingPolicyIamUpdaterProducer, DataprocAutoscalingPolicyIdParseFunc), + "google_dataproc_autoscaling_policy_iam_member": ResourceIamMember(DataprocAutoscalingPolicyIamSchema, DataprocAutoscalingPolicyIamUpdaterProducer, DataprocAutoscalingPolicyIdParseFunc), + "google_dataproc_autoscaling_policy_iam_policy": ResourceIamPolicy(DataprocAutoscalingPolicyIamSchema, DataprocAutoscalingPolicyIamUpdaterProducer, DataprocAutoscalingPolicyIdParseFunc), "google_datastore_index": resourceDatastoreIndex(), "google_deployment_manager_deployment": resourceDeploymentManagerDeployment(), "google_dialogflow_agent": resourceDialogflowAgent(), diff --git a/google/resource_dataproc_autoscaling_policy_generated_test.go b/google/resource_dataproc_autoscaling_policy_generated_test.go index 645f890bf45..b8cc57042e5 100644 --- a/google/resource_dataproc_autoscaling_policy_generated_test.go +++ b/google/resource_dataproc_autoscaling_policy_generated_test.go @@ -23,6 +23,53 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) +func TestAccDataprocAutoscalingPolicy_dataprocAutoscalingPolicyBasicExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDataprocAutoscalingPolicyDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDataprocAutoscalingPolicy_dataprocAutoscalingPolicyBasicExample(context), + }, + { + ResourceName: "google_dataproc_autoscaling_policy.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"location"}, + }, + }, + }) +} + +func testAccDataprocAutoscalingPolicy_dataprocAutoscalingPolicyBasicExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_dataproc_autoscaling_policy" "basic" { + policy_id = "tf-test-dataproc-policy%{random_suffix}" + location = "us-central1" + + worker_config { + max_instances = 3 + } + + basic_algorithm { + yarn_config { + graceful_decommission_timeout = "30s" + + scale_up_factor = 0.5 + scale_down_factor = 0.5 + } + } +} +`, context) +} + func TestAccDataprocAutoscalingPolicy_dataprocAutoscalingPolicyExample(t *testing.T) { t.Parallel() diff --git a/website/docs/r/dataproc_autoscaling_policy_iam.html.markdown b/website/docs/r/dataproc_autoscaling_policy_iam.html.markdown new file mode 100644 index 00000000000..acec7ff0edc --- /dev/null +++ b/website/docs/r/dataproc_autoscaling_policy_iam.html.markdown @@ -0,0 +1,157 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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: "Dataproc" +layout: "google" +page_title: "Google: google_dataproc_autoscaling_policy_iam" +sidebar_current: "docs-google-dataproc-autoscaling-policy-iam" +description: |- + Collection of resources to manage IAM policy for Dataproc AutoscalingPolicy +--- + +# IAM policy for Dataproc AutoscalingPolicy +Three different resources help you manage your IAM policy for Dataproc AutoscalingPolicy. Each of these resources serves a different use case: + +* `google_dataproc_autoscaling_policy_iam_policy`: Authoritative. Sets the IAM policy for the autoscalingpolicy and replaces any existing policy already attached. +* `google_dataproc_autoscaling_policy_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 autoscalingpolicy are preserved. +* `google_dataproc_autoscaling_policy_iam_member`: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the autoscalingpolicy are preserved. + +~> **Note:** `google_dataproc_autoscaling_policy_iam_policy` **cannot** be used in conjunction with `google_dataproc_autoscaling_policy_iam_binding` and `google_dataproc_autoscaling_policy_iam_member` or they will fight over what your policy should be. + +~> **Note:** `google_dataproc_autoscaling_policy_iam_binding` resources **can be** used in conjunction with `google_dataproc_autoscaling_policy_iam_member` resources **only if** they do not grant privilege to the same role. + + + + +## google\_dataproc\_autoscaling\_policy\_iam\_policy + +```hcl +data "google_iam_policy" "admin" { + binding { + role = "roles/viewer" + members = [ + "user:jane@example.com", + ] + } +} + +resource "google_dataproc_autoscaling_policy_iam_policy" "policy" { + project = google_dataproc_autoscaling_policy.basic.project + location = google_dataproc_autoscaling_policy.basic.location + policy_id = google_dataproc_autoscaling_policy.basic.policy_id + policy_data = data.google_iam_policy.admin.policy_data +} +``` + +## google\_dataproc\_autoscaling\_policy\_iam\_binding + +```hcl +resource "google_dataproc_autoscaling_policy_iam_binding" "binding" { + project = google_dataproc_autoscaling_policy.basic.project + location = google_dataproc_autoscaling_policy.basic.location + policy_id = google_dataproc_autoscaling_policy.basic.policy_id + role = "roles/viewer" + members = [ + "user:jane@example.com", + ] +} +``` + +## google\_dataproc\_autoscaling\_policy\_iam\_member + +```hcl +resource "google_dataproc_autoscaling_policy_iam_member" "member" { + project = google_dataproc_autoscaling_policy.basic.project + location = google_dataproc_autoscaling_policy.basic.location + policy_id = google_dataproc_autoscaling_policy.basic.policy_id + role = "roles/viewer" + member = "user:jane@example.com" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `policy_id` - (Required) The policy id. The id must contain only letters (a-z, A-Z), numbers (0-9), underscores (_), +and hyphens (-). Cannot begin or end with underscore or hyphen. Must consist of between +3 and 50 characters. + Used to find the parent resource to bind the IAM policy to +* `location` - (Required) The location where the autoscaling policy should reside. +The default value is `global`. + 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_dataproc_autoscaling_policy_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_dataproc_autoscaling_policy_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}}/autoscalingPolicies/{{policy_id}} +* {{project}}/{{location}}/{{policy_id}} +* {{location}}/{{policy_id}} +* {{policy_id}} + +Any variables not passed in the import command will be taken from the provider configuration. + +Dataproc autoscalingpolicy 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_dataproc_autoscaling_policy_iam_member.editor "projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_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_dataproc_autoscaling_policy_iam_binding.editor "projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_id}} roles/viewer" +``` + +IAM policy imports use the identifier of the resource in question, e.g. +``` +$ terraform import google_dataproc_autoscaling_policy_iam_policy.editor projects/{{project}}/locations/{{location}}/autoscalingPolicies/{{policy_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://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override). diff --git a/website/google.erb b/website/google.erb index 85e089242e0..f8e2aba601a 100644 --- a/website/google.erb +++ b/website/google.erb @@ -2527,6 +2527,10 @@ google_dataproc_autoscaling_policy +
  • + google_dataproc_autoscaling_policy_iam +
  • +
  • google_dataproc_cluster