From 867f6b3691c77f2ddf314aba2d45b78c2017bfec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Jun 2014 12:53:59 -0700 Subject: [PATCH] config: test to make sure that cycles are properly detected --- config/config_test.go | 12 ++++++++++++ config/test-fixtures/resource_graph_cycle.tf | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 config/test-fixtures/resource_graph_cycle.tf diff --git a/config/config_test.go b/config/config_test.go index 8e93cd43d..1c7463b4d 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -29,6 +29,18 @@ func TestConfigResourceGraph(t *testing.T) { } } +func TestConfigResourceGraph_cycle(t *testing.T) { + c, err := Load(filepath.Join(fixtureDir, "resource_graph_cycle.tf")) + if err != nil { + t.Fatalf("err: %s", err) + } + + graph := c.ResourceGraph() + if err := graph.Validate(); err == nil { + t.Fatal("graph should be invalid") + } +} + func TestNewResourceVariable(t *testing.T) { v, err := NewResourceVariable("foo.bar.baz") if err != nil { diff --git a/config/test-fixtures/resource_graph_cycle.tf b/config/test-fixtures/resource_graph_cycle.tf new file mode 100644 index 000000000..135a35af8 --- /dev/null +++ b/config/test-fixtures/resource_graph_cycle.tf @@ -0,0 +1,18 @@ +variable "foo" { + default = "bar"; + description = "bar"; +} + +provider "aws" { + foo = "${aws_security_group.firewall.value}" +} + +resource "aws_security_group" "firewall" {} + +resource "aws_instance" "web" { + ami = "${var.foo}" + security_groups = [ + "foo", + "${aws_security_group.firewall.foo}" + ] +}