Skip to content

Commit

Permalink
Merge pull request #3831 from hashicorp/b-2598-output-add-test
Browse files Browse the repository at this point in the history
Add test attempting to reproduce #2598
  • Loading branch information
jen20 committed Nov 9, 2015
2 parents 003cbc0 + 2a03341 commit 4eea011
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
49 changes: 49 additions & 0 deletions terraform/context_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2851,6 +2851,55 @@ func TestContext2Apply_outputInvalid(t *testing.T) {
}
}

func TestContext2Apply_outputAdd(t *testing.T) {
m1 := testModule(t, "apply-output-add-before")
p1 := testProvider("aws")
p1.ApplyFn = testApplyFn
p1.DiffFn = testDiffFn
ctx1 := testContext2(t, &ContextOpts{
Module: m1,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p1),
},
})

if _, err := ctx1.Plan(); err != nil {
t.Fatalf("err: %s", err)
}

state1, err := ctx1.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}

m2 := testModule(t, "apply-output-add-after")
p2 := testProvider("aws")
p2.ApplyFn = testApplyFn
p2.DiffFn = testDiffFn
ctx2 := testContext2(t, &ContextOpts{
Module: m2,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p2),
},
State: state1,
})

if _, err := ctx2.Plan(); err != nil {
t.Fatalf("err: %s", err)
}

state2, err := ctx2.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}

actual := strings.TrimSpace(state2.String())
expected := strings.TrimSpace(testTerraformApplyOutputAddStr)
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
}

func TestContext2Apply_outputList(t *testing.T) {
m := testModule(t, "apply-output-list")
p := testProvider("aws")
Expand Down
16 changes: 16 additions & 0 deletions terraform/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,22 @@ Outputs:
foo_num = 2
`

const testTerraformApplyOutputAddStr = `
aws_instance.test.0:
ID = foo
foo = foo0
type = aws_instance
aws_instance.test.1:
ID = foo
foo = foo1
type = aws_instance
Outputs:
firstOutput = foo0
secondOutput = foo1
`

const testTerraformApplyOutputListStr = `
aws_instance.bar.0:
ID = foo
Expand Down
6 changes: 6 additions & 0 deletions terraform/test-fixtures/apply-output-add-after/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
provider "aws" {}

resource "aws_instance" "test" {
foo = "${format("foo%d", count.index)}"
count = 2
}
10 changes: 10 additions & 0 deletions terraform/test-fixtures/apply-output-add-after/outputs.tf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"output": {
"firstOutput": {
"value": "${aws_instance.test.0.foo}"
},
"secondOutput": {
"value": "${aws_instance.test.1.foo}"
}
}
}
6 changes: 6 additions & 0 deletions terraform/test-fixtures/apply-output-add-before/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
provider "aws" {}

resource "aws_instance" "test" {
foo = "${format("foo%d", count.index)}"
count = 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"output": {
"firstOutput": {
"value": "${aws_instance.test.0.foo}"
}
}
}

0 comments on commit 4eea011

Please sign in to comment.