Skip to content

Commit

Permalink
terraform: depends_on with count creates proper graph [GH-244]
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Aug 30, 2014
1 parent 7cfad67 commit 28a2e7b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ IMPROVEMENTS:
BUG FIXES:

* core: Configuration parses when identifier and '=' have no space. [GH-243]
* core: `depends_on` with `count` generates the proper graph. [GH-244]

## 0.2.0 (August 28, 2014)

Expand Down
2 changes: 1 addition & 1 deletion terraform/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func graphAddExplicitDeps(g *depgraph.Graph) {
continue
}

rs[rn.Config.Id()] = n
rs[rn.Resource.Id] = n
if len(rn.Config.DependsOn) > 0 {
depends = true
}
Expand Down
30 changes: 30 additions & 0 deletions terraform/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ func TestGraph_dependsOn(t *testing.T) {
}
}

func TestGraph_dependsOnCount(t *testing.T) {
config := testConfig(t, "graph-depends-on-count")

g, err := Graph(&GraphOpts{Config: config})
if err != nil {
t.Fatalf("err: %s", err)
}

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

func TestGraph_state(t *testing.T) {
config := testConfig(t, "graph-basic")
state := &State{
Expand Down Expand Up @@ -372,6 +387,21 @@ root
root -> aws_instance.web
`

const testTerraformGraphDependsCountStr = `
root: root
aws_instance.db
aws_instance.db -> aws_instance.db.0
aws_instance.db -> aws_instance.db.1
aws_instance.db.0
aws_instance.db.0 -> aws_instance.web
aws_instance.db.1
aws_instance.db.1 -> aws_instance.web
aws_instance.web
root
root -> aws_instance.db
root -> aws_instance.web
`

const testTerraformGraphDiffStr = `
root: root
aws_instance.foo
Expand Down
6 changes: 6 additions & 0 deletions terraform/test-fixtures/graph-depends-on-count/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "aws_instance" "web" {}

resource "aws_instance" "db" {
depends_on = ["aws_instance.web"]
count = 2
}

0 comments on commit 28a2e7b

Please sign in to comment.