helper/schema: test cases around unknown variable values

This commit is contained in:
Mitchell Hashimoto 2014-08-30 17:03:01 -07:00
parent 08dbf4daf0
commit 3a6940d715
2 changed files with 75 additions and 6 deletions

View File

@ -23,7 +23,7 @@ type Provider struct {
// //
// The keys of this map are the configuration keys, and the value is // The keys of this map are the configuration keys, and the value is
// the schema describing the value of the configuration. // 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 // ResourcesMap is the list of available resources that this provider
// can manage, along with their Resource structure defining their // can manage, along with their Resource structure defining their

View File

@ -10,11 +10,12 @@ import (
func TestSchemaMap_Diff(t *testing.T) { func TestSchemaMap_Diff(t *testing.T) {
cases := []struct { cases := []struct {
Schema map[string]*Schema Schema map[string]*Schema
State *terraform.ResourceState State *terraform.ResourceState
Config map[string]interface{} Config map[string]interface{}
Diff *terraform.ResourceDiff ConfigVariables map[string]string
Err bool Diff *terraform.ResourceDiff
Err bool
}{ }{
/* /*
* String decode * String decode
@ -129,6 +130,68 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false, 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 * Int decode
*/ */
@ -870,6 +933,12 @@ func TestSchemaMap_Diff(t *testing.T) {
t.Fatalf("err: %s", err) 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( d, err := schemaMap(tc.Schema).Diff(
tc.State, terraform.NewResourceConfig(c)) tc.State, terraform.NewResourceConfig(c))
if (err != nil) != tc.Err { if (err != nil) != tc.Err {