2018-03-31 04:58:57 +02:00
|
|
|
package addrs
|
|
|
|
|
2018-04-07 03:45:16 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
2020-03-09 22:11:57 +01:00
|
|
|
"strings"
|
2018-04-24 01:58:01 +02:00
|
|
|
|
2021-05-17 19:11:06 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
2020-02-14 15:06:50 +01:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
2018-04-24 01:58:01 +02:00
|
|
|
|
2019-09-10 00:58:44 +02:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
|
|
"github.com/hashicorp/hcl/v2/hclsyntax"
|
2018-04-07 03:45:16 +02:00
|
|
|
)
|
|
|
|
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
// ProviderConfig is an interface type whose dynamic type can be either
|
|
|
|
// LocalProviderConfig or AbsProviderConfig, in order to represent situations
|
|
|
|
// where a value might either be module-local or absolute but the decision
|
|
|
|
// cannot be made until runtime.
|
|
|
|
//
|
|
|
|
// Where possible, use either LocalProviderConfig or AbsProviderConfig directly
|
|
|
|
// instead, to make intent more clear. ProviderConfig can be used only in
|
|
|
|
// situations where the recipient of the value has some out-of-band way to
|
|
|
|
// determine a "current module" to use if the value turns out to be
|
|
|
|
// a LocalProviderConfig.
|
|
|
|
//
|
|
|
|
// Recipients of non-nil ProviderConfig values that actually need
|
|
|
|
// AbsProviderConfig values should call ResolveAbsProviderAddr on the
|
|
|
|
// *configs.Config value representing the root module configuration, which
|
|
|
|
// handles the translation from local to fully-qualified using mapping tables
|
|
|
|
// defined in the configuration.
|
|
|
|
//
|
|
|
|
// Recipients of a ProviderConfig value can assume it can contain only a
|
|
|
|
// LocalProviderConfig value, an AbsProviderConfigValue, or nil to represent
|
|
|
|
// the absense of a provider config in situations where that is meaningful.
|
|
|
|
type ProviderConfig interface {
|
|
|
|
providerConfig()
|
|
|
|
}
|
|
|
|
|
|
|
|
// LocalProviderConfig is the address of a provider configuration from the
|
|
|
|
// perspective of references in a particular module.
|
|
|
|
//
|
|
|
|
// Finding the corresponding AbsProviderConfig will require looking up the
|
|
|
|
// LocalName in the providers table in the module's configuration; there is
|
|
|
|
// no syntax-only translation between these types.
|
|
|
|
type LocalProviderConfig struct {
|
|
|
|
LocalName string
|
2018-03-31 04:58:57 +02:00
|
|
|
|
|
|
|
// If not empty, Alias identifies which non-default (aliased) provider
|
|
|
|
// configuration this address refers to.
|
|
|
|
Alias string
|
|
|
|
}
|
2018-04-07 03:45:16 +02:00
|
|
|
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
var _ ProviderConfig = LocalProviderConfig{}
|
|
|
|
|
|
|
|
// NewDefaultLocalProviderConfig returns the address of the default (un-aliased)
|
|
|
|
// configuration for the provider with the given local type name.
|
|
|
|
func NewDefaultLocalProviderConfig(LocalNameName string) LocalProviderConfig {
|
|
|
|
return LocalProviderConfig{
|
|
|
|
LocalName: LocalNameName,
|
2018-04-30 19:06:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
// providerConfig Implements addrs.ProviderConfig.
|
|
|
|
func (pc LocalProviderConfig) providerConfig() {}
|
|
|
|
|
|
|
|
func (pc LocalProviderConfig) String() string {
|
|
|
|
if pc.LocalName == "" {
|
2018-05-08 20:33:04 +02:00
|
|
|
// Should never happen; always indicates a bug
|
|
|
|
return "provider.<invalid>"
|
|
|
|
}
|
|
|
|
|
2018-04-07 03:45:16 +02:00
|
|
|
if pc.Alias != "" {
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
return fmt.Sprintf("provider.%s.%s", pc.LocalName, pc.Alias)
|
2018-04-07 03:45:16 +02:00
|
|
|
}
|
|
|
|
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
return "provider." + pc.LocalName
|
2018-04-07 03:45:16 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 19:06:05 +02:00
|
|
|
// StringCompact is an alternative to String that returns the form that can
|
|
|
|
// be parsed by ParseProviderConfigCompact, without the "provider." prefix.
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
func (pc LocalProviderConfig) StringCompact() string {
|
2018-04-30 19:06:05 +02:00
|
|
|
if pc.Alias != "" {
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
return fmt.Sprintf("%s.%s", pc.LocalName, pc.Alias)
|
2018-04-30 19:06:05 +02:00
|
|
|
}
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
return pc.LocalName
|
2018-04-30 19:06:05 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 03:45:16 +02:00
|
|
|
// AbsProviderConfig is the absolute address of a provider configuration
|
|
|
|
// within a particular module instance.
|
|
|
|
type AbsProviderConfig struct {
|
2020-03-09 22:11:57 +01:00
|
|
|
Module Module
|
2020-02-13 21:32:58 +01:00
|
|
|
Provider Provider
|
|
|
|
Alias string
|
2018-04-07 03:45:16 +02:00
|
|
|
}
|
|
|
|
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
var _ ProviderConfig = AbsProviderConfig{}
|
|
|
|
|
2018-04-24 01:58:01 +02:00
|
|
|
// 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:
|
|
|
|
//
|
2020-02-14 15:06:50 +01:00
|
|
|
// 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
|
2018-04-24 01:58:01 +02:00
|
|
|
//
|
|
|
|
// 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)
|
2020-03-09 22:11:57 +01:00
|
|
|
var ret AbsProviderConfig
|
|
|
|
|
|
|
|
// Providers cannot resolve within module instances, so verify that there
|
|
|
|
// are no instance keys in the module path before converting to a Module.
|
|
|
|
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
|
|
|
|
}
|
2018-04-24 01:58:01 +02:00
|
|
|
}
|
2020-03-09 22:11:57 +01:00
|
|
|
ret.Module = modInst.Module()
|
|
|
|
|
2018-04-24 01:58:01 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:32:58 +01:00
|
|
|
if tt, ok := remain[1].(hcl.TraverseIndex); ok {
|
2020-02-14 15:06:50 +01:00
|
|
|
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
|
|
|
|
}
|
2020-02-13 21:32:58 +01:00
|
|
|
p, sourceDiags := ParseProviderSourceString(tt.Key.AsString())
|
|
|
|
ret.Provider = p
|
|
|
|
if sourceDiags.HasErrors() {
|
|
|
|
diags = diags.Append(sourceDiags)
|
|
|
|
return ret, diags
|
|
|
|
}
|
2018-04-24 01:58:01 +02:00
|
|
|
} 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 {
|
2020-02-13 21:32:58 +01:00
|
|
|
ret.Alias = tt.Name
|
2018-04-24 01:58:01 +02:00
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
2018-05-31 20:59:19 +02:00
|
|
|
// ParseAbsProviderConfigStr is a helper wrapper around ParseAbsProviderConfig
|
|
|
|
// that takes a string and parses it with the HCL native syntax traversal parser
|
|
|
|
// before interpreting it.
|
|
|
|
//
|
|
|
|
// This should be used only in specialized situations since it will cause the
|
|
|
|
// created references to not have any meaningful source location information.
|
|
|
|
// If a reference string is coming from a source that should be identified in
|
|
|
|
// error messages then the caller should instead parse it directly using a
|
|
|
|
// suitable function from the HCL API and pass the traversal itself to
|
|
|
|
// ParseAbsProviderConfig.
|
|
|
|
//
|
|
|
|
// Error diagnostics are returned if either the parsing fails or the analysis
|
|
|
|
// of the traversal fails. There is no way for the caller to distinguish the
|
|
|
|
// two kinds of diagnostics programmatically. If error diagnostics are returned
|
|
|
|
// the returned address is invalid.
|
|
|
|
func ParseAbsProviderConfigStr(str string) (AbsProviderConfig, tfdiags.Diagnostics) {
|
|
|
|
var diags tfdiags.Diagnostics
|
2020-02-13 21:32:58 +01:00
|
|
|
traversal, parseDiags := hclsyntax.ParseTraversalAbs([]byte(str), "", hcl.Pos{Line: 1, Column: 1})
|
|
|
|
diags = diags.Append(parseDiags)
|
|
|
|
if parseDiags.HasErrors() {
|
|
|
|
return AbsProviderConfig{}, diags
|
|
|
|
}
|
|
|
|
addr, addrDiags := ParseAbsProviderConfig(traversal)
|
|
|
|
diags = diags.Append(addrDiags)
|
|
|
|
return addr, diags
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseLegacyAbsProviderConfigStr(str string) (AbsProviderConfig, tfdiags.Diagnostics) {
|
|
|
|
var diags tfdiags.Diagnostics
|
2018-05-31 20:59:19 +02:00
|
|
|
|
|
|
|
traversal, parseDiags := hclsyntax.ParseTraversalAbs([]byte(str), "", hcl.Pos{Line: 1, Column: 1})
|
|
|
|
diags = diags.Append(parseDiags)
|
|
|
|
if parseDiags.HasErrors() {
|
|
|
|
return AbsProviderConfig{}, diags
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:32:58 +01:00
|
|
|
addr, addrDiags := ParseLegacyAbsProviderConfig(traversal)
|
2018-05-31 20:59:19 +02:00
|
|
|
diags = diags.Append(addrDiags)
|
|
|
|
return addr, diags
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:32:58 +01:00
|
|
|
// 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)
|
2020-03-09 22:11:57 +01:00
|
|
|
var ret AbsProviderConfig
|
|
|
|
|
|
|
|
// Providers cannot resolve within module instances, so verify that there
|
|
|
|
// are no instance keys in the module path before converting to a Module.
|
|
|
|
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
|
|
|
|
}
|
2020-02-13 21:32:58 +01:00
|
|
|
}
|
2020-03-09 22:11:57 +01:00
|
|
|
ret.Module = modInst.Module()
|
2020-02-13 21:32:58 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-06-08 14:27:36 +02:00
|
|
|
// We always assume legacy-style providers in legacy state ...
|
2020-02-13 21:32:58 +01:00
|
|
|
if tt, ok := remain[1].(hcl.TraverseAttr); ok {
|
2020-06-08 14:27:36 +02:00
|
|
|
// ... unless it's the builtin "terraform" provider, a special case.
|
|
|
|
if tt.Name == "terraform" {
|
|
|
|
ret.Provider = NewBuiltInProvider(tt.Name)
|
|
|
|
} else {
|
|
|
|
ret.Provider = NewLegacyProvider(tt.Name)
|
|
|
|
}
|
2020-02-13 21:32:58 +01:00
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:06:50 +01:00
|
|
|
// ProviderConfigDefault returns the address of the default provider config of
|
|
|
|
// the given type inside the recieving module instance.
|
|
|
|
func (m ModuleInstance) ProviderConfigDefault(provider Provider) AbsProviderConfig {
|
2018-05-04 22:22:02 +02:00
|
|
|
return AbsProviderConfig{
|
2020-03-09 22:11:57 +01:00
|
|
|
Module: m.Module(),
|
2020-02-14 15:06:50 +01:00
|
|
|
Provider: provider,
|
2018-05-04 22:22:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:06:50 +01:00
|
|
|
// ProviderConfigAliased returns the address of an aliased provider config of
|
|
|
|
// the given type and alias inside the recieving module instance.
|
|
|
|
func (m ModuleInstance) ProviderConfigAliased(provider Provider, alias string) AbsProviderConfig {
|
2018-05-04 22:22:02 +02:00
|
|
|
return AbsProviderConfig{
|
2020-03-09 22:11:57 +01:00
|
|
|
Module: m.Module(),
|
2020-02-14 15:06:50 +01:00
|
|
|
Provider: provider,
|
2020-02-13 21:32:58 +01:00
|
|
|
Alias: alias,
|
2018-05-04 22:22:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses
In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.
This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.
In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
package, including removing addrs.NewLegacyProvider and
addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
work with addrs.Provider to identify providers, rather than legacy
strings.
In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.
* addrs: ProviderConfig interface
In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.
We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.
In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.
This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.
* rename LocalType to LocalName
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 14:23:07 +01:00
|
|
|
// providerConfig Implements addrs.ProviderConfig.
|
|
|
|
func (pc AbsProviderConfig) providerConfig() {}
|
|
|
|
|
2018-04-24 02:19:55 +02:00
|
|
|
// Inherited returns an address that the receiving configuration address might
|
|
|
|
// inherit from in a parent module. The second bool return value indicates if
|
|
|
|
// such inheritance is possible, and thus whether the returned address is valid.
|
|
|
|
//
|
|
|
|
// Inheritance is possible only for default (un-aliased) providers in modules
|
|
|
|
// other than the root module. Even if a valid address is returned, inheritence
|
|
|
|
// may not be performed for other reasons, such as if the calling module
|
|
|
|
// provided explicit provider configurations within the call for this module.
|
2020-02-14 15:06:50 +01:00
|
|
|
// The ProviderTransformer graph transform in the main terraform module has the
|
|
|
|
// authoritative logic for provider inheritance, and this method is here mainly
|
|
|
|
// just for its benefit.
|
2018-04-24 02:19:55 +02:00
|
|
|
func (pc AbsProviderConfig) Inherited() (AbsProviderConfig, bool) {
|
|
|
|
// Can't inherit if we're already in the root.
|
|
|
|
if len(pc.Module) == 0 {
|
|
|
|
return AbsProviderConfig{}, false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't inherit if we have an alias.
|
2020-02-13 21:32:58 +01:00
|
|
|
if pc.Alias != "" {
|
2018-04-24 02:19:55 +02:00
|
|
|
return AbsProviderConfig{}, false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we might inherit from a configuration with the same
|
2020-02-13 21:32:58 +01:00
|
|
|
// provider type in the parent module instance.
|
2018-04-24 02:19:55 +02:00
|
|
|
parentMod := pc.Module.Parent()
|
2020-02-13 21:32:58 +01:00
|
|
|
return AbsProviderConfig{
|
|
|
|
Module: parentMod,
|
|
|
|
Provider: pc.Provider,
|
|
|
|
}, true
|
|
|
|
|
2018-04-24 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:32:58 +01:00
|
|
|
// LegacyString() returns a legacy-style AbsProviderConfig string and should only be used for legacy state shimming.
|
|
|
|
func (pc AbsProviderConfig) LegacyString() string {
|
|
|
|
if pc.Alias != "" {
|
|
|
|
if len(pc.Module) == 0 {
|
|
|
|
return fmt.Sprintf("%s.%s.%s", "provider", pc.Provider.LegacyString(), pc.Alias)
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf("%s.%s.%s.%s", pc.Module.String(), "provider", pc.Provider.LegacyString(), pc.Alias)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(pc.Module) == 0 {
|
|
|
|
return fmt.Sprintf("%s.%s", "provider", pc.Provider.LegacyString())
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s.%s.%s", pc.Module.String(), "provider", pc.Provider.LegacyString())
|
|
|
|
}
|
|
|
|
|
|
|
|
// String() returns a string representation of an AbsProviderConfig in the following format:
|
|
|
|
//
|
|
|
|
// provider["example.com/namespace/name"]
|
|
|
|
// provider["example.com/namespace/name"].alias
|
|
|
|
// module.module-name.provider["example.com/namespace/name"]
|
|
|
|
// module.module-name.provider["example.com/namespace/name"].alias
|
2018-04-07 03:45:16 +02:00
|
|
|
func (pc AbsProviderConfig) String() string {
|
2020-03-09 22:11:57 +01:00
|
|
|
var parts []string
|
|
|
|
if len(pc.Module) > 0 {
|
|
|
|
parts = append(parts, pc.Module.String())
|
2020-02-13 21:32:58 +01:00
|
|
|
}
|
2020-03-09 22:11:57 +01:00
|
|
|
|
|
|
|
parts = append(parts, fmt.Sprintf("provider[%q]", pc.Provider))
|
|
|
|
|
|
|
|
if pc.Alias != "" {
|
|
|
|
parts = append(parts, pc.Alias)
|
2018-04-24 01:58:01 +02:00
|
|
|
}
|
2020-02-13 21:32:58 +01:00
|
|
|
|
2020-03-09 22:11:57 +01:00
|
|
|
return strings.Join(parts, ".")
|
2018-04-07 03:45:16 +02:00
|
|
|
}
|