From 2aa30516e00d47192e1e802ff1443dad62d273a2 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 11 Apr 2022 15:54:38 -0500 Subject: [PATCH] Add IAM support for privateca CertificateTemplate (#5904) (#11464) Signed-off-by: Modular Magician --- .changelog/5904.txt | 9 + google/iam_privateca_certificate_template.go | 226 +++++++++++++++ ...eca_certificate_template_generated_test.go | 260 ++++++++++++++++++ google/provider.go | 7 +- ...eca_certificate_template_iam.html.markdown | 216 +++++++++++++++ website/google.erb | 4 + 6 files changed, 720 insertions(+), 2 deletions(-) create mode 100644 .changelog/5904.txt create mode 100644 google/iam_privateca_certificate_template.go create mode 100644 google/iam_privateca_certificate_template_generated_test.go create mode 100644 website/docs/r/privateca_certificate_template_iam.html.markdown diff --git a/.changelog/5904.txt b/.changelog/5904.txt new file mode 100644 index 00000000000..95f3dfaa45e --- /dev/null +++ b/.changelog/5904.txt @@ -0,0 +1,9 @@ +```release-note:new-resource +`google_privateca_certificate_template_iam_binding` +``` +```release-note:new-resource +`google_privateca_certificate_template_iam_member` +``` +```release-note:new-resource +`google_privateca_certificate_template_iam_policy` +``` diff --git a/google/iam_privateca_certificate_template.go b/google/iam_privateca_certificate_template.go new file mode 100644 index 00000000000..acefe6605be --- /dev/null +++ b/google/iam_privateca_certificate_template.go @@ -0,0 +1,226 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 PrivatecaCertificateTemplateIamSchema = map[string]*schema.Schema{ + "project": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "location": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "certificate_template": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, +} + +type PrivatecaCertificateTemplateIamUpdater struct { + project string + location string + certificateTemplate string + d TerraformResourceData + Config *Config +} + +func PrivatecaCertificateTemplateIamUpdaterProducer(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("certificate_template"); ok { + values["certificate_template"] = 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[^/]+)/certificateTemplates/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)"}, d, config, d.Get("certificate_template").(string)) + if err != nil { + return nil, err + } + + for k, v := range m { + values[k] = v + } + + u := &PrivatecaCertificateTemplateIamUpdater{ + project: values["project"], + location: values["location"], + certificateTemplate: values["certificate_template"], + 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("certificate_template", u.GetResourceId()); err != nil { + return nil, fmt.Errorf("Error setting certificate_template: %s", err) + } + + return u, nil +} + +func PrivatecaCertificateTemplateIdParseFunc(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[^/]+)/certificateTemplates/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)"}, d, config, d.Id()) + if err != nil { + return err + } + + for k, v := range m { + values[k] = v + } + + u := &PrivatecaCertificateTemplateIamUpdater{ + project: values["project"], + location: values["location"], + certificateTemplate: values["certificate_template"], + d: d, + Config: config, + } + if err := d.Set("certificate_template", u.GetResourceId()); err != nil { + return fmt.Errorf("Error setting certificate_template: %s", err) + } + d.SetId(u.GetResourceId()) + return nil +} + +func (u *PrivatecaCertificateTemplateIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { + url, err := u.qualifyCertificateTemplateUrl("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{} + url, err = addQueryParams(url, map[string]string{"options.requestedPolicyVersion": fmt.Sprintf("%d", iamPolicyVersion)}) + if err != nil { + return nil, err + } + + userAgent, err := generateUserAgentString(u.d, u.Config.userAgent) + if err != nil { + return nil, err + } + + policy, err := sendRequest(u.Config, "GET", 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 *PrivatecaCertificateTemplateIamUpdater) 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.qualifyCertificateTemplateUrl("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 *PrivatecaCertificateTemplateIamUpdater) qualifyCertificateTemplateUrl(methodIdentifier string) (string, error) { + urlTemplate := fmt.Sprintf("{{PrivatecaBasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", u.project, u.location, u.certificateTemplate), methodIdentifier) + url, err := replaceVars(u.d, u.Config, urlTemplate) + if err != nil { + return "", err + } + return url, nil +} + +func (u *PrivatecaCertificateTemplateIamUpdater) GetResourceId() string { + return fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", u.project, u.location, u.certificateTemplate) +} + +func (u *PrivatecaCertificateTemplateIamUpdater) GetMutexKey() string { + return fmt.Sprintf("iam-privateca-certificatetemplate-%s", u.GetResourceId()) +} + +func (u *PrivatecaCertificateTemplateIamUpdater) DescribeResource() string { + return fmt.Sprintf("privateca certificatetemplate %q", u.GetResourceId()) +} diff --git a/google/iam_privateca_certificate_template_generated_test.go b/google/iam_privateca_certificate_template_generated_test.go new file mode 100644 index 00000000000..513b0760f96 --- /dev/null +++ b/google/iam_privateca_certificate_template_generated_test.go @@ -0,0 +1,260 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 TestAccPrivatecaCertificateTemplateIamBindingGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "role": "roles/privateca.templateUser", + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccPrivatecaCertificateTemplateIamBinding_basicGenerated(context), + }, + { + ResourceName: "google_privateca_certificate_template_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + // Test Iam Binding update + Config: testAccPrivatecaCertificateTemplateIamBinding_updateGenerated(context), + }, + { + ResourceName: "google_privateca_certificate_template_iam_binding.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccPrivatecaCertificateTemplateIamMemberGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "role": "roles/privateca.templateUser", + } + + 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: testAccPrivatecaCertificateTemplateIamMember_basicGenerated(context), + }, + { + ResourceName: "google_privateca_certificate_template_iam_member.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s roles/privateca.templateUser user:admin@hashicorptest.com", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccPrivatecaCertificateTemplateIamPolicyGenerated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + "role": "roles/privateca.templateUser", + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccPrivatecaCertificateTemplateIamPolicy_basicGenerated(context), + }, + { + ResourceName: "google_privateca_certificate_template_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccPrivatecaCertificateTemplateIamPolicy_emptyBinding(context), + }, + { + ResourceName: "google_privateca_certificate_template_iam_policy.foo", + ImportStateId: fmt.Sprintf("projects/%s/locations/%s/certificateTemplates/%s", getTestProjectFromEnv(), getTestRegionFromEnv(), fmt.Sprintf("tf-test-my-template%s", context["random_suffix"])), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccPrivatecaCertificateTemplateIamMember_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_privateca_certificate_template" "default" { + name = "tf-test-my-template%{random_suffix}" + location = "us-central1" + + identity_constraints { + allow_subject_alt_names_passthrough = true + allow_subject_passthrough = true + + cel_expression { + description = "Always true" + expression = "true" + location = "any.file.anywhere" + title = "Sample expression" + } + } +} + +resource "google_privateca_certificate_template_iam_member" "foo" { + certificate_template = google_privateca_certificate_template.default.id + role = "%{role}" + member = "user:admin@hashicorptest.com" +} +`, context) +} + +func testAccPrivatecaCertificateTemplateIamPolicy_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_privateca_certificate_template" "default" { + name = "tf-test-my-template%{random_suffix}" + location = "us-central1" + + identity_constraints { + allow_subject_alt_names_passthrough = true + allow_subject_passthrough = true + + cel_expression { + description = "Always true" + expression = "true" + location = "any.file.anywhere" + title = "Sample expression" + } + } +} + +data "google_iam_policy" "foo" { + binding { + role = "%{role}" + members = ["user:admin@hashicorptest.com"] + } +} + +resource "google_privateca_certificate_template_iam_policy" "foo" { + certificate_template = google_privateca_certificate_template.default.id + policy_data = data.google_iam_policy.foo.policy_data +} +`, context) +} + +func testAccPrivatecaCertificateTemplateIamPolicy_emptyBinding(context map[string]interface{}) string { + return Nprintf(` +resource "google_privateca_certificate_template" "default" { + name = "tf-test-my-template%{random_suffix}" + location = "us-central1" + + identity_constraints { + allow_subject_alt_names_passthrough = true + allow_subject_passthrough = true + + cel_expression { + description = "Always true" + expression = "true" + location = "any.file.anywhere" + title = "Sample expression" + } + } +} + +data "google_iam_policy" "foo" { +} + +resource "google_privateca_certificate_template_iam_policy" "foo" { + certificate_template = google_privateca_certificate_template.default.id + policy_data = data.google_iam_policy.foo.policy_data +} +`, context) +} + +func testAccPrivatecaCertificateTemplateIamBinding_basicGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_privateca_certificate_template" "default" { + name = "tf-test-my-template%{random_suffix}" + location = "us-central1" + + identity_constraints { + allow_subject_alt_names_passthrough = true + allow_subject_passthrough = true + + cel_expression { + description = "Always true" + expression = "true" + location = "any.file.anywhere" + title = "Sample expression" + } + } +} + +resource "google_privateca_certificate_template_iam_binding" "foo" { + certificate_template = google_privateca_certificate_template.default.id + role = "%{role}" + members = ["user:admin@hashicorptest.com"] +} +`, context) +} + +func testAccPrivatecaCertificateTemplateIamBinding_updateGenerated(context map[string]interface{}) string { + return Nprintf(` +resource "google_privateca_certificate_template" "default" { + name = "tf-test-my-template%{random_suffix}" + location = "us-central1" + + identity_constraints { + allow_subject_alt_names_passthrough = true + allow_subject_passthrough = true + + cel_expression { + description = "Always true" + expression = "true" + location = "any.file.anywhere" + title = "Sample expression" + } + } +} + +resource "google_privateca_certificate_template_iam_binding" "foo" { + certificate_template = google_privateca_certificate_template.default.id + role = "%{role}" + members = ["user:admin@hashicorptest.com", "user:gterraformtest1@gmail.com"] +} +`, context) +} diff --git a/google/provider.go b/google/provider.go index f3e4ba410b5..619e1ea514a 100644 --- a/google/provider.go +++ b/google/provider.go @@ -830,8 +830,8 @@ func Provider() *schema.Provider { } // Generated resources: 217 -// Generated IAM resources: 105 -// Total generated resources: 322 +// Generated IAM resources: 108 +// Total generated resources: 325 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -1104,6 +1104,9 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_privateca_ca_pool_iam_binding": ResourceIamBinding(PrivatecaCaPoolIamSchema, PrivatecaCaPoolIamUpdaterProducer, PrivatecaCaPoolIdParseFunc), "google_privateca_ca_pool_iam_member": ResourceIamMember(PrivatecaCaPoolIamSchema, PrivatecaCaPoolIamUpdaterProducer, PrivatecaCaPoolIdParseFunc), "google_privateca_ca_pool_iam_policy": ResourceIamPolicy(PrivatecaCaPoolIamSchema, PrivatecaCaPoolIamUpdaterProducer, PrivatecaCaPoolIdParseFunc), + "google_privateca_certificate_template_iam_binding": ResourceIamBinding(PrivatecaCertificateTemplateIamSchema, PrivatecaCertificateTemplateIamUpdaterProducer, PrivatecaCertificateTemplateIdParseFunc), + "google_privateca_certificate_template_iam_member": ResourceIamMember(PrivatecaCertificateTemplateIamSchema, PrivatecaCertificateTemplateIamUpdaterProducer, PrivatecaCertificateTemplateIdParseFunc), + "google_privateca_certificate_template_iam_policy": ResourceIamPolicy(PrivatecaCertificateTemplateIamSchema, PrivatecaCertificateTemplateIamUpdaterProducer, PrivatecaCertificateTemplateIdParseFunc), "google_pubsub_topic": resourcePubsubTopic(), "google_pubsub_topic_iam_binding": ResourceIamBinding(PubsubTopicIamSchema, PubsubTopicIamUpdaterProducer, PubsubTopicIdParseFunc), "google_pubsub_topic_iam_member": ResourceIamMember(PubsubTopicIamSchema, PubsubTopicIamUpdaterProducer, PubsubTopicIdParseFunc), diff --git a/website/docs/r/privateca_certificate_template_iam.html.markdown b/website/docs/r/privateca_certificate_template_iam.html.markdown new file mode 100644 index 00000000000..dace01a1dab --- /dev/null +++ b/website/docs/r/privateca_certificate_template_iam.html.markdown @@ -0,0 +1,216 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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: "Certificate Authority Service" +layout: "google" +page_title: "Google: google_privateca_certificate_template_iam" +sidebar_current: "docs-google-privateca-certificate-template-iam" +description: |- + Collection of resources to manage IAM policy for Certificate Authority Service CertificateTemplate +--- + +# IAM policy for Certificate Authority Service CertificateTemplate +Three different resources help you manage your IAM policy for Certificate Authority Service CertificateTemplate. Each of these resources serves a different use case: + +* `google_privateca_certificate_template_iam_policy`: Authoritative. Sets the IAM policy for the certificatetemplate and replaces any existing policy already attached. +* `google_privateca_certificate_template_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 certificatetemplate are preserved. +* `google_privateca_certificate_template_iam_member`: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the certificatetemplate are preserved. + +~> **Note:** `google_privateca_certificate_template_iam_policy` **cannot** be used in conjunction with `google_privateca_certificate_template_iam_binding` and `google_privateca_certificate_template_iam_member` or they will fight over what your policy should be. + +~> **Note:** `google_privateca_certificate_template_iam_binding` resources **can be** used in conjunction with `google_privateca_certificate_template_iam_member` resources **only if** they do not grant privilege to the same role. + +~> **Note:** This resource supports IAM Conditions ([beta](https://terraform.io/docs/providers/google/provider_versions.html)) but they have some known limitations which can be found [here](https://cloud.google.com/iam/docs/conditions-overview#limitations). Please review this article if you are having issues with IAM Conditions. + + + +## google\_privateca\_certificate\_template\_iam\_policy + +```hcl +data "google_iam_policy" "admin" { + binding { + role = "roles/privateca.templateUser" + members = [ + "user:jane@example.com", + ] + } +} + +resource "google_privateca_certificate_template_iam_policy" "policy" { + certificate_template = google_privateca_certificate_template.default.id + policy_data = data.google_iam_policy.admin.policy_data +} +``` + +With IAM Conditions ([beta](https://terraform.io/docs/providers/google/provider_versions.html)): + +```hcl +data "google_iam_policy" "admin" { + binding { + role = "roles/privateca.templateUser" + members = [ + "user:jane@example.com", + ] + + condition { + title = "expires_after_2019_12_31" + description = "Expiring at midnight of 2019-12-31" + expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")" + } + } +} + +resource "google_privateca_certificate_template_iam_policy" "policy" { + certificate_template = google_privateca_certificate_template.default.id + policy_data = data.google_iam_policy.admin.policy_data +} +``` +## google\_privateca\_certificate\_template\_iam\_binding + +```hcl +resource "google_privateca_certificate_template_iam_binding" "binding" { + certificate_template = google_privateca_certificate_template.default.id + role = "roles/privateca.templateUser" + members = [ + "user:jane@example.com", + ] +} +``` + +With IAM Conditions ([beta](https://terraform.io/docs/providers/google/provider_versions.html)): + +```hcl +resource "google_privateca_certificate_template_iam_binding" "binding" { + certificate_template = google_privateca_certificate_template.default.id + role = "roles/privateca.templateUser" + members = [ + "user:jane@example.com", + ] + + condition { + title = "expires_after_2019_12_31" + description = "Expiring at midnight of 2019-12-31" + expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")" + } +} +``` +## google\_privateca\_certificate\_template\_iam\_member + +```hcl +resource "google_privateca_certificate_template_iam_member" "member" { + certificate_template = google_privateca_certificate_template.default.id + role = "roles/privateca.templateUser" + member = "user:jane@example.com" +} +``` + +With IAM Conditions ([beta](https://terraform.io/docs/providers/google/provider_versions.html)): + +```hcl +resource "google_privateca_certificate_template_iam_member" "member" { + certificate_template = google_privateca_certificate_template.default.id + role = "roles/privateca.templateUser" + member = "user:jane@example.com" + + condition { + title = "expires_after_2019_12_31" + description = "Expiring at midnight of 2019-12-31" + expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")" + } +} +``` +## Argument Reference + +The following arguments are supported: + +* `certificate_template` - (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" + +* `role` - (Required) The role that should be applied. Only one + `google_privateca_certificate_template_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_privateca_certificate_template_iam_policy`) The policy data generated by + a `google_iam_policy` data source. + +* `condition` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding. + Structure is documented below. + +--- + +The `condition` block supports: + +* `expression` - (Required) Textual representation of an expression in Common Expression Language syntax. + +* `title` - (Required) A title for the expression, i.e. a short string describing its purpose. + +* `description` - (Optional) An optional description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI. + +~> **Warning:** Terraform considers the `role` and condition contents (`title`+`description`+`expression`) as the + identifier for the binding. This means that if any part of the condition is changed out-of-band, Terraform will + consider it to be an entirely different resource and will treat it as such. +## 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}}/certificateTemplates/{{name}} +* {{project}}/{{location}}/{{name}} +* {{location}}/{{name}} + +Any variables not passed in the import command will be taken from the provider configuration. + +Certificate Authority Service certificatetemplate 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_privateca_certificate_template_iam_member.editor "projects/{{project}}/locations/{{location}}/certificateTemplates/{{certificate_template}} roles/privateca.templateUser user:jane@example.com" +``` + +IAM binding imports use space-delimited identifiers: the resource in question and the role, e.g. +``` +$ terraform import google_privateca_certificate_template_iam_binding.editor "projects/{{project}}/locations/{{location}}/certificateTemplates/{{certificate_template}} roles/privateca.templateUser" +``` + +IAM policy imports use the identifier of the resource in question, e.g. +``` +$ terraform import google_privateca_certificate_template_iam_policy.editor projects/{{project}}/locations/{{location}}/certificateTemplates/{{certificate_template}} +``` + +-> **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 5fb9df4b904..1d15c46b037 100644 --- a/website/google.erb +++ b/website/google.erb @@ -493,6 +493,10 @@ google_privateca_certificate_authority +
  • + google_privateca_certificate_template_iam +
  • +