From 3a6940d715433f76000fd34a54ee43d887d2039f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 30 Aug 2014 17:03:01 -0700 Subject: [PATCH] helper/schema: test cases around unknown variable values --- helper/schema/provider.go | 2 +- helper/schema/schema_test.go | 79 +++++++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/helper/schema/provider.go b/helper/schema/provider.go index f34bf0195..e59f96494 100644 --- a/helper/schema/provider.go +++ b/helper/schema/provider.go @@ -23,7 +23,7 @@ type Provider struct { // // The keys of this map are the configuration keys, and the value is // the schema describing the value of the configuration. - Schema map[string]*Schema + Schema map[string]*Schema // ResourcesMap is the list of available resources that this provider // can manage, along with their Resource structure defining their diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index cbf995704..c7fe06960 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -10,11 +10,12 @@ import ( func TestSchemaMap_Diff(t *testing.T) { cases := []struct { - Schema map[string]*Schema - State *terraform.ResourceState - Config map[string]interface{} - Diff *terraform.ResourceDiff - Err bool + Schema map[string]*Schema + State *terraform.ResourceState + Config map[string]interface{} + ConfigVariables map[string]string + Diff *terraform.ResourceDiff + Err bool }{ /* * String decode @@ -129,6 +130,68 @@ func TestSchemaMap_Diff(t *testing.T) { Err: false, }, + // Variable (just checking) + { + Schema: map[string]*Schema{ + "availability_zone": &Schema{ + Type: TypeString, + Optional: true, + }, + }, + + State: nil, + + Config: map[string]interface{}{ + "availability_zone": "${var.foo}", + }, + + ConfigVariables: map[string]string{ + "var.foo": "bar", + }, + + Diff: &terraform.ResourceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "availability_zone": &terraform.ResourceAttrDiff{ + Old: "", + New: "bar", + }, + }, + }, + + Err: false, + }, + + // Variable computed + { + Schema: map[string]*Schema{ + "availability_zone": &Schema{ + Type: TypeString, + Optional: true, + }, + }, + + State: nil, + + Config: map[string]interface{}{ + "availability_zone": "${var.foo}", + }, + + ConfigVariables: map[string]string{ + "var.foo": config.UnknownVariableValue, + }, + + Diff: &terraform.ResourceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "availability_zone": &terraform.ResourceAttrDiff{ + Old: "", + New: "${var.foo}", + }, + }, + }, + + Err: false, + }, + /* * Int decode */ @@ -870,6 +933,12 @@ func TestSchemaMap_Diff(t *testing.T) { t.Fatalf("err: %s", err) } + if len(tc.ConfigVariables) > 0 { + if err := c.Interpolate(tc.ConfigVariables); err != nil { + t.Fatalf("err: %s", err) + } + } + d, err := schemaMap(tc.Schema).Diff( tc.State, terraform.NewResourceConfig(c)) if (err != nil) != tc.Err {