Skip to content

Commit ecf214e

Browse files
authored
Fixed TF<>API mapping for nested_query fine-grained resources (GoogleCloudPlatform#16591)
1 parent ddbe96b commit ecf214e

16 files changed

Lines changed: 34 additions & 8 deletions

mmv1/api/resource.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ type Resource struct {
5454
// organization variant, however most resources do not need it.
5555
ApiVariantPatterns []string `yaml:"api_variant_patterns,omitempty"`
5656

57+
// ApiResourceField indicates what field on the API resource is managed by a resource.
58+
// This is generally relevant for fine-grained resources. For example,
59+
// google_compute_router_nat manages the `nat` field on the `Router` resource. Can be
60+
// set to "." to indicate explicitly that the resource's fields aren't
61+
// "nested", even if the resource uses NestedQuery. This is useful for resources that
62+
// use "list" instead of "get" as the read endpoint.
63+
ApiResourceField string `yaml:"api_resource_field,omitempty"`
64+
5765
// [Required] A description of the resource that's surfaced in provider
5866
// documentation.
5967
Description string
@@ -323,11 +331,6 @@ type Resource struct {
323331
// The version name provided by the user through CI
324332
TargetVersionName string `yaml:"-"`
325333

326-
// ApiResourceField indicates what field on the API resource is managed by a resource.
327-
// This is generally relevant for fine-grained resources. For example,
328-
// google_compute_router_nat manages the `nat` field on the `Router` resource.
329-
ApiResourceField string `yaml:"api_resource_field,omitempty"`
330-
331334
ImportPath string `yaml:"-"`
332335
SourceYamlFile string `yaml:"-"`
333336

mmv1/api/type.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,19 @@ func (t Type) Lineage() []string {
579579
// include the field on the API resource that the fine-grained resource manages.
580580
func (t Type) ApiLineage() []string {
581581
if t.ParentMetadata == nil {
582-
if !t.UrlParamOnly && t.ResourceMetadata.ApiResourceField != "" {
583-
return []string{t.ResourceMetadata.ApiResourceField, t.ApiName}
582+
// The special value "." indicates that the resource's shouldn't be considered "nested"
583+
// even if it has NestedQuery set.
584+
if !t.UrlParamOnly && t.ResourceMetadata.ApiResourceField != "." {
585+
if t.ResourceMetadata.ApiResourceField != "" {
586+
return []string{t.ResourceMetadata.ApiResourceField, t.ApiName}
587+
} else if t.ResourceMetadata.NestedQuery != nil {
588+
// Handle `items` as a special case since that's a common container field name for a list endpoint,
589+
// not a fine-grained field name within a resource.
590+
keys := t.ResourceMetadata.NestedQuery.Keys
591+
if len(keys) > 1 || keys[0] != "items" {
592+
return append(t.ResourceMetadata.NestedQuery.Keys, t.ApiName)
593+
}
594+
}
584595
}
585596
return []string{t.ApiName}
586597
}

mmv1/products/accesscontextmanager/AccessLevelCondition.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,4 @@ properties:
255255
The name of the Access Policy this resource belongs to.
256256
ignore_read: true
257257
output: true
258+
client_side: true

mmv1/products/accesscontextmanager/EgressPolicy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ properties:
8080
The name of the Access Policy this resource belongs to.
8181
ignore_read: true
8282
output: true
83+
client_side: true

mmv1/products/accesscontextmanager/IngressPolicy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ properties:
8080
The name of the Access Policy this resource belongs to.
8181
ignore_read: true
8282
output: true
83+
client_side: true

mmv1/products/accesscontextmanager/ServicePerimeterDryRunEgressPolicy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ properties:
232232
The name of the Access Policy this resource belongs to.
233233
ignore_read: true
234234
output: true
235+
client_side: true
235236
- name: 'etag'
236237
type: String
237238
output: true

mmv1/products/accesscontextmanager/ServicePerimeterDryRunIngressPolicy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ properties:
231231
The name of the Access Policy this resource belongs to.
232232
ignore_read: true
233233
output: true
234+
client_side: true
234235
- name: 'etag'
235236
type: String
236237
output: true

mmv1/products/accesscontextmanager/ServicePerimeterDryRunResource.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ properties:
108108
The name of the Access Policy this resource belongs to.
109109
ignore_read: true
110110
output: true
111+
client_side: true
111112
- name: 'etag'
112113
type: String
113114
output: true

mmv1/products/accesscontextmanager/ServicePerimeterEgressPolicy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ properties:
230230
The name of the Access Policy this resource belongs to.
231231
ignore_read: true
232232
output: true
233+
client_side: true
233234
- name: 'etag'
234235
type: String
235236
output: true

mmv1/products/accesscontextmanager/ServicePerimeterIngressPolicy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ properties:
233233
The name of the Access Policy this resource belongs to.
234234
ignore_read: true
235235
output: true
236+
client_side: true
236237
- name: 'etag'
237238
type: String
238239
output: true

0 commit comments

Comments
 (0)