error out when a referenced provider is missing
This commit is contained in:
parent
b9b418bcb0
commit
105b66e74d
|
@ -0,0 +1,11 @@
|
||||||
|
provider "aws" {
|
||||||
|
}
|
||||||
|
|
||||||
|
module "mod" {
|
||||||
|
source = "./mod"
|
||||||
|
|
||||||
|
# aws.foo doesn't exist, and should report an error
|
||||||
|
providers = {
|
||||||
|
"aws" = "aws.foo"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
resource "aws_resource" "foo" {
|
||||||
|
}
|
|
@ -428,7 +428,7 @@ func (t *ProviderConfigTransformer) Transform(g *Graph) error {
|
||||||
|
|
||||||
// Start the transformation process
|
// Start the transformation process
|
||||||
if err := t.transform(g, t.Module); err != nil {
|
if err := t.transform(g, t.Module); err != nil {
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally attach the configs to the new nodes
|
// finally attach the configs to the new nodes
|
||||||
|
@ -524,6 +524,7 @@ func (t *ProviderConfigTransformer) addProxyProviders(g *Graph, m *module.Tree)
|
||||||
for name, parentName := range parentCfg.Providers {
|
for name, parentName := range parentCfg.Providers {
|
||||||
fullName := ResolveProviderName(name, path)
|
fullName := ResolveProviderName(name, path)
|
||||||
fullParentName := ResolveProviderName(parentName, parentPath)
|
fullParentName := ResolveProviderName(parentName, parentPath)
|
||||||
|
|
||||||
parentProvider := t.providers[fullParentName]
|
parentProvider := t.providers[fullParentName]
|
||||||
|
|
||||||
if parentProvider == nil {
|
if parentProvider == nil {
|
||||||
|
|
|
@ -545,6 +545,35 @@ provider.aws.foo`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// error out when a non-existent provider is named in a module providers map
|
||||||
|
func TestProviderConfigTransformer_invalidProvider(t *testing.T) {
|
||||||
|
mod := testModule(t, "transform-provider-invalid")
|
||||||
|
concrete := func(a *NodeAbstractProvider) dag.Vertex { return a }
|
||||||
|
|
||||||
|
g := Graph{Path: RootModulePath}
|
||||||
|
{
|
||||||
|
tf := &ConfigTransformer{Module: mod}
|
||||||
|
if err := tf.Transform(&g); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
tf := &AttachResourceConfigTransformer{Module: mod}
|
||||||
|
if err := tf.Transform(&g); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tf := TransformProviders([]string{"aws"}, concrete, mod)
|
||||||
|
err := tf.Transform(&g)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected missing provider error")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "provider.aws.foo") {
|
||||||
|
t.Fatalf("error should reference missing provider, got: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const testTransformProviderBasicStr = `
|
const testTransformProviderBasicStr = `
|
||||||
aws_instance.web
|
aws_instance.web
|
||||||
provider.aws
|
provider.aws
|
||||||
|
|
Loading…
Reference in New Issue