Skip to content

Commit 3aa06ab

Browse files
authored
Removed ReadProperties method (GoogleCloudPlatform#16219)
1 parent 598e4df commit 3aa06ab

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

mmv1/api/resource.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,10 @@ func (r Resource) UnorderedListProperties() []*Type {
726726
})
727727
}
728728

729-
// Properties that will be returned in the API body
729+
// Properties that are read from the API response.
730730
func (r Resource) GettableProperties() []*Type {
731731
return google.Reject(r.AllUserProperties(), func(v *Type) bool {
732-
return v.UrlParamOnly
732+
return v.UrlParamOnly || v.IgnoreRead
733733
})
734734
}
735735

@@ -1490,7 +1490,7 @@ func (r Resource) HasPostCreateComputedFields() bool {
14901490
if _, ok := fields[google.Underscore(p.Name)]; !ok {
14911491
continue
14921492
}
1493-
if (p.Output || p.DefaultFromApi) && !p.IgnoreRead {
1493+
if p.Output || p.DefaultFromApi {
14941494
return true
14951495
}
14961496
}
@@ -1501,14 +1501,8 @@ func (r Resource) HasPostCreateComputedFields() bool {
15011501
// Template Methods
15021502
// ====================
15031503
// Functions used to create slices of resource properties that could not otherwise be called from within generating templates.
1504-
func (r Resource) ReadProperties() []*Type {
1505-
return google.Reject(r.GettableProperties(), func(p *Type) bool {
1506-
return p.IgnoreRead
1507-
})
1508-
}
1509-
15101504
func (r Resource) FlattenedProperties() []*Type {
1511-
return google.Select(r.ReadProperties(), func(p *Type) bool {
1505+
return google.Select(r.GettableProperties(), func(p *Type) bool {
15121506
return p.FlattenObject
15131507
})
15141508
}

mmv1/templates/terraform/resource.go.tmpl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,19 @@ func resource{{ $.ResourceName -}}Create(d *schema.ResourceData, meta interface{
388388
{{- $renderedIdFromName := "false" }}
389389
{{- range $prop := $.GettableProperties }}
390390
{{- /* Check if prop is potentially computed */}}
391-
{{- if and ($.InPostCreateComputed $prop) (and (or $prop.Output $prop.DefaultFromApi) (not $prop.IgnoreRead)) }}
391+
{{- if and ($.InPostCreateComputed $prop) (or $prop.Output $prop.DefaultFromApi) }}
392392
{{- if and (eq $prop.CustomFlatten "templates/terraform/custom_flatten/id_from_name.tmpl") (eq $renderedIdFromName "false") }}
393393
// Setting `name` field so that `id_from_name` flattener will work properly.
394394
if err := d.Set("name", flatten{{ if $.NestedQuery -}}Nested{{end}}{{ $.ResourceName -}}Name(opRes["name"], d, config)); err != nil {
395395
return err
396396
}
397397
{{- $renderedIdFromName = "true" }}
398398
{{- end }}
399-
{{- if and $prop.Output (not $prop.IgnoreRead) }}
399+
{{- if $prop.Output }}
400400
if err := d.Set("{{ underscore $prop.Name -}}", flatten{{ if $.NestedQuery -}}Nested{{end}}{{ $.ResourceName -}}{{ camelize $prop.Name "upper" -}}(opRes["{{ $prop.ApiName -}}"], d, config)); err != nil {
401401
return err
402402
}
403-
{{- else if and $prop.DefaultFromApi (not $prop.IgnoreRead) }}
403+
{{- else if $prop.DefaultFromApi }}
404404
// {{ underscore $prop.Name }} is set by API when unset
405405
if tpgresource.IsEmptyValue(reflect.ValueOf(d.Get("{{ underscore $prop.Name }}"))) {
406406
if err := d.Set("{{ underscore $prop.Name -}}", flatten{{ if $.NestedQuery -}}Nested{{end}}{{ $.ResourceName -}}{{ camelize $prop.Name "upper" -}}(opRes["{{ $prop.ApiName -}}"], d, config)); err != nil {
@@ -689,7 +689,7 @@ func resource{{ $.ResourceName -}}Read(d *schema.ResourceData, meta interface{})
689689
return fmt.Errorf("Error reading {{ $.Name -}}: %s", err)
690690
}
691691
{{- end}}
692-
{{ range $prop := $.ReadProperties }}
692+
{{ range $prop := $.GettableProperties }}
693693
{{if $prop.FlattenObject -}}
694694
// Terraform must set the top level schema field, but since this object contains collapsed properties
695695
// it's difficult to know what the top level should be. Instead we just loop over the map returned from flatten.
@@ -1216,9 +1216,7 @@ func resource{{ $.ResourceName }}Import(d *schema.ResourceData, meta interface{}
12161216
}
12171217
{{ end }}
12181218
{{- range $prop := $.GettableProperties }}
1219-
{{- if not $prop.IgnoreRead }}
1220-
{{ template "flattenPropertyMethod" $prop -}}
1221-
{{- end }}
1219+
{{ template "flattenPropertyMethod" $prop -}}
12221220
{{- end }}
12231221
{{- range $prop := $.SettableProperties }}
12241222
{{- template "expandPropertyMethod" $prop -}}
@@ -1284,19 +1282,19 @@ func resource{{ $.ResourceName -}}PostCreateSetComputedFields(d *schema.Resource
12841282
{{- $renderedIdFromName := "false" }}
12851283
{{- range $prop := $.GettableProperties }}
12861284
{{- /* Check if prop is potentially computed */}}
1287-
{{- if and ($.InPostCreateComputed $prop) (and (or $prop.Output $prop.DefaultFromApi) (not $prop.IgnoreRead)) }}
1285+
{{- if and ($.InPostCreateComputed $prop) (or $prop.Output $prop.DefaultFromApi) }}
12881286
{{- if and (eq $prop.CustomFlatten "templates/terraform/custom_flatten/id_from_name.tmpl") (eq $renderedIdFromName "false") }}
12891287
// Setting `name` field so that `id_from_name` flattener will work properly.
12901288
if err := d.Set("name", flatten{{ if $.NestedQuery -}}Nested{{end}}{{ $.ResourceName -}}Name(res["name"], d, config)); err != nil {
12911289
return fmt.Errorf(`Error setting computed identity field "name": %s`, err)
12921290
}
12931291
{{- $renderedIdFromName = "true" }}
12941292
{{- end }}
1295-
{{- if and $prop.Output (not $prop.IgnoreRead) }}
1293+
{{- if $prop.Output }}
12961294
if err := d.Set("{{ underscore $prop.Name -}}", flatten{{ if $.NestedQuery -}}Nested{{end}}{{ $.ResourceName -}}{{ camelize $prop.Name "upper" -}}(res["{{ $prop.ApiName -}}"], d, config)); err != nil {
12971295
return fmt.Errorf(`Error setting computed identity field "{{ underscore $prop.Name }}": %s`, err)
12981296
}
1299-
{{- else if and $prop.DefaultFromApi (not $prop.IgnoreRead) }}
1297+
{{- else if $prop.DefaultFromApi }}
13001298
// {{ underscore $prop.Name }} is set by API when unset
13011299
if tpgresource.IsEmptyValue(reflect.ValueOf(d.Get("{{ underscore $prop.Name }}"))) {
13021300
if err := d.Set("{{ underscore $prop.Name -}}", flatten{{ if $.NestedQuery -}}Nested{{end}}{{ $.ResourceName -}}{{ camelize $prop.Name "upper" -}}(res["{{ $prop.ApiName -}}"], d, config)); err != nil {

mmv1/templates/terraform/resource_fw.go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ func (r *{{$.ResourceName}}FWResource) {{$.ResourceName}}FWRefresh(ctx context.C
805805
}
806806
}
807807

808-
{{ range $prop := $.ReadProperties }}
808+
{{ range $prop := $.GettableProperties }}
809809
data.{{camelize $prop.Name "upper"}} = res["{{ $prop.ApiName -}}"]
810810
{{$prop.ApiName}}Prop, d := data.{{camelize $prop.Name "upper"}}.To{{$prop.GetFWType}}Value(ctx)
811811
diags.Append(d...)

0 commit comments

Comments
 (0)