test passing in implicitly used provider

This commit is contained in:
James Bardin 2017-11-10 09:39:05 -05:00
parent 8bf270daa9
commit b9b418bcb0
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,10 @@
provider "aws" {
alias = "foo"
}
module "mod" {
source = "./mod"
providers = {
"aws" = "aws.foo"
}
}

View File

@ -0,0 +1,2 @@
resource "aws_instance" "bar" {
}

View File

@ -511,6 +511,40 @@ func TestProviderConfigTransformer_grandparentProviders(t *testing.T) {
}
}
// pass a specific provider into a module using it implicitly
func TestProviderConfigTransformer_implicitModule(t *testing.T) {
mod := testModule(t, "transform-provider-implicit-module")
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)
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(`module.mod.aws_instance.bar
provider.aws.foo
provider.aws.foo`)
if actual != expected {
t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual)
}
}
const testTransformProviderBasicStr = `
aws_instance.web
provider.aws