diff --git a/terraform/graph_builder_plan_test.go b/terraform/graph_builder_plan_test.go index 3da9287bb..108d80a5d 100644 --- a/terraform/graph_builder_plan_test.go +++ b/terraform/graph_builder_plan_test.go @@ -1,11 +1,11 @@ package terraform import ( - "fmt" "strings" "testing" "github.com/hashicorp/terraform/addrs" + "github.com/hashicorp/terraform/config/configschema" ) func TestPlanGraphBuilder_impl(t *testing.T) { @@ -17,12 +17,24 @@ func TestPlanGraphBuilder(t *testing.T) { Config: testModule(t, "graph-builder-plan-basic"), Components: &basicComponentFactory{ providers: map[string]ResourceProviderFactory{ - "aws": func() (ResourceProvider, error) { - return nil, fmt.Errorf("not implemented") - }, - "openstack": func() (ResourceProvider, error) { - return nil, fmt.Errorf("not implemented") - }, + "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(), + }, + }, + }), }, }, DisableReduce: true, @@ -46,17 +58,8 @@ func TestPlanGraphBuilder(t *testing.T) { func TestPlanGraphBuilder_targetModule(t *testing.T) { b := &PlanGraphBuilder{ - Config: testModule(t, "graph-builder-plan-target-module-provider"), - Components: &basicComponentFactory{ - providers: map[string]ResourceProviderFactory{ - "null": func() (ResourceProvider, error) { - return nil, fmt.Errorf("not implemented") - }, - "openstack": func() (ResourceProvider, error) { - return nil, fmt.Errorf("not implemented") - }, - }, - }, + Config: testModule(t, "graph-builder-plan-target-module-provider"), + Components: simpleMockComponentFactory(), Targets: []addrs.Targetable{ addrs.RootModuleInstance.Child("child2", addrs.NoKey), }, @@ -69,8 +72,8 @@ func TestPlanGraphBuilder_targetModule(t *testing.T) { t.Logf("Graph: %s", g.String()) - testGraphNotContains(t, g, "module.child1.provider.null") - testGraphNotContains(t, g, "module.child1.null_resource.foo") + testGraphNotContains(t, g, "module.child1.provider.test") + testGraphNotContains(t, g, "module.child1.test_object.foo") } const testPlanGraphBuilderStr = ` diff --git a/terraform/test-fixtures/graph-builder-plan-basic/main.tf b/terraform/test-fixtures/graph-builder-plan-basic/main.tf index 47cf9590b..df74468a1 100644 --- a/terraform/test-fixtures/graph-builder-plan-basic/main.tf +++ b/terraform/test-fixtures/graph-builder-plan-basic/main.tf @@ -1,10 +1,10 @@ variable "foo" { - default = "bar" - description = "bar" + default = "bar" + description = "bar" } provider "aws" { - foo = "${openstack_floating_ip.random.value}" + test_string = "${openstack_floating_ip.random.test_string}" } resource "openstack_floating_ip" "random" {} @@ -12,19 +12,20 @@ resource "openstack_floating_ip" "random" {} resource "aws_security_group" "firewall" {} resource "aws_instance" "web" { - ami = "${var.foo}" - security_groups = [ - "foo", - "${aws_security_group.firewall.foo}" - ] + test_string = var.foo + + test_list = [ + "foo", + aws_security_group.firewall.test_string, + ] } resource "aws_load_balancer" "weblb" { - members = "${aws_instance.web.id_list}" + test_list = aws_instance.web.test_list } locals { - instance_id = "${aws_instance.web.id}" + instance_id = "${aws_instance.web.test_string}" } output "instance_id" { diff --git a/terraform/test-fixtures/graph-builder-plan-target-module-provider/child1/main.tf b/terraform/test-fixtures/graph-builder-plan-target-module-provider/child1/main.tf index c9aaff5f7..f95800f7a 100644 --- a/terraform/test-fixtures/graph-builder-plan-target-module-provider/child1/main.tf +++ b/terraform/test-fixtures/graph-builder-plan-target-module-provider/child1/main.tf @@ -1,7 +1,7 @@ variable "key" {} -provider "null" { - key = "${var.key}" +provider "test" { + test_string = "${var.key}" } -resource "null_resource" "foo" {} +resource "test_object" "foo" {} diff --git a/terraform/test-fixtures/graph-builder-plan-target-module-provider/child2/main.tf b/terraform/test-fixtures/graph-builder-plan-target-module-provider/child2/main.tf index c9aaff5f7..f95800f7a 100644 --- a/terraform/test-fixtures/graph-builder-plan-target-module-provider/child2/main.tf +++ b/terraform/test-fixtures/graph-builder-plan-target-module-provider/child2/main.tf @@ -1,7 +1,7 @@ variable "key" {} -provider "null" { - key = "${var.key}" +provider "test" { + test_string = "${var.key}" } -resource "null_resource" "foo" {} +resource "test_object" "foo" {} diff --git a/terraform/test-fixtures/graph-builder-plan-target-module-provider/main.tf b/terraform/test-fixtures/graph-builder-plan-target-module-provider/main.tf index b9822a4f8..d5a01db9a 100644 --- a/terraform/test-fixtures/graph-builder-plan-target-module-provider/main.tf +++ b/terraform/test-fixtures/graph-builder-plan-target-module-provider/main.tf @@ -1,7 +1,9 @@ module "child1" { source = "./child1" + key = "!" } module "child2" { source = "./child2" + key = "!" }