diff --git a/terraform/resource.go b/terraform/resource.go index a9db7e6a4..202116d63 100644 --- a/terraform/resource.go +++ b/terraform/resource.go @@ -15,7 +15,8 @@ type Resource struct { State *ResourceState } -// TODO: test +// Vars returns the mapping of variables that should be replaced in +// configuration based on the attributes of this resource. func (r *Resource) Vars() map[string]string { if r.State == nil { return nil diff --git a/terraform/resource_test.go b/terraform/resource_test.go new file mode 100644 index 000000000..9837cee29 --- /dev/null +++ b/terraform/resource_test.go @@ -0,0 +1,31 @@ +package terraform + +import ( + "reflect" + "testing" +) + +func TestResource_Vars(t *testing.T) { + r := new(Resource) + + if len(r.Vars()) > 0 { + t.Fatalf("bad: %#v", r.Vars()) + } + + r = &Resource{ + Id: "key", + State: &ResourceState{ + Attributes: map[string]string{ + "foo": "bar", + }, + }, + } + + expected := map[string]string{ + "key.foo": "bar", + } + actual := r.Vars() + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("bad: %#v", actual) + } +}