Skip to content

Commit

Permalink
Remove diffs in iam documentations (#11027)
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 authored Jun 25, 2024
1 parent 1c89cc9 commit 4a08ebf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
28 changes: 20 additions & 8 deletions mmv1/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,15 +985,9 @@ func ImportIdFormats(importFormat, identity []string, baseUrl string) []string {
// `{{project}}/{{%name}}` as there is no way to differentiate between
// project-name/resource-name and resource-name/with-slash
if !strings.Contains(idFormats[0], "%") {
idFormats = append(idFormats, shortIdFormat, shortIdDefaultProjectFormat)
if shortIdDefaultProjectFormat != shortIdDefaultFormat {
idFormats = append(idFormats, shortIdDefaultFormat)
}
idFormats = append(idFormats, shortIdFormat, shortIdDefaultProjectFormat, shortIdDefaultFormat)
}

idFormats = google.Reject(slices.Compact(idFormats), func(i string) bool {
return i == ""
})
slices.SortFunc(idFormats, func(a, b string) int {
i := strings.Count(a, "/")
j := strings.Count(b, "/")
Expand All @@ -1003,7 +997,25 @@ func ImportIdFormats(importFormat, identity []string, baseUrl string) []string {
return i - j
})
slices.Reverse(idFormats)
return idFormats

// Remove duplicates from idFormats
uniq := make([]string, len(idFormats))
uniq[0] = idFormats[0]
i := 1
j := 1
for j < len(idFormats) {
format := idFormats[j]
if format != uniq[i-1] {
uniq[i] = format
i++
}
j++
}

uniq = google.Reject(slices.Compact(uniq), func(i string) bool {
return i == ""
})
return uniq
}

func (r Resource) IgnoreReadPropertiesToString(e resource.Examples) string {
Expand Down
17 changes: 8 additions & 9 deletions mmv1/templates/terraform/resource_iam.html.markdown.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ With IAM Conditions:

```hcl
data "google_iam_policy" "admin" {
{{ if eq $.MinVersionObj.Name "beta" }}
{{- if eq $.MinVersionObj.Name "beta" }}
provider = google-beta
{{- end }}
binding {
Expand Down Expand Up @@ -135,7 +135,7 @@ resource "{{ $.IamTerraformName }}_policy" "policy" {
resource "{{ $.IamTerraformName }}_binding" "binding" {
{{- if eq $.MinVersionObj.Name "beta" }}
provider = google-beta
{{- end -}}
{{- end }}
{{- $.CustomTemplate $.IamPolicy.ExampleConfigBody false }}
role = "{{if $.IamPolicy.AdminIamRole}}{{$.IamPolicy.AdminIamRole }}{{else}}{{$.IamPolicy.AllowedIamRole}}{{end}}"
members = [
Expand Down Expand Up @@ -169,22 +169,22 @@ resource "{{ $.IamTerraformName }}_binding" "binding" {

```hcl
resource "{{ $.IamTerraformName }}_member" "member" {
{{- if eq $.MinVersionObj.Name "beta" -}}
{{- if eq $.MinVersionObj.Name "beta" }}
provider = google-beta
{{- end -}}
{{- end }}
{{- $.CustomTemplate $.IamPolicy.ExampleConfigBody false }}
role = "{{if $.IamPolicy.AdminIamRole}}{{$.IamPolicy.AdminIamRole }}{{else}}{{$.IamPolicy.AllowedIamRole}}{{end}}"
member = "user:[email protected]"
}
```
{{ if $.IamPolicy.IamConditionsRequestType -}}
{{ if $.IamPolicy.IamConditionsRequestType }}
With IAM Conditions:

```hcl
resource "{{ $.IamTerraformName }}_member" "member" {
{{- if eq $.MinVersionObj.Name "beta" }}
provider = google-beta
{{- end -}}
{{- end }}
{{- $.CustomTemplate $.IamPolicy.ExampleConfigBody false }}
role = "{{if $.IamPolicy.AdminIamRole}}{{$.IamPolicy.AdminIamRole}}{{else}}{{$.IamPolicy.AllowedIamRole}}{{end}}"
member = "user:[email protected]"
Expand Down Expand Up @@ -245,8 +245,7 @@ The following arguments are supported:

* `policy_data` - (Required only by `{{ $.IamTerraformName }}_policy`) The policy data generated by
a `google_iam_policy` data source.

{{ if $.IamPolicy.IamConditionsRequestType -}}
{{ if $.IamPolicy.IamConditionsRequestType }}
* `condition` - (Optional) An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding.
Structure is documented below.

Expand All @@ -263,7 +262,7 @@ The `condition` block supports:
~> **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.
{{- end -}}
{{- end }}
## Attributes Reference

In addition to the arguments listed above, the following computed attributes are
Expand Down

0 comments on commit 4a08ebf

Please sign in to comment.