// ParseLegacyAbsProviderConfig parses the given traversal as an absolute
// provider address. The following are examples of traversals that can be
// successfully parsed as legacy absolute provider configuration addresses:
//
//     provider.aws
//     provider.aws.foo
//     module.bar.provider.aws
//     module.bar.module.baz.provider.aws.foo
//
// This type of address is used in legacy state and may appear in state v4 if
// the provider config addresses have not been normalized to include provider
// FQN.
ParseLegacyAbsProviderConfig parses the given traversal as an absolute
provider address. The following are examples of traversals that can be
successfully parsed as legacy absolute provider configuration addresses.

provider.aws
provider.aws.foo
module.bar.provider.aws
module.bar.module.baz.provider.aws.foo

This type of address is used in legacy state and may appear in state v4 if
the provider config addresses have not been normalized to include provider
FQN.
// ParseLegacyAbsProviderConfig parses the given traversal as an absolute // provider address . The following are examples of traversals that can be // successfully parsed as legacy absolute provider configuration addresses : // // provider . aws // provider . aws . foo // module . bar . provider . aws // module . bar . module . baz . provider . aws . foo // // This type of address is used in legacy state and may appear in state v4 if // the provider config addresses have not been normalized to include provider // FQN .
func ParseLegacyAbsProviderConfig(traversal hcl.Traversal) (AbsProviderConfig, tfdiags.Diagnostics) {
	modInst, remain, diags := parseModuleInstancePrefix(traversal)
	var ret AbsProviderConfig
	for _, step := range modInst {
		if step.InstanceKey != NoKey {
			diags = diags.Append(&hcl.Diagnostic{
				Severity: hcl.DiagError,
				Summary:  "Invalid provider configuration address",
				Detail:   "Provider address cannot contain module indexes",
				Subject:  remain.SourceRange().Ptr(),
			})
			return ret, diags
		}
	}
	ret.Module = modInst.Module()
	if len(remain) < 2 || remain.RootName() != "provider" {
		diags = diags.Append(&hcl.Diagnostic{
			Severity: hcl.DiagError,
			Summary:  "Invalid provider configuration address",
			Detail:   "Provider address must begin with \"provider.\", followed by a provider type name.",
			Subject:  remain.SourceRange().Ptr(),
		})
		return ret, diags
	}
	if len(remain) > 3 {
		diags = diags.Append(&hcl.Diagnostic{
			Severity: hcl.DiagError,
			Summary:  "Invalid provider configuration address",
			Detail:   "Extraneous operators after provider configuration alias.",
			Subject:  hcl.Traversal(remain[3:]).SourceRange().Ptr(),
		})
		return ret, diags
	}
	if tt, ok := remain[1].(hcl.TraverseAttr); ok {
		if tt.Name == "terraform" {
			ret.Provider = NewBuiltInProvider(tt.Name)
		} else {
			ret.Provider = NewLegacyProvider(tt.Name)
		}
	} else {
		diags = diags.Append(&hcl.Diagnostic{
			Severity: hcl.DiagError,
			Summary:  "Invalid provider configuration address",
			Detail:   "The prefix \"provider.\" must be followed by a provider type name.",
			Subject:  remain[1].SourceRange().Ptr(),
		})
		return ret, diags
	}
	if len(remain) == 3 {
		if tt, ok := remain[2].(hcl.TraverseAttr); ok {
			ret.Alias = tt.Name
		} else {
			diags = diags.Append(&hcl.Diagnostic{
				Severity: hcl.DiagError,
				Summary:  "Invalid provider configuration address",
				Detail:   "Provider type name must be followed by a configuration alias name.",
				Subject:  remain[2].SourceRange().Ptr(),
			})
			return ret, diags
		}
	}
	return ret, diags
}
func ParseLegacyAbsProviderConfig ( traversal hcl . Traversal ) ( AbsProviderConfig , tfdiags . Diagnostics ) { modInst , remain , diags := parseModuleInstancePrefix ( traversal ) var ret AbsProviderConfig for _ , step := range modInst { if step . InstanceKey != NoKey { diags = diags . Append ( & hcl . Diagnostic { Severity : hcl . DiagError , Summary : " " , Detail : " " , Subject : remain . SourceRange ( ) . Ptr ( ) , } ) return ret , diags } } ret . Module = modInst . Module ( ) if len ( remain ) < 2 || remain . RootName ( ) != " " { diags = diags . Append ( & hcl . Diagnostic { Severity : hcl . DiagError , Summary : " " , Detail : " \" \" " , Subject : remain . SourceRange ( ) . Ptr ( ) , } ) return ret , diags } if len ( remain ) > 3 { diags = diags . Append ( & hcl . Diagnostic { Severity : hcl . DiagError , Summary : " " , Detail : " " , Subject : hcl . Traversal ( remain [ 3 : ] ) . SourceRange ( ) . Ptr ( ) , } ) return ret , diags } if tt , ok := remain [ 1 ] . ( hcl . TraverseAttr ) ; ok { if tt . Name == " " { ret . Provider = NewBuiltInProvider ( tt . Name ) } else { ret . Provider = NewLegacyProvider ( tt . Name ) } } else { diags = diags . Append ( & hcl . Diagnostic { Severity : hcl . DiagError , Summary : " " , Detail : " \" \" " , Subject : remain [ 1 ] . SourceRange ( ) . Ptr ( ) , } ) return ret , diags } if len ( remain ) == 3 { if tt , ok := remain [ 2 ] . ( hcl . TraverseAttr ) ; ok { ret . Alias = tt . Name } else { diags = diags . Append ( & hcl . Diagnostic { Severity : hcl . DiagError , Summary : " " , Detail : " " , Subject : remain [ 2 ] . SourceRange ( ) . Ptr ( ) , } ) return ret , diags } } return ret , diags }
ParseLegacyAbsProviderConfig parses the given traversal as an absolute
provider address.
ParseLegacyAbsProviderConfig parses the given traversal as an absolute provider address .
// Providers cannot resolve within module instances, so verify that there // are no instance keys in the module path before converting to a Module. // We always assume legacy-style providers in legacy state ... // ... unless it's the builtin "terraform" provider, a special case.