From d1e76e38e3eaeedbe91eeb370b1ac48f87755226 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Mon, 9 Sep 2019 20:29:29 +0000 Subject: [PATCH] Reverse parent attribute override for TF IAM Signed-off-by: Modular Magician --- google-beta/iam_iap_web_backend_service.go | 38 +++++++++---------- ..._iap_web_backend_service_generated_test.go | 8 ++-- .../iam_pubsub_topic_generated_test.go | 8 ++-- ...m_source_repo_repository_generated_test.go | 8 ++-- google-beta/resource_logging_metric.go | 22 +++++++++++ .../resource_logging_metric_generated_test.go | 1 + .../iap_web_backend_service_iam.html.markdown | 14 +++---- website/docs/r/logging_metric.html.markdown | 7 ++++ website/docs/r/pubsub_topic_iam.html.markdown | 6 +-- .../r/sourcerepo_repository_iam.html.markdown | 6 +-- 10 files changed, 74 insertions(+), 44 deletions(-) diff --git a/google-beta/iam_iap_web_backend_service.go b/google-beta/iam_iap_web_backend_service.go index d24eb7d7b82..d7cfc00f89c 100644 --- a/google-beta/iam_iap_web_backend_service.go +++ b/google-beta/iam_iap_web_backend_service.go @@ -28,7 +28,7 @@ var IapWebBackendServiceIamSchema = map[string]*schema.Schema{ Optional: true, ForceNew: true, }, - "backend_service_name": { + "web_backend_service": { Type: schema.TypeString, Required: true, ForceNew: true, @@ -37,10 +37,10 @@ var IapWebBackendServiceIamSchema = map[string]*schema.Schema{ } type IapWebBackendServiceIamUpdater struct { - project string - backendServiceName string - d *schema.ResourceData - Config *Config + project string + webBackendService string + d *schema.ResourceData + Config *Config } func IapWebBackendServiceIamUpdaterProducer(d *schema.ResourceData, config *Config) (ResourceIamUpdater, error) { @@ -57,7 +57,7 @@ func IapWebBackendServiceIamUpdaterProducer(d *schema.ResourceData, config *Conf values["project"] = project // We may have gotten either a long or short name, so attempt to parse long name if possible - m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/iap_web/compute/services/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("backend_service_name").(string)) + m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/iap_web/compute/services/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("web_backend_service").(string)) if err != nil { return nil, err } @@ -67,14 +67,14 @@ func IapWebBackendServiceIamUpdaterProducer(d *schema.ResourceData, config *Conf } u := &IapWebBackendServiceIamUpdater{ - project: values["project"], - backendServiceName: values["backendServiceName"], - d: d, - Config: config, + project: values["project"], + webBackendService: values["web_backend_service"], + d: d, + Config: config, } d.Set("project", u.project) - d.Set("backend_service_name", u.GetResourceId()) + d.Set("web_backend_service", u.GetResourceId()) d.SetId(u.GetResourceId()) @@ -91,7 +91,7 @@ func IapWebBackendServiceIdParseFunc(d *schema.ResourceData, config *Config) err values["project"] = project - m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/iap_web/compute/services/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Id()) + m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/iap_web/compute/services/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Id()) if err != nil { return err } @@ -101,12 +101,12 @@ func IapWebBackendServiceIdParseFunc(d *schema.ResourceData, config *Config) err } u := &IapWebBackendServiceIamUpdater{ - project: values["project"], - backendServiceName: values["backendServiceName"], - d: d, - Config: config, + project: values["project"], + webBackendService: values["web_backend_service"], + d: d, + Config: config, } - d.Set("backend_service_name", u.GetResourceId()) + d.Set("web_backend_service", u.GetResourceId()) d.SetId(u.GetResourceId()) return nil } @@ -158,11 +158,11 @@ func (u *IapWebBackendServiceIamUpdater) SetResourceIamPolicy(policy *cloudresou } func (u *IapWebBackendServiceIamUpdater) qualifyWebBackendServiceUrl(methodIdentifier string) string { - return fmt.Sprintf("https://iap.googleapis.com/v1/%s:%s", fmt.Sprintf("projects/%s/iap_web/compute/services/%s", u.project, u.backendServiceName), methodIdentifier) + return fmt.Sprintf("https://iap.googleapis.com/v1/%s:%s", fmt.Sprintf("projects/%s/iap_web/compute/services/%s", u.project, u.webBackendService), methodIdentifier) } func (u *IapWebBackendServiceIamUpdater) GetResourceId() string { - return fmt.Sprintf("projects/%s/iap_web/compute/services/%s", u.project, u.backendServiceName) + return fmt.Sprintf("projects/%s/iap_web/compute/services/%s", u.project, u.webBackendService) } func (u *IapWebBackendServiceIamUpdater) GetMutexKey() string { diff --git a/google-beta/iam_iap_web_backend_service_generated_test.go b/google-beta/iam_iap_web_backend_service_generated_test.go index d5409afb240..6bba31ed4b2 100644 --- a/google-beta/iam_iap_web_backend_service_generated_test.go +++ b/google-beta/iam_iap_web_backend_service_generated_test.go @@ -124,7 +124,7 @@ resource "google_compute_http_health_check" "default" { resource "google_iap_web_backend_service_iam_member" "foo" { project = "${google_compute_backend_service.default.project}" - backend_service_name = "${google_compute_backend_service.default.name}" + web_backend_service = "${google_compute_backend_service.default.name}" role = "%{role}" member = "user:admin@hashicorptest.com" } @@ -154,7 +154,7 @@ data "google_iam_policy" "foo" { resource "google_iap_web_backend_service_iam_policy" "foo" { project = "${google_compute_backend_service.default.project}" - backend_service_name = "${google_compute_backend_service.default.name}" + web_backend_service = "${google_compute_backend_service.default.name}" policy_data = "${data.google_iam_policy.foo.policy_data}" } `, context) @@ -176,7 +176,7 @@ resource "google_compute_http_health_check" "default" { resource "google_iap_web_backend_service_iam_binding" "foo" { project = "${google_compute_backend_service.default.project}" - backend_service_name = "${google_compute_backend_service.default.name}" + web_backend_service = "${google_compute_backend_service.default.name}" role = "%{role}" members = ["user:admin@hashicorptest.com"] } @@ -199,7 +199,7 @@ resource "google_compute_http_health_check" "default" { resource "google_iap_web_backend_service_iam_binding" "foo" { project = "${google_compute_backend_service.default.project}" - backend_service_name = "${google_compute_backend_service.default.name}" + web_backend_service = "${google_compute_backend_service.default.name}" role = "%{role}" members = ["user:admin@hashicorptest.com", "user:paddy@hashicorp.com"] } diff --git a/google-beta/iam_pubsub_topic_generated_test.go b/google-beta/iam_pubsub_topic_generated_test.go index 999df0520aa..0f60901c920 100644 --- a/google-beta/iam_pubsub_topic_generated_test.go +++ b/google-beta/iam_pubsub_topic_generated_test.go @@ -120,7 +120,7 @@ resource "google_pubsub_topic" "example" { resource "google_pubsub_topic_iam_member" "foo" { project = "${google_pubsub_topic.example.project}" - topic = "${google_pubsub_topic.example.id}" + topic = "${google_pubsub_topic.example.name}" role = "%{role}" member = "user:admin@hashicorptest.com" } @@ -146,7 +146,7 @@ data "google_iam_policy" "foo" { resource "google_pubsub_topic_iam_policy" "foo" { project = "${google_pubsub_topic.example.project}" - topic = "${google_pubsub_topic.example.id}" + topic = "${google_pubsub_topic.example.name}" policy_data = "${data.google_iam_policy.foo.policy_data}" } `, context) @@ -164,7 +164,7 @@ resource "google_pubsub_topic" "example" { resource "google_pubsub_topic_iam_binding" "foo" { project = "${google_pubsub_topic.example.project}" - topic = "${google_pubsub_topic.example.id}" + topic = "${google_pubsub_topic.example.name}" role = "%{role}" members = ["user:admin@hashicorptest.com"] } @@ -183,7 +183,7 @@ resource "google_pubsub_topic" "example" { resource "google_pubsub_topic_iam_binding" "foo" { project = "${google_pubsub_topic.example.project}" - topic = "${google_pubsub_topic.example.id}" + topic = "${google_pubsub_topic.example.name}" role = "%{role}" members = ["user:admin@hashicorptest.com", "user:paddy@hashicorp.com"] } diff --git a/google-beta/iam_source_repo_repository_generated_test.go b/google-beta/iam_source_repo_repository_generated_test.go index cdb6f234522..a607939f28b 100644 --- a/google-beta/iam_source_repo_repository_generated_test.go +++ b/google-beta/iam_source_repo_repository_generated_test.go @@ -116,7 +116,7 @@ resource "google_sourcerepo_repository" "my-repo" { resource "google_sourcerepo_repository_iam_member" "foo" { project = "${google_sourcerepo_repository.my-repo.project}" - repository = "${google_sourcerepo_repository.my-repo.id}" + repository = "${google_sourcerepo_repository.my-repo.name}" role = "%{role}" member = "user:admin@hashicorptest.com" } @@ -138,7 +138,7 @@ data "google_iam_policy" "foo" { resource "google_sourcerepo_repository_iam_policy" "foo" { project = "${google_sourcerepo_repository.my-repo.project}" - repository = "${google_sourcerepo_repository.my-repo.id}" + repository = "${google_sourcerepo_repository.my-repo.name}" policy_data = "${data.google_iam_policy.foo.policy_data}" } `, context) @@ -152,7 +152,7 @@ resource "google_sourcerepo_repository" "my-repo" { resource "google_sourcerepo_repository_iam_binding" "foo" { project = "${google_sourcerepo_repository.my-repo.project}" - repository = "${google_sourcerepo_repository.my-repo.id}" + repository = "${google_sourcerepo_repository.my-repo.name}" role = "%{role}" members = ["user:admin@hashicorptest.com"] } @@ -167,7 +167,7 @@ resource "google_sourcerepo_repository" "my-repo" { resource "google_sourcerepo_repository_iam_binding" "foo" { project = "${google_sourcerepo_repository.my-repo.project}" - repository = "${google_sourcerepo_repository.my-repo.id}" + repository = "${google_sourcerepo_repository.my-repo.name}" role = "%{role}" members = ["user:admin@hashicorptest.com", "user:paddy@hashicorp.com"] } diff --git a/google-beta/resource_logging_metric.go b/google-beta/resource_logging_metric.go index f2c6dbe2447..bf641dc5a06 100644 --- a/google-beta/resource_logging_metric.go +++ b/google-beta/resource_logging_metric.go @@ -85,6 +85,11 @@ func resourceLoggingMetric() *schema.Resource { }, }, }, + "unit": { + Type: schema.TypeString, + Optional: true, + Default: "1", + }, }, }, }, @@ -456,6 +461,8 @@ func flattenLoggingMetricMetricDescriptor(v interface{}, d *schema.ResourceData) return nil } transformed := make(map[string]interface{}) + transformed["unit"] = + flattenLoggingMetricMetricDescriptorUnit(original["unit"], d) transformed["value_type"] = flattenLoggingMetricMetricDescriptorValueType(original["valueType"], d) transformed["metric_kind"] = @@ -464,6 +471,10 @@ func flattenLoggingMetricMetricDescriptor(v interface{}, d *schema.ResourceData) flattenLoggingMetricMetricDescriptorLabels(original["labels"], d) return []interface{}{transformed} } +func flattenLoggingMetricMetricDescriptorUnit(v interface{}, d *schema.ResourceData) interface{} { + return v +} + func flattenLoggingMetricMetricDescriptorValueType(v interface{}, d *schema.ResourceData) interface{} { return v } @@ -652,6 +663,13 @@ func expandLoggingMetricMetricDescriptor(v interface{}, d TerraformResourceData, original := raw.(map[string]interface{}) transformed := make(map[string]interface{}) + transformedUnit, err := expandLoggingMetricMetricDescriptorUnit(original["unit"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUnit); val.IsValid() && !isEmptyValue(val) { + transformed["unit"] = transformedUnit + } + transformedValueType, err := expandLoggingMetricMetricDescriptorValueType(original["value_type"], d, config) if err != nil { return nil, err @@ -676,6 +694,10 @@ func expandLoggingMetricMetricDescriptor(v interface{}, d TerraformResourceData, return transformed, nil } +func expandLoggingMetricMetricDescriptorUnit(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandLoggingMetricMetricDescriptorValueType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/google-beta/resource_logging_metric_generated_test.go b/google-beta/resource_logging_metric_generated_test.go index ca7407138b6..91a2a1b2960 100644 --- a/google-beta/resource_logging_metric_generated_test.go +++ b/google-beta/resource_logging_metric_generated_test.go @@ -56,6 +56,7 @@ resource "google_logging_metric" "logging_metric" { metric_descriptor { metric_kind = "DELTA" value_type = "DISTRIBUTION" + unit = "1" labels { key = "mass" value_type = "STRING" diff --git a/website/docs/r/iap_web_backend_service_iam.html.markdown b/website/docs/r/iap_web_backend_service_iam.html.markdown index 0e31d0412fa..9e073725e02 100644 --- a/website/docs/r/iap_web_backend_service_iam.html.markdown +++ b/website/docs/r/iap_web_backend_service_iam.html.markdown @@ -46,7 +46,7 @@ data "google_iam_policy" "admin" { resource "google_iap_web_backend_service_iam_policy" "editor" { project = "${google_compute_backend_service.default.project}" - backend_service_name = "${google_compute_backend_service.default.name}" + web_backend_service = "${google_compute_backend_service.default.name}" policy_data = "${data.google_iam_policy.admin.policy_data}" } ``` @@ -56,7 +56,7 @@ resource "google_iap_web_backend_service_iam_policy" "editor" { ```hcl resource "google_iap_web_backend_service_iam_binding" "editor" { project = "${google_compute_backend_service.default.project}" - backend_service_name = "${google_compute_backend_service.default.name}" + web_backend_service = "${google_compute_backend_service.default.name}" role = "roles/iap.httpsResourceAccessor" members = [ "user:jane@example.com", @@ -69,7 +69,7 @@ resource "google_iap_web_backend_service_iam_binding" "editor" { ```hcl resource "google_iap_web_backend_service_iam_member" "editor" { project = "${google_compute_backend_service.default.project}" - backend_service_name = "${google_compute_backend_service.default.name}" + web_backend_service = "${google_compute_backend_service.default.name}" role = "roles/iap.httpsResourceAccessor" member = "user:jane@example.com" } @@ -79,7 +79,7 @@ resource "google_iap_web_backend_service_iam_member" "editor" { The following arguments are supported: -* `backend_service_name` - (Required) Name or self link of a backend service. Used to find the parent resource to bind the IAM policy to +* `web_backend_service` - (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. @@ -112,11 +112,11 @@ exported: Iap webbackendservice IAM resources can be imported using the project, resource identifiers, role and member. ``` -$ terraform import google_iap_web_backend_service_iam_policy.editor projects/{{project}}/iap_web/compute/services/{{backendServiceName}} +$ terraform import google_iap_web_backend_service_iam_policy.editor projects/{{project}}/iap_web/compute/services/{{web_backend_service}} -$ terraform import google_iap_web_backend_service_iam_binding.editor "projects/{{project}}/iap_web/compute/services/{{backendServiceName}} roles/iap.httpsResourceAccessor" +$ terraform import google_iap_web_backend_service_iam_binding.editor "projects/{{project}}/iap_web/compute/services/{{web_backend_service}} roles/iap.httpsResourceAccessor" -$ terraform import google_iap_web_backend_service_iam_member.editor "projects/{{project}}/iap_web/compute/services/{{backendServiceName}} roles/iap.httpsResourceAccessor jane@example.com" +$ terraform import google_iap_web_backend_service_iam_member.editor "projects/{{project}}/iap_web/compute/services/{{web_backend_service}} roles/iap.httpsResourceAccessor jane@example.com" ``` -> If you're importing a resource with beta features, make sure to include `-provider=google-beta` diff --git a/website/docs/r/logging_metric.html.markdown b/website/docs/r/logging_metric.html.markdown index 7942092c421..3a859be939c 100644 --- a/website/docs/r/logging_metric.html.markdown +++ b/website/docs/r/logging_metric.html.markdown @@ -48,6 +48,7 @@ resource "google_logging_metric" "logging_metric" { metric_descriptor { metric_kind = "DELTA" value_type = "DISTRIBUTION" + unit = "1" labels { key = "mass" value_type = "STRING" @@ -133,6 +134,12 @@ The following arguments are supported: The `metric_descriptor` block supports: +* `unit` - + (Optional) + The unit in which the metric value is reported. It is only applicable if the valueType is + `INT64`, `DOUBLE`, or `DISTRIBUTION`. The supported units are a subset of + [The Unified Code for Units of Measure](http://unitsofmeasure.org/ucum.html) standard + * `value_type` - (Required) Whether the measurement is an integer, a floating-point number, etc. diff --git a/website/docs/r/pubsub_topic_iam.html.markdown b/website/docs/r/pubsub_topic_iam.html.markdown index 69460fe9b0d..e580097eb98 100644 --- a/website/docs/r/pubsub_topic_iam.html.markdown +++ b/website/docs/r/pubsub_topic_iam.html.markdown @@ -46,7 +46,7 @@ data "google_iam_policy" "admin" { resource "google_pubsub_topic_iam_policy" "editor" { project = "${google_pubsub_topic_iam.example.project}" - name = "${google_pubsub_topic_iam.example.id}" + topic = "${google_pubsub_topic_iam.example.name}" policy_data = "${data.google_iam_policy.admin.policy_data}" } ``` @@ -56,7 +56,7 @@ resource "google_pubsub_topic_iam_policy" "editor" { ```hcl resource "google_pubsub_topic_iam_binding" "editor" { project = "${google_pubsub_topic_iam.example.project}" - name = "${google_pubsub_topic_iam.example.id}" + topic = "${google_pubsub_topic_iam.example.name}" role = "roles/viewer" members = [ "user:jane@example.com", @@ -69,7 +69,7 @@ resource "google_pubsub_topic_iam_binding" "editor" { ```hcl resource "google_pubsub_topic_iam_member" "editor" { project = "${google_pubsub_topic_iam.example.project}" - name = "${google_pubsub_topic_iam.example.id}" + topic = "${google_pubsub_topic_iam.example.name}" role = "roles/viewer" member = "user:jane@example.com" } diff --git a/website/docs/r/sourcerepo_repository_iam.html.markdown b/website/docs/r/sourcerepo_repository_iam.html.markdown index e6321044690..c425a212258 100644 --- a/website/docs/r/sourcerepo_repository_iam.html.markdown +++ b/website/docs/r/sourcerepo_repository_iam.html.markdown @@ -46,7 +46,7 @@ data "google_iam_policy" "admin" { resource "google_sourcerepo_repository_iam_policy" "editor" { project = "${google_sourcerepo_repository_iam.my-repo.project}" - name = "${google_sourcerepo_repository_iam.my-repo.id}" + repository = "${google_sourcerepo_repository_iam.my-repo.name}" policy_data = "${data.google_iam_policy.admin.policy_data}" } ``` @@ -56,7 +56,7 @@ resource "google_sourcerepo_repository_iam_policy" "editor" { ```hcl resource "google_sourcerepo_repository_iam_binding" "editor" { project = "${google_sourcerepo_repository_iam.my-repo.project}" - name = "${google_sourcerepo_repository_iam.my-repo.id}" + repository = "${google_sourcerepo_repository_iam.my-repo.name}" role = "roles/viewer" members = [ "user:jane@example.com", @@ -69,7 +69,7 @@ resource "google_sourcerepo_repository_iam_binding" "editor" { ```hcl resource "google_sourcerepo_repository_iam_member" "editor" { project = "${google_sourcerepo_repository_iam.my-repo.project}" - name = "${google_sourcerepo_repository_iam.my-repo.id}" + repository = "${google_sourcerepo_repository_iam.my-repo.name}" role = "roles/viewer" member = "user:jane@example.com" }