add implied providers during import
The CLI adds the provider references during import, but tests may not have them specified.
This commit is contained in:
parent
a65624e0c1
commit
7f9d76cbf5
|
@ -37,8 +37,7 @@ func TestContextImport_basic(t *testing.T) {
|
||||||
Addr: addrs.RootModuleInstance.ResourceInstance(
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
||||||
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
||||||
),
|
),
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -77,8 +76,7 @@ func TestContextImport_countIndex(t *testing.T) {
|
||||||
Addr: addrs.RootModuleInstance.ResourceInstance(
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
||||||
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.IntKey(0),
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.IntKey(0),
|
||||||
),
|
),
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -135,8 +133,7 @@ func TestContextImport_collision(t *testing.T) {
|
||||||
Addr: addrs.RootModuleInstance.ResourceInstance(
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
||||||
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
||||||
),
|
),
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -179,8 +176,7 @@ func TestContextImport_missingType(t *testing.T) {
|
||||||
Addr: addrs.RootModuleInstance.ResourceInstance(
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
||||||
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
||||||
),
|
),
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -233,8 +229,7 @@ func TestContextImport_moduleProvider(t *testing.T) {
|
||||||
Addr: addrs.RootModuleInstance.ResourceInstance(
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
||||||
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
||||||
),
|
),
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -291,8 +286,7 @@ func TestContextImport_providerModule(t *testing.T) {
|
||||||
Addr: addrs.RootModuleInstance.Child("child", addrs.NoKey).ResourceInstance(
|
Addr: addrs.RootModuleInstance.Child("child", addrs.NoKey).ResourceInstance(
|
||||||
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
||||||
),
|
),
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -349,8 +343,7 @@ func TestContextImport_providerVarConfig(t *testing.T) {
|
||||||
Addr: addrs.RootModuleInstance.ResourceInstance(
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
||||||
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
||||||
),
|
),
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
provider "aws" {
|
||||||
|
foo = data.template_data_source.d.foo
|
||||||
|
}
|
||||||
|
|
||||||
|
data "template_data_source" "d" {
|
||||||
|
foo = "bar"
|
||||||
|
}
|
|
@ -16,10 +16,18 @@ type ImportStateTransformer struct {
|
||||||
|
|
||||||
func (t *ImportStateTransformer) Transform(g *Graph) error {
|
func (t *ImportStateTransformer) Transform(g *Graph) error {
|
||||||
for _, target := range t.Targets {
|
for _, target := range t.Targets {
|
||||||
|
// The ProviderAddr may not be supplied for non-aliased providers.
|
||||||
|
// This will be populated if the targets come from the cli, but tests
|
||||||
|
// may not specify implied provider addresses.
|
||||||
|
providerAddr := target.ProviderAddr
|
||||||
|
if providerAddr.ProviderConfig.Type == "" {
|
||||||
|
providerAddr = target.Addr.Resource.Resource.DefaultProviderConfig().Absolute(target.Addr.Module)
|
||||||
|
}
|
||||||
|
|
||||||
node := &graphNodeImportState{
|
node := &graphNodeImportState{
|
||||||
Addr: target.Addr,
|
Addr: target.Addr,
|
||||||
ID: target.ID,
|
ID: target.ID,
|
||||||
ProviderAddr: target.ProviderAddr,
|
ProviderAddr: providerAddr,
|
||||||
}
|
}
|
||||||
g.Add(node)
|
g.Add(node)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue