// ParseAbsProviderConfig parses the given traversal as an absolute provider
// address. The following are examples of traversals that can be successfully
// parsed as absolute provider configuration addresses:
//
//     provider["registry.terraform.io/hashicorp/aws"]
//     provider["registry.terraform.io/hashicorp/aws"].foo
//     module.bar.provider["registry.terraform.io/hashicorp/aws"]
//     module.bar.module.baz.provider["registry.terraform.io/hashicorp/aws"].foo
//
// This type of address is used, for example, to record the relationships
// between resources and provider configurations in the state structure.
// This type of address is not generally used in the UI, except in error
// messages that refer to provider configurations.
ParseAbsProviderConfig parses the given traversal as an absolute provider
address. The following are examples of traversals that can be successfully
parsed as absolute provider configuration addresses.

provider["registry.terraform.io/hashicorp/aws"]
provider["registry.terraform.io/hashicorp/aws"].foo
module.bar.provider["registry.terraform.io/hashicorp/aws"]
module.bar.module.baz.provider["registry.terraform.io/hashicorp/aws"].foo

This type of address is used, for example, to record the relationships
between resources and provider configurations in the state structure.
This type of address is not generally used in the UI, except in error
messages that refer to provider configurations.
// ParseAbsProviderConfig parses the given traversal as an absolute provider // address . The following are examples of traversals that can be successfully // parsed as absolute provider configuration addresses : // // provider [ " registry . terraform . io / hashicorp / aws " ] // provider [ " registry . terraform . io / hashicorp / aws " ] . foo // module . bar . provider [ " registry . terraform . io / hashicorp / aws " ] // module . bar . module . baz . provider [ " registry . terraform . io / hashicorp / aws " ] . foo // // This type of address is used for example to record the relationships // between resources and provider configurations in the state structure . // This type of address is not generally used in the UI except in error // messages that refer to provider configurations .
func ParseAbsProviderConfig(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.TraverseIndex); ok {
		if !tt.Key.Type().Equals(cty.String) {
			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
		}
		p, sourceDiags := ParseProviderSourceString(tt.Key.AsString())
		ret.Provider = p
		if sourceDiags.HasErrors() {
			diags = diags.Append(sourceDiags)
			return ret, diags
		}
	} 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 ParseAbsProviderConfig ( 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 . TraverseIndex ) ; ok { if ! tt . Key . Type ( ) . Equals ( cty . String ) { diags = diags . Append ( & hcl . Diagnostic { Severity : hcl . DiagError , Summary : " " , Detail : " \" \" " , Subject : remain [ 1 ] . SourceRange ( ) . Ptr ( ) , } ) return ret , diags } p , sourceDiags := ParseProviderSourceString ( tt . Key . AsString ( ) ) ret . Provider = p if sourceDiags . HasErrors ( ) { diags = diags . Append ( sourceDiags ) return ret , diags } } 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 }
ParseAbsProviderConfig parses the given traversal as an absolute provider
address.
ParseAbsProviderConfig 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.