From de004d718314061617a96eb1427864281a579c0e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 20 Apr 2015 14:54:25 -0700 Subject: [PATCH] terraform: context test for when provider is missing from state --- terraform/context_test.go | 37 +++++++++++++++++++ .../apply-provider-alias-missing/main.tf | 8 ++++ 2 files changed, 45 insertions(+) create mode 100644 terraform/test-fixtures/apply-provider-alias-missing/main.tf diff --git a/terraform/context_test.go b/terraform/context_test.go index eba7e93d2..6c9a8e34c 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -610,6 +610,43 @@ func TestContext2Plan_preventDestroy_destroyPlan(t *testing.T) { } } +func TestContext2Plan_providerAliasMissing(t *testing.T) { + m := testModule(t, "apply-provider-alias-missing") + p := testProvider("aws") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.foo": &ResourceState{ + Type: "aws_instance", + Provider: "aws.foo", + Primary: &InstanceState{ + ID: "bar", + Attributes: map[string]string{ + "require_new": "abc", + }, + }, + }, + }, + }, + }, + } + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + State: state, + }) + + if _, err := ctx.Plan(); err == nil { + t.Fatal("should err") + } +} + func TestContext2Plan_computed(t *testing.T) { m := testModule(t, "plan-computed") p := testProvider("aws") diff --git a/terraform/test-fixtures/apply-provider-alias-missing/main.tf b/terraform/test-fixtures/apply-provider-alias-missing/main.tf new file mode 100644 index 000000000..ea50084fd --- /dev/null +++ b/terraform/test-fixtures/apply-provider-alias-missing/main.tf @@ -0,0 +1,8 @@ +provider "aws" { + alias = "bar" +} + +resource "aws_instance" "bar" { + foo = "bar" + provider = "aws.bar" +}