@@ -524,82 +524,38 @@ func (t *Type) Validate(rName string) {
524524// check the allowed types for Type field
525525// check the allowed fields for each type, for example, KeyName is only allowed for Map
526526
527- // Prints a dot notation path to where the field is nested within the parent
528- // object. eg: parent.meta.label.foo
529- // The only intended purpose is to allow better error messages. Some objects
530- // and at some points in the build this doesn't output a valid output.
531- func (t Type ) Lineage () string {
532- if t .ParentMetadata == nil {
533- return google .Underscore (t .Name )
534- }
535-
536- return fmt .Sprintf ("%s.%s" , t .ParentMetadata .Lineage (), google .Underscore (t .Name ))
537- }
538-
539- // Returns the actual Terraform lineage for the field, formatted for resource metadata.
540- // This will return a simple dot notation path, like: foo_field.bar_field
541- func (t Type ) MetadataLineage () string {
527+ // Returns a slice of Terraform field names representing where the field is nested within the parent resource.
528+ // For example, []string{"parent_field", "meta", "label", "foo_bar"}.
529+ func (t Type ) Lineage () []string {
542530 if t .ParentMetadata == nil || t .ParentMetadata .FlattenObject {
543- return google .Underscore (t .Name )
531+ return [] string { google .Underscore (t .Name )}
544532 }
545533
546- // Skip arrays because otherwise the array name will be included twice
534+ // Skip arrays because otherwise the array will be included twice
547535 if t .ParentMetadata .IsA ("Array" ) {
548- return t .ParentMetadata .MetadataLineage ()
536+ return t .ParentMetadata .Lineage ()
549537 }
550538
551- return fmt . Sprintf ( "%s.%s" , t .ParentMetadata .MetadataLineage (), google .Underscore (t .Name ))
539+ return append ( t .ParentMetadata .Lineage (), google .Underscore (t .Name ))
552540}
553541
554- // Returns the default Terraform lineage for the field, based on converting MetadataApiLineage
555- // to snake_case. This is used to determine whether an explicit Terraform field name is required.
556- // This will return a simple dot notation path like: foo_field.bar_field
557- func (t Type ) MetadataDefaultLineage () string {
558- apiLineage := t .MetadataApiLineage ()
559- parts := strings .Split (apiLineage , "." )
560- var snakeParts []string
561- for _ , p := range parts {
562- snakeParts = append (snakeParts , google .Underscore (p ))
563- }
564- return strings .Join (snakeParts , "." )
565- }
566-
567- // Returns the actual API lineage for the field (that is, using API names), formatted for
568- // resource metadata. This will return a simple dot notation path, like: fooField.barField
569- // This format is intended for to represent an API type.
570- func (t Type ) MetadataApiLineage () string {
571- apiName := t .ApiName
542+ // Returns a slice of API field names representing where the field is nested within the parent resource.
543+ // For example, []string{"parentField", "meta", "label", "fooBar"}. For fine-grained resources, this will
544+ // include the field on the API resource that the fine-grained resource manages.
545+ func (t Type ) ApiLineage () []string {
572546 if t .ParentMetadata == nil {
573547 if ! t .UrlParamOnly && t .ResourceMetadata .ApiResourceField != "" {
574- apiName = fmt . Sprintf ( "%s.%s" , t .ResourceMetadata .ApiResourceField , apiName )
548+ return [] string { t .ResourceMetadata .ApiResourceField , t . ApiName }
575549 }
576- return apiName
550+ return [] string { t . ApiName }
577551 }
578552
553+ // Skip arrays because otherwise the array will be included twice
579554 if t .ParentMetadata .IsA ("Array" ) {
580- return t .ParentMetadata .MetadataApiLineage ()
581- }
582-
583- return fmt .Sprintf ("%s.%s" , t .ParentMetadata .MetadataApiLineage (), apiName )
584- }
585-
586- // Returns the lineage in snake case
587- func (t Type ) LineageAsSnakeCase () string {
588- if t .ParentMetadata == nil {
589- return google .Underscore (t .Name )
590- }
591-
592- return fmt .Sprintf ("%s_%s" , t .ParentMetadata .LineageAsSnakeCase (), google .Underscore (t .Name ))
593- }
594-
595- // Prints the access path of the field in the configration eg: metadata.0.labels
596- // The only intended purpose is to get the value of the labes field by calling d.Get().
597- func (t Type ) TerraformLineage () string {
598- if t .ParentMetadata == nil || t .ParentMetadata .FlattenObject {
599- return google .Underscore (t .Name )
555+ return t .ParentMetadata .ApiLineage ()
600556 }
601557
602- return fmt . Sprintf ( "%s.0.%s" , t .ParentMetadata .TerraformLineage (), google . Underscore ( t . Name ) )
558+ return append ( t .ParentMetadata .ApiLineage (), t . ApiName )
603559}
604560
605561func (t Type ) EnumValuesToString (quoteSeperator string , addEmpty bool ) string {
@@ -1114,7 +1070,7 @@ func (t Type) AllProperties() []*Type {
11141070func (t Type ) UserProperties () []* Type {
11151071 if t .IsA ("NestedObject" ) {
11161072 if t .Properties == nil {
1117- log .Fatalf ("Field '{%s}' properties are nil!" , t .Lineage ())
1073+ log .Fatalf ("Field '{%s}' properties are nil!" , strings . Join ( t .Lineage (), "." ))
11181074 }
11191075
11201076 return google .Reject (t .Properties , func (p * Type ) bool {
@@ -1268,7 +1224,7 @@ func propertyWithAtLeastOneOfPointer(ptr *[]string) func(*Type) {
12681224func (t * Type ) validateLabelsField () {
12691225 productName := t .ResourceMetadata .ProductMetadata .Name
12701226 resourceName := t .ResourceMetadata .Name
1271- lineage := t .Lineage ()
1227+ lineage := strings . Join ( t .Lineage (), "." )
12721228 if lineage == "labels" || lineage == "metadata.labels" || lineage == "configuration.labels" {
12731229 if ! t .IsA ("KeyValueLabels" ) &&
12741230 // The label value must be empty string, so skip this resource
0 commit comments