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 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

View File

@ -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 {