Skip to content

Commit

Permalink
Merge pull request hashicorp#1126 from modular-magician/codegen-pr-2302
Browse files Browse the repository at this point in the history
Reverse parent attribute override for TF IAM
  • Loading branch information
slevenick authored Sep 9, 2019
2 parents 4c84515 + d1e76e3 commit 77114d1
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
38 changes: 19 additions & 19 deletions google-beta/iam_iap_web_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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<project>[^/]+)/iap_web/compute/services/(?P<backendServiceName>[^/]+)", "(?P<project>[^/]+)/(?P<backendServiceName>[^/]+)", "(?P<backendServiceName>[^/]+)"}, d, config, d.Get("backend_service_name").(string))
m, err := getImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/iap_web/compute/services/(?P<web_backend_service>[^/]+)", "(?P<project>[^/]+)/(?P<web_backend_service>[^/]+)", "(?P<web_backend_service>[^/]+)"}, d, config, d.Get("web_backend_service").(string))
if err != nil {
return nil, err
}
Expand All @@ -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())

Expand All @@ -91,7 +91,7 @@ func IapWebBackendServiceIdParseFunc(d *schema.ResourceData, config *Config) err

values["project"] = project

m, err := getImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/iap_web/compute/services/(?P<backendServiceName>[^/]+)", "(?P<project>[^/]+)/(?P<backendServiceName>[^/]+)", "(?P<backendServiceName>[^/]+)"}, d, config, d.Id())
m, err := getImportIdQualifiers([]string{"projects/(?P<project>[^/]+)/iap_web/compute/services/(?P<web_backend_service>[^/]+)", "(?P<project>[^/]+)/(?P<web_backend_service>[^/]+)", "(?P<web_backend_service>[^/]+)"}, d, config, d.Id())
if err != nil {
return err
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions google-beta/iam_iap_web_backend_service_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]"
}
Expand Down Expand Up @@ -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)
Expand All @@ -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:[email protected]"]
}
Expand All @@ -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:[email protected]", "user:[email protected]"]
}
Expand Down
8 changes: 4 additions & 4 deletions google-beta/iam_pubsub_topic_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]"
}
Expand All @@ -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)
Expand All @@ -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:[email protected]"]
}
Expand All @@ -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:[email protected]", "user:[email protected]"]
}
Expand Down
8 changes: 4 additions & 4 deletions google-beta/iam_source_repo_repository_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]"
}
Expand All @@ -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)
Expand All @@ -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:[email protected]"]
}
Expand All @@ -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:[email protected]", "user:[email protected]"]
}
Expand Down
14 changes: 7 additions & 7 deletions website/docs/r/iap_web_backend_service_iam.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
```
Expand All @@ -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:[email protected]",
Expand All @@ -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:[email protected]"
}
Expand All @@ -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.
Expand Down Expand Up @@ -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 [email protected]"
$ terraform import google_iap_web_backend_service_iam_member.editor "projects/{{project}}/iap_web/compute/services/{{web_backend_service}} roles/iap.httpsResourceAccessor [email protected]"
```

-> If you're importing a resource with beta features, make sure to include `-provider=google-beta`
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/pubsub_topic_iam.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
```
Expand All @@ -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:[email protected]",
Expand All @@ -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:[email protected]"
}
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/sourcerepo_repository_iam.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
```
Expand All @@ -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:[email protected]",
Expand All @@ -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:[email protected]"
}
Expand Down

0 comments on commit 77114d1

Please sign in to comment.