terraform: test apply with modules

This commit is contained in:
Mitchell Hashimoto 2014-09-23 17:13:50 -07:00
parent e8dfcdbe7b
commit 86a4a6c7c8
4 changed files with 59 additions and 0 deletions

View File

@ -524,6 +524,34 @@ func TestContextApply_compute(t *testing.T) {
}
}
func TestContextApply_module(t *testing.T) {
m := testModule(t, "apply-module")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
if _, err := ctx.Plan(nil); err != nil {
t.Fatalf("err: %s", err)
}
state, err := ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testTerraformApplyModuleStr)
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
}
func TestContextApply_nilDiff(t *testing.T) {
m := testModule(t, "apply-good")
p := testProvider("aws")

View File

@ -152,6 +152,23 @@ aws_instance.foo:
ID = foo
`
const testTerraformApplyModuleStr = `
aws_instance.bar:
ID = foo
foo = bar
type = aws_instance
aws_instance.foo:
ID = foo
num = 2
type = aws_instance
module.child:
aws_instance.baz:
ID = foo
foo = bar
type = aws_instance
`
const testTerraformApplyProvisionerStr = `
aws_instance.bar:
ID = foo

View File

@ -0,0 +1,3 @@
resource "aws_instance" "baz" {
foo = "bar"
}

View File

@ -0,0 +1,11 @@
module "child" {
source = "./child"
}
resource "aws_instance" "foo" {
num = "2"
}
resource "aws_instance" "bar" {
foo = "bar"
}