2016-11-05 19:58:38 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2018-05-04 21:24:06 -05:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
2018-05-10 11:56:32 -05:00
|
|
|
"github.com/hashicorp/terraform/config/configschema"
|
2016-11-05 19:58:38 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPlanGraphBuilder_impl(t *testing.T) {
|
|
|
|
var _ GraphBuilder = new(PlanGraphBuilder)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPlanGraphBuilder(t *testing.T) {
|
|
|
|
b := &PlanGraphBuilder{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: testModule(t, "graph-builder-plan-basic"),
|
|
|
|
Components: &basicComponentFactory{
|
|
|
|
providers: map[string]ResourceProviderFactory{
|
2018-05-10 11:56:32 -05:00
|
|
|
"aws": ResourceProviderFactoryFixed(&MockResourceProvider{
|
|
|
|
GetSchemaReturn: &ProviderSchema{
|
|
|
|
Provider: simpleTestSchema(),
|
|
|
|
ResourceTypes: map[string]*configschema.Block{
|
|
|
|
"aws_security_group": simpleTestSchema(),
|
|
|
|
"aws_instance": simpleTestSchema(),
|
|
|
|
"aws_load_balancer": simpleTestSchema(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
"openstack": ResourceProviderFactoryFixed(&MockResourceProvider{
|
|
|
|
GetSchemaReturn: &ProviderSchema{
|
|
|
|
Provider: simpleTestSchema(),
|
|
|
|
ResourceTypes: map[string]*configschema.Block{
|
|
|
|
"openstack_floating_ip": simpleTestSchema(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2018-05-04 21:24:06 -05:00
|
|
|
},
|
|
|
|
},
|
2016-11-05 19:58:38 -05:00
|
|
|
DisableReduce: true,
|
|
|
|
}
|
|
|
|
|
2018-05-04 21:24:06 -05:00
|
|
|
g, err := b.Build(addrs.RootModuleInstance)
|
2016-11-05 19:58:38 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-05-04 21:24:06 -05:00
|
|
|
if g.Path.String() != addrs.RootModuleInstance.String() {
|
|
|
|
t.Fatalf("wrong module path %q", g.Path)
|
2016-11-05 19:58:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testPlanGraphBuilderStr)
|
|
|
|
if actual != expected {
|
2017-04-20 00:23:52 -05:00
|
|
|
t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual)
|
2016-11-05 19:58:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 11:21:29 -06:00
|
|
|
func TestPlanGraphBuilder_targetModule(t *testing.T) {
|
|
|
|
b := &PlanGraphBuilder{
|
2018-05-10 11:56:32 -05:00
|
|
|
Config: testModule(t, "graph-builder-plan-target-module-provider"),
|
|
|
|
Components: simpleMockComponentFactory(),
|
2018-05-04 21:24:06 -05:00
|
|
|
Targets: []addrs.Targetable{
|
|
|
|
addrs.RootModuleInstance.Child("child2", addrs.NoKey),
|
|
|
|
},
|
2017-02-17 11:21:29 -06:00
|
|
|
}
|
|
|
|
|
2018-05-04 21:24:06 -05:00
|
|
|
g, err := b.Build(addrs.RootModuleInstance)
|
2017-02-17 11:21:29 -06:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Graph: %s", g.String())
|
|
|
|
|
2018-05-10 11:56:32 -05:00
|
|
|
testGraphNotContains(t, g, "module.child1.provider.test")
|
|
|
|
testGraphNotContains(t, g, "module.child1.test_object.foo")
|
2017-02-17 11:21:29 -06:00
|
|
|
}
|
|
|
|
|
2016-11-05 19:58:38 -05:00
|
|
|
const testPlanGraphBuilderStr = `
|
|
|
|
aws_instance.web
|
|
|
|
aws_security_group.firewall
|
|
|
|
provider.aws
|
|
|
|
var.foo
|
|
|
|
aws_load_balancer.weblb
|
|
|
|
aws_instance.web
|
|
|
|
provider.aws
|
|
|
|
aws_security_group.firewall
|
|
|
|
provider.aws
|
2017-07-01 11:48:37 -05:00
|
|
|
local.instance_id
|
|
|
|
aws_instance.web
|
2017-04-20 00:23:52 -05:00
|
|
|
meta.count-boundary (count boundary fixup)
|
|
|
|
aws_instance.web
|
|
|
|
aws_load_balancer.weblb
|
|
|
|
aws_security_group.firewall
|
2017-07-01 11:48:37 -05:00
|
|
|
local.instance_id
|
2017-04-20 00:23:52 -05:00
|
|
|
openstack_floating_ip.random
|
2017-07-01 11:48:37 -05:00
|
|
|
output.instance_id
|
2017-04-20 00:23:52 -05:00
|
|
|
provider.aws
|
|
|
|
provider.openstack
|
|
|
|
var.foo
|
2016-11-05 19:58:38 -05:00
|
|
|
openstack_floating_ip.random
|
|
|
|
provider.openstack
|
2017-07-01 11:48:37 -05:00
|
|
|
output.instance_id
|
|
|
|
local.instance_id
|
2016-11-05 19:58:38 -05:00
|
|
|
provider.aws
|
|
|
|
openstack_floating_ip.random
|
2017-04-12 16:25:15 -05:00
|
|
|
provider.aws (close)
|
|
|
|
aws_instance.web
|
|
|
|
aws_load_balancer.weblb
|
|
|
|
aws_security_group.firewall
|
|
|
|
provider.aws
|
2016-11-05 19:58:38 -05:00
|
|
|
provider.openstack
|
2017-04-12 16:25:15 -05:00
|
|
|
provider.openstack (close)
|
|
|
|
openstack_floating_ip.random
|
|
|
|
provider.openstack
|
|
|
|
root
|
2017-04-20 00:23:52 -05:00
|
|
|
meta.count-boundary (count boundary fixup)
|
2017-04-12 16:25:15 -05:00
|
|
|
provider.aws (close)
|
|
|
|
provider.openstack (close)
|
2016-11-05 19:58:38 -05:00
|
|
|
var.foo
|
|
|
|
`
|