core: Provider transformers don't use the set of all available providers
In earlier incarnations of these transformers we used the set of all available providers for tasks such as generating implied provider configuration nodes. However, in modern Terraform we can extract all of the information we need from the configuration itself, and so these transformers weren't actually using this set of provider addresses. These also ended up getting left behind as sets of string rather than sets of addrs.Provider in our earlier refactoring work, which didn't really matter because the result wasn't used anywhere anyway. Rather than updating these to use addrs.Provider instead, I've just removed the unused arguments entirely in the hope of making it easier to see what inputs these transformers use to make their decisions.
This commit is contained in:
parent
feb219a9c4
commit
d51921f085
|
@ -116,7 +116,7 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
|
||||||
&AttachResourceConfigTransformer{Config: b.Config},
|
&AttachResourceConfigTransformer{Config: b.Config},
|
||||||
|
|
||||||
// add providers
|
// add providers
|
||||||
TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config),
|
transformProviders(concreteProvider, b.Config),
|
||||||
|
|
||||||
// Remove modules no longer present in the config
|
// Remove modules no longer present in the config
|
||||||
&RemovedModuleTransformer{Config: b.Config, State: b.State},
|
&RemovedModuleTransformer{Config: b.Config, State: b.State},
|
||||||
|
|
|
@ -94,7 +94,7 @@ func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer {
|
||||||
// Attach the configuration to any resources
|
// Attach the configuration to any resources
|
||||||
&AttachResourceConfigTransformer{Config: b.Config},
|
&AttachResourceConfigTransformer{Config: b.Config},
|
||||||
|
|
||||||
TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config),
|
transformProviders(concreteProvider, b.Config),
|
||||||
|
|
||||||
// Destruction ordering. We require this only so that
|
// Destruction ordering. We require this only so that
|
||||||
// targeting below will prune the correct things.
|
// targeting below will prune the correct things.
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (b *EvalGraphBuilder) Steps() []GraphTransformer {
|
||||||
// Attach the state
|
// Attach the state
|
||||||
&AttachStateTransformer{State: b.State},
|
&AttachStateTransformer{State: b.State},
|
||||||
|
|
||||||
TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config),
|
transformProviders(concreteProvider, b.Config),
|
||||||
|
|
||||||
// Must attach schemas before ReferenceTransformer so that we can
|
// Must attach schemas before ReferenceTransformer so that we can
|
||||||
// analyze the configuration to find references.
|
// analyze the configuration to find references.
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
|
||||||
// Add the import steps
|
// Add the import steps
|
||||||
&ImportStateTransformer{Targets: b.ImportTargets, Config: b.Config},
|
&ImportStateTransformer{Targets: b.ImportTargets, Config: b.Config},
|
||||||
|
|
||||||
TransformProviders(b.Components.ResourceProviders(), concreteProvider, config),
|
transformProviders(concreteProvider, config),
|
||||||
|
|
||||||
// Must attach schemas before ReferenceTransformer so that we can
|
// Must attach schemas before ReferenceTransformer so that we can
|
||||||
// analyze the configuration to find references.
|
// analyze the configuration to find references.
|
||||||
|
|
|
@ -130,7 +130,7 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
|
||||||
&AttachResourceConfigTransformer{Config: b.Config},
|
&AttachResourceConfigTransformer{Config: b.Config},
|
||||||
|
|
||||||
// add providers
|
// add providers
|
||||||
TransformProviders(b.Components.ResourceProviders(), b.ConcreteProvider, b.Config),
|
transformProviders(b.ConcreteProvider, b.Config),
|
||||||
|
|
||||||
// Remove modules no longer present in the config
|
// Remove modules no longer present in the config
|
||||||
&RemovedModuleTransformer{Config: b.Config, State: b.State},
|
&RemovedModuleTransformer{Config: b.Config, State: b.State},
|
||||||
|
|
|
@ -11,19 +11,17 @@ import (
|
||||||
"github.com/hashicorp/terraform/internal/tfdiags"
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TransformProviders(providers []string, concrete ConcreteProviderNodeFunc, config *configs.Config) GraphTransformer {
|
func transformProviders(concrete ConcreteProviderNodeFunc, config *configs.Config) GraphTransformer {
|
||||||
return GraphTransformMulti(
|
return GraphTransformMulti(
|
||||||
// Add providers from the config
|
// Add providers from the config
|
||||||
&ProviderConfigTransformer{
|
&ProviderConfigTransformer{
|
||||||
Config: config,
|
Config: config,
|
||||||
Providers: providers,
|
Concrete: concrete,
|
||||||
Concrete: concrete,
|
|
||||||
},
|
},
|
||||||
// Add any remaining missing providers
|
// Add any remaining missing providers
|
||||||
&MissingProviderTransformer{
|
&MissingProviderTransformer{
|
||||||
Config: config,
|
Config: config,
|
||||||
Providers: providers,
|
Concrete: concrete,
|
||||||
Concrete: concrete,
|
|
||||||
},
|
},
|
||||||
// Connect the providers
|
// Connect the providers
|
||||||
&ProviderTransformer{
|
&ProviderTransformer{
|
||||||
|
@ -298,9 +296,6 @@ func (t *CloseProviderTransformer) Transform(g *Graph) error {
|
||||||
// PruneProviderTransformer can then remove these once ProviderTransformer
|
// PruneProviderTransformer can then remove these once ProviderTransformer
|
||||||
// has resolved all of the inheritence, etc.
|
// has resolved all of the inheritence, etc.
|
||||||
type MissingProviderTransformer struct {
|
type MissingProviderTransformer struct {
|
||||||
// Providers is the list of providers we support.
|
|
||||||
Providers []string
|
|
||||||
|
|
||||||
// MissingProviderTransformer needs the config to rule out _implied_ default providers
|
// MissingProviderTransformer needs the config to rule out _implied_ default providers
|
||||||
Config *configs.Config
|
Config *configs.Config
|
||||||
|
|
||||||
|
@ -478,8 +473,7 @@ func (n *graphNodeProxyProvider) Target() GraphNodeProvider {
|
||||||
// ProviderConfigTransformer adds all provider nodes from the configuration and
|
// ProviderConfigTransformer adds all provider nodes from the configuration and
|
||||||
// attaches the configs.
|
// attaches the configs.
|
||||||
type ProviderConfigTransformer struct {
|
type ProviderConfigTransformer struct {
|
||||||
Providers []string
|
Concrete ConcreteProviderNodeFunc
|
||||||
Concrete ConcreteProviderNodeFunc
|
|
||||||
|
|
||||||
// each provider node is stored here so that the proxy nodes can look up
|
// each provider node is stored here so that the proxy nodes can look up
|
||||||
// their targets by name.
|
// their targets by name.
|
||||||
|
|
|
@ -31,7 +31,7 @@ func TestProviderTransformer(t *testing.T) {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
{
|
{
|
||||||
transform := &MissingProviderTransformer{Providers: []string{"aws"}}
|
transform := &MissingProviderTransformer{}
|
||||||
if err := transform.Transform(g); err != nil {
|
if err := transform.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ func TestProviderTransformer_ImportModuleChild(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
tf := &MissingProviderTransformer{Providers: []string{"foo", "bar"}}
|
tf := &MissingProviderTransformer{}
|
||||||
if err := tf.Transform(g); err != nil {
|
if err := tf.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func TestProviderTransformer_fqns(t *testing.T) {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
{
|
{
|
||||||
transform := &MissingProviderTransformer{Providers: []string{"aws"}, Config: mod}
|
transform := &MissingProviderTransformer{Config: mod}
|
||||||
if err := transform.Transform(g); err != nil {
|
if err := transform.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ func TestCloseProviderTransformer(t *testing.T) {
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
|
|
||||||
{
|
{
|
||||||
transform := &MissingProviderTransformer{Providers: []string{"aws"}}
|
transform := &MissingProviderTransformer{}
|
||||||
if err := transform.Transform(g); err != nil {
|
if err := transform.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ func TestCloseProviderTransformer_withTargets(t *testing.T) {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
transforms := []GraphTransformer{
|
transforms := []GraphTransformer{
|
||||||
&MissingProviderTransformer{Providers: []string{"aws"}},
|
&MissingProviderTransformer{},
|
||||||
&ProviderTransformer{},
|
&ProviderTransformer{},
|
||||||
&CloseProviderTransformer{},
|
&CloseProviderTransformer{},
|
||||||
&TargetsTransformer{
|
&TargetsTransformer{
|
||||||
|
@ -194,7 +194,7 @@ func TestMissingProviderTransformer(t *testing.T) {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
{
|
{
|
||||||
transform := &MissingProviderTransformer{Providers: []string{"aws", "foo", "bar"}}
|
transform := &MissingProviderTransformer{}
|
||||||
if err := transform.Transform(g); err != nil {
|
if err := transform.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ func TestMissingProviderTransformer_grandchildMissing(t *testing.T) {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
{
|
{
|
||||||
transform := TransformProviders([]string{"aws", "foo", "bar"}, concrete, mod)
|
transform := transformProviders(concrete, mod)
|
||||||
if err := transform.Transform(g); err != nil {
|
if err := transform.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ func TestPruneProviderTransformer(t *testing.T) {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
{
|
{
|
||||||
transform := &MissingProviderTransformer{Providers: []string{"foo"}}
|
transform := &MissingProviderTransformer{}
|
||||||
if err := transform.Transform(g); err != nil {
|
if err := transform.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ func TestProviderConfigTransformer_parentProviders(t *testing.T) {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
{
|
{
|
||||||
tf := TransformProviders([]string{"aws"}, concrete, mod)
|
tf := transformProviders(concrete, mod)
|
||||||
if err := tf.Transform(g); err != nil {
|
if err := tf.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ func TestProviderConfigTransformer_grandparentProviders(t *testing.T) {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
{
|
{
|
||||||
tf := TransformProviders([]string{"aws"}, concrete, mod)
|
tf := transformProviders(concrete, mod)
|
||||||
if err := tf.Transform(g); err != nil {
|
if err := tf.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -347,7 +347,7 @@ resource "test_object" "a" {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
{
|
{
|
||||||
tf := TransformProviders([]string{"registry.terraform.io/hashicorp/test"}, concrete, mod)
|
tf := transformProviders(concrete, mod)
|
||||||
if err := tf.Transform(g); err != nil {
|
if err := tf.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -425,7 +425,7 @@ resource "test_object" "a" {
|
||||||
|
|
||||||
g := testProviderTransformerGraph(t, mod)
|
g := testProviderTransformerGraph(t, mod)
|
||||||
{
|
{
|
||||||
tf := TransformProviders([]string{"registry.terraform.io/hashicorp/test"}, concrete, mod)
|
tf := transformProviders(concrete, mod)
|
||||||
if err := tf.Transform(g); err != nil {
|
if err := tf.Transform(g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,7 @@ func TestRootTransformer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
transform := &MissingProviderTransformer{
|
transform := &MissingProviderTransformer{}
|
||||||
Providers: []string{"aws", "do"},
|
|
||||||
}
|
|
||||||
if err := transform.Transform(&g); err != nil {
|
if err := transform.Transform(&g); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue