Skip to content

Commit 56ff575

Browse files
authored
resourceIdentity: generalize custom_identity (#15784)
2 parents f4ad889 + 93fe0ed commit 56ff575

File tree

10 files changed

+11
-69
lines changed

10 files changed

+11
-69
lines changed

mmv1/api/resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,12 @@ func (r Resource) IdentityProperties() []*Type {
656656
}
657657
}
658658

659+
if len(r.CustomCode.CustomIdentity) > 0 {
660+
for _, fieldName := range r.CustomCode.CustomIdentity {
661+
props = append(props, &Type{Name: google.Underscore(fieldName), Type: "string", Required: true})
662+
}
663+
}
664+
659665
return props
660666
}
661667

mmv1/api/resource/custom_code.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ type CustomCode struct {
130130

131131
// This code replaces the entire identity schema method. Since the identity schema method's function header can't be changed, the template
132132
// inserts that for you - do not include it in your custom code.
133-
CustomIdentitySchema *string `yaml:"custom_identity_schema,omitempty"`
134-
135-
// This code is run in the Read method to set the identity.
136-
CustomIdentityRead string `yaml:"custom_identity_read"`
133+
CustomIdentity []string `yaml:"custom_identity,omitempty"`
137134

138135
// This code is run just after the import method succeeds - it
139136
// is useful for parsing attributes that are necessary for

mmv1/products/apigee/AddonsConfig.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ async:
4141
custom_code:
4242
custom_import: 'templates/terraform/custom_import/apigee_addons.go.tmpl'
4343
test_check_destroy: 'templates/terraform/custom_check_destroy/apigee_addons_override.go.tmpl'
44-
custom_identity_schema: 'templates/terraform/custom_identity_schema/apigee_addons.go.tmpl'
45-
custom_identity_read: 'templates/terraform/custom_identity_read/apigee_addons.go.tmpl'
44+
custom_identity:
45+
- 'org'
4646
examples:
4747
- name: 'apigee_addons_basic'
4848
exclude_test: true

mmv1/products/iap/Brand.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ identity:
5757
- name
5858
custom_code:
5959
custom_import: 'templates/terraform/custom_import/iap_brand.go.tmpl'
60-
custom_identity_schema: 'templates/terraform/custom_identity_schema/iap_brand.go.tmpl'
61-
custom_identity_read: 'templates/terraform/custom_identity_read/iap_brand.go.tmpl'
60+
custom_identity:
61+
- 'project'
6262
examples:
6363
- name: 'iap_brand'
6464
primary_resource_id: 'project_brand'

mmv1/templates/terraform/custom_identity_read/apigee_addons.go.tmpl

Lines changed: 0 additions & 10 deletions
This file was deleted.

mmv1/templates/terraform/custom_identity_read/iap_brand.go.tmpl

Lines changed: 0 additions & 10 deletions
This file was deleted.

mmv1/templates/terraform/custom_identity_schema/addons_config.go.tmpl

Lines changed: 0 additions & 11 deletions
This file was deleted.

mmv1/templates/terraform/custom_identity_schema/apigee_addons.go.tmpl

Lines changed: 0 additions & 11 deletions
This file was deleted.

mmv1/templates/terraform/custom_identity_schema/iap_brand.go.tmpl

Lines changed: 0 additions & 11 deletions
This file was deleted.

mmv1/templates/terraform/resource.go.tmpl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ func Resource{{ $.ResourceName -}}() *schema.Resource {
163163
DeprecationMessage: "{{ $.DeprecationMessage -}}",
164164
{{- end}}
165165

166-
{{ if $.CustomCode.CustomIdentitySchema }}
167-
{{ $.CustomTemplate $.CustomCode.CustomIdentitySchema false -}}
168-
{{ else }}
169166
Identity: &schema.ResourceIdentity{
170167
Version: {{ $.GetIdentitySchemaVersion }},
171168
SchemaFunc: func() map[string]*schema.Schema {
@@ -194,7 +191,6 @@ func Resource{{ $.ResourceName -}}() *schema.Resource {
194191
},
195192
{{- end }}
196193
},
197-
{{- end }}
198194
Schema: map[string]*schema.Schema{
199195
{{- range $prop := $.OrderProperties $.AllUserProperties }}
200196
{{template "SchemaFields" $prop -}}
@@ -750,9 +746,6 @@ func resource{{ $.ResourceName -}}Read(d *schema.ResourceData, meta interface{})
750746
}
751747
{{- end}}
752748

753-
{{- if $.CustomCode.CustomIdentityRead }}
754-
{{ $.CustomTemplate $.CustomCode.CustomIdentityRead true -}}
755-
{{- else }}
756749
identity, err := d.Identity()
757750
if err != nil && identity != nil {
758751
{{- range $p := $.IdentityProperties }}
@@ -767,7 +760,6 @@ func resource{{ $.ResourceName -}}Read(d *schema.ResourceData, meta interface{})
767760
log.Printf("[DEBUG] identity not set: %s", err)
768761
}
769762
{{- end }}
770-
{{ end -}}
771763
return nil
772764
}
773765

0 commit comments

Comments
 (0)