2014-08-15 04:55:47 +02:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
2015-01-27 21:23:49 +01:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2015-01-16 19:54:43 +01:00
|
|
|
"os"
|
2014-08-15 04:55:47 +02:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
2015-01-15 00:28:36 +01:00
|
|
|
"github.com/hashicorp/terraform/config/lang/ast"
|
2015-01-27 21:23:49 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/hashcode"
|
2014-08-15 04:55:47 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2015-01-16 19:54:43 +01:00
|
|
|
func TestEnvDefaultFunc(t *testing.T) {
|
|
|
|
key := "TF_TEST_ENV_DEFAULT_FUNC"
|
|
|
|
defer os.Unsetenv(key)
|
|
|
|
|
|
|
|
f := EnvDefaultFunc(key, "42")
|
|
|
|
if err := os.Setenv(key, "foo"); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual, err := f()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if actual != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.Unsetenv(key); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual, err = f()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if actual != "42" {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:30:27 +01:00
|
|
|
func TestMultiEnvDefaultFunc(t *testing.T) {
|
|
|
|
keys := []string{
|
|
|
|
"TF_TEST_MULTI_ENV_DEFAULT_FUNC1",
|
|
|
|
"TF_TEST_MULTI_ENV_DEFAULT_FUNC2",
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
for _, k := range keys {
|
|
|
|
os.Unsetenv(k)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2015-01-22 21:34:48 +01:00
|
|
|
// Test that the first key is returned first
|
2015-01-22 21:30:27 +01:00
|
|
|
f := MultiEnvDefaultFunc(keys, "42")
|
2015-01-22 21:34:48 +01:00
|
|
|
if err := os.Setenv(keys[0], "foo"); err != nil {
|
2015-01-22 21:30:27 +01:00
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual, err := f()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if actual != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:34:48 +01:00
|
|
|
if err := os.Unsetenv(keys[0]); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that the second key is returned if the first one is empty
|
|
|
|
f = MultiEnvDefaultFunc(keys, "42")
|
|
|
|
if err := os.Setenv(keys[1], "foo"); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual, err = f()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if actual != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:30:27 +01:00
|
|
|
if err := os.Unsetenv(keys[1]); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:34:48 +01:00
|
|
|
// Test that the default value is returned when no keys are set
|
2015-01-22 21:30:27 +01:00
|
|
|
actual, err = f()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if actual != "42" {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 03:02:19 +01:00
|
|
|
func TestValueType_Zero(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Type ValueType
|
|
|
|
Value interface{}
|
|
|
|
}{
|
|
|
|
{TypeBool, false},
|
|
|
|
{TypeInt, 0},
|
2015-01-11 00:57:06 +01:00
|
|
|
{TypeFloat, 0.0},
|
2015-01-09 03:02:19 +01:00
|
|
|
{TypeString, ""},
|
|
|
|
{TypeList, []interface{}{}},
|
|
|
|
{TypeMap, map[string]interface{}{}},
|
2015-02-18 01:58:47 +01:00
|
|
|
{TypeSet, new(Set)},
|
2015-01-09 03:02:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
|
|
|
actual := tc.Type.Zero()
|
|
|
|
if !reflect.DeepEqual(actual, tc.Value) {
|
|
|
|
t.Fatalf("%d: %#v != %#v", i, actual, tc.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 04:55:47 +02:00
|
|
|
func TestSchemaMap_Diff(t *testing.T) {
|
|
|
|
cases := []struct {
|
2014-08-31 02:03:01 +02:00
|
|
|
Schema map[string]*Schema
|
2014-09-17 02:07:13 +02:00
|
|
|
State *terraform.InstanceState
|
2014-08-31 02:03:01 +02:00
|
|
|
Config map[string]interface{}
|
|
|
|
ConfigVariables map[string]string
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff *terraform.InstanceDiff
|
2014-08-31 02:03:01 +02:00
|
|
|
Err bool
|
2014-08-15 04:55:47 +02:00
|
|
|
}{
|
2014-08-15 05:02:52 +02:00
|
|
|
/*
|
|
|
|
* String decode
|
|
|
|
*/
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #0
|
2014-08-15 04:55:47 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-15 04:55:47 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "foo",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #1
|
2014-08-15 04:55:47 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-15 04:55:47 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
NewComputed: true,
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #2
|
2014-08-22 21:18:08 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-22 21:18:08 +02:00
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #3 Computed, but set in config
|
2014-10-21 08:52:22 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "foo",
|
|
|
|
New: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #4 Default
|
2014-09-10 06:17:29 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: nil,
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-09-10 06:17:29 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #5 DefaultFunc, value
|
2014-09-10 06:33:08 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: func() (interface{}, error) {
|
|
|
|
return "foo", nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: nil,
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-09-10 06:33:08 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #6 DefaultFunc, configuration set
|
2014-09-10 06:33:08 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: func() (interface{}, error) {
|
|
|
|
return "foo", nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-09-10 06:33:08 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #7 String with StateFunc
|
2014-08-22 17:45:54 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
StateFunc: func(a interface{}) string {
|
|
|
|
return a.(string) + "!"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-22 17:45:54 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
2014-08-22 17:57:44 +02:00
|
|
|
Old: "",
|
|
|
|
New: "foo!",
|
|
|
|
NewExtra: "foo",
|
2014-08-22 17:45:54 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #8 Variable (just checking)
|
2014-08-31 02:03:01 +02:00
|
|
|
{
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-31 02:03:01 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #9 Variable computed
|
2014-08-31 02:03:01 +02:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-31 02:03:01 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "${var.foo}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-08-15 05:02:52 +02:00
|
|
|
/*
|
|
|
|
* Int decode
|
|
|
|
*/
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #10
|
2014-08-15 05:02:52 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"port": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"port": 27,
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-15 05:02:52 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"port": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "27",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bool decode
|
|
|
|
*/
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #11
|
2014-08-15 05:02:52 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"port": &Schema{
|
|
|
|
Type: TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"port": false,
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-15 05:02:52 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"port": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "0",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-08-15 08:17:53 +02:00
|
|
|
|
2014-10-20 23:08:56 +02:00
|
|
|
/*
|
|
|
|
* Bool
|
|
|
|
*/
|
2014-12-12 23:21:20 +01:00
|
|
|
|
|
|
|
// #12
|
2014-10-20 23:08:56 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"delete": &Schema{
|
|
|
|
Type: TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
Default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"delete": "false",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: nil,
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-08-15 08:17:53 +02:00
|
|
|
/*
|
|
|
|
* List decode
|
|
|
|
*/
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #13
|
2014-08-15 08:17:53 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{1, 2, 5},
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-15 08:17:53 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
2014-08-19 06:22:27 +02:00
|
|
|
Old: "0",
|
2014-08-15 08:17:53 +02:00
|
|
|
New: "3",
|
|
|
|
},
|
|
|
|
"ports.0": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "1",
|
|
|
|
},
|
|
|
|
"ports.1": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "2",
|
|
|
|
},
|
|
|
|
"ports.2": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #14
|
2014-10-10 01:31:24 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{1, "${var.foo}"},
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigVariables: map[string]string{
|
|
|
|
"var.foo": "2" + config.InterpSplitDelim + "5",
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "0",
|
|
|
|
New: "3",
|
|
|
|
},
|
|
|
|
"ports.0": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "1",
|
|
|
|
},
|
|
|
|
"ports.1": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "2",
|
|
|
|
},
|
|
|
|
"ports.2": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #15
|
2014-10-10 04:09:06 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{1, "${var.foo}"},
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigVariables: map[string]string{
|
|
|
|
"var.foo": config.UnknownVariableValue +
|
|
|
|
config.InterpSplitDelim + "5",
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
2014-10-10 23:50:35 +02:00
|
|
|
Old: "0",
|
|
|
|
New: "",
|
2014-10-10 04:09:06 +02:00
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #16
|
2014-08-15 08:17:53 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-15 08:17:53 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"ports.#": "3",
|
|
|
|
"ports.0": "1",
|
|
|
|
"ports.1": "2",
|
|
|
|
"ports.2": "5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{1, 2, 5},
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #17
|
2014-08-15 08:17:53 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-15 08:17:53 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"ports.#": "2",
|
|
|
|
"ports.0": "1",
|
|
|
|
"ports.1": "2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{1, 2, 5},
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-15 08:17:53 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "2",
|
|
|
|
New: "3",
|
|
|
|
},
|
|
|
|
"ports.2": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-08-15 08:32:20 +02:00
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #18
|
2014-08-15 08:32:20 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{1, 2, 5},
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-15 08:32:20 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
2014-08-19 06:22:27 +02:00
|
|
|
Old: "0",
|
2014-08-15 08:32:20 +02:00
|
|
|
New: "3",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
"ports.0": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "1",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
"ports.1": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "2",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
"ports.2": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "5",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-08-15 19:25:25 +02:00
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #19
|
2014-08-19 06:22:27 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-19 06:22:27 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
2014-08-21 02:51:27 +02:00
|
|
|
Old: "",
|
2014-08-19 06:22:27 +02:00
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-08-15 19:25:25 +02:00
|
|
|
/*
|
2014-08-21 03:30:28 +02:00
|
|
|
* Set
|
|
|
|
*/
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #20
|
2014-08-15 19:25:25 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
2014-08-21 00:45:34 +02:00
|
|
|
"ports": &Schema{
|
2014-08-21 02:51:27 +02:00
|
|
|
Type: TypeSet,
|
2014-08-15 19:25:25 +02:00
|
|
|
Required: true,
|
2014-08-21 00:45:34 +02:00
|
|
|
Elem: &Schema{Type: TypeInt},
|
2014-08-21 02:51:27 +02:00
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
2014-08-15 19:25:25 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
2014-08-21 00:45:34 +02:00
|
|
|
"ports": []interface{}{5, 2, 1},
|
2014-08-15 19:25:25 +02:00
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-15 19:25:25 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
2014-08-21 00:45:34 +02:00
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
2014-08-19 06:22:27 +02:00
|
|
|
Old: "0",
|
2014-08-21 00:45:34 +02:00
|
|
|
New: "3",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.1": &terraform.ResourceAttrDiff{
|
2014-08-21 00:45:34 +02:00
|
|
|
Old: "",
|
2014-08-15 19:25:25 +02:00
|
|
|
New: "1",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.2": &terraform.ResourceAttrDiff{
|
2014-08-15 19:25:25 +02:00
|
|
|
Old: "",
|
2014-08-21 00:45:34 +02:00
|
|
|
New: "2",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.5": &terraform.ResourceAttrDiff{
|
2014-08-21 00:45:34 +02:00
|
|
|
Old: "",
|
|
|
|
New: "5",
|
2014-08-15 19:25:25 +02:00
|
|
|
},
|
2014-10-10 18:13:04 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #21
|
2014-10-11 00:46:24 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Computed: true,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"ports.#": "0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: nil,
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #22
|
2014-10-11 00:58:38 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: nil,
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #23
|
2014-10-10 18:13:04 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{"${var.foo}", 1},
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigVariables: map[string]string{
|
|
|
|
"var.foo": "2" + config.InterpSplitDelim + "5",
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "0",
|
|
|
|
New: "3",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.1": &terraform.ResourceAttrDiff{
|
2014-10-10 18:13:04 +02:00
|
|
|
Old: "",
|
|
|
|
New: "1",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.2": &terraform.ResourceAttrDiff{
|
2014-10-10 18:13:04 +02:00
|
|
|
Old: "",
|
|
|
|
New: "2",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.5": &terraform.ResourceAttrDiff{
|
2014-10-10 18:13:04 +02:00
|
|
|
Old: "",
|
|
|
|
New: "5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #24
|
2014-10-10 18:13:04 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{1, "${var.foo}"},
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigVariables: map[string]string{
|
|
|
|
"var.foo": config.UnknownVariableValue +
|
|
|
|
config.InterpSplitDelim + "5",
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
2015-01-15 00:35:40 +01:00
|
|
|
Old: "",
|
2014-10-10 23:50:35 +02:00
|
|
|
New: "",
|
2014-10-10 18:13:04 +02:00
|
|
|
NewComputed: true,
|
|
|
|
},
|
2014-08-15 19:25:25 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-08-15 19:39:40 +02:00
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #25
|
2014-08-21 06:02:42 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-21 06:02:42 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"ports.#": "2",
|
|
|
|
"ports.1": "1",
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.2": "2",
|
2014-08-21 06:02:42 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{5, 2, 1},
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-21 06:02:42 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "2",
|
|
|
|
New: "3",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.1": &terraform.ResourceAttrDiff{
|
2014-10-21 19:49:27 +02:00
|
|
|
Old: "1",
|
|
|
|
New: "1",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.2": &terraform.ResourceAttrDiff{
|
2014-10-21 19:49:27 +02:00
|
|
|
Old: "2",
|
|
|
|
New: "2",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.5": &terraform.ResourceAttrDiff{
|
2014-08-21 06:02:42 +02:00
|
|
|
Old: "",
|
|
|
|
New: "5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #26
|
2014-08-21 06:02:42 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-21 06:02:42 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"ports.#": "2",
|
|
|
|
"ports.1": "1",
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.2": "2",
|
2014-08-21 06:02:42 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-21 06:02:42 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "2",
|
|
|
|
New: "0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #27
|
2014-08-28 00:03:42 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
2014-12-12 23:21:20 +01:00
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
2014-08-28 00:03:42 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-28 00:03:42 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
"ports.#": "1",
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.80": "80",
|
2014-08-28 00:03:42 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
2014-10-11 19:40:54 +02:00
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #28
|
2014-10-11 19:40:54 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ingress": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Set: func(v interface{}) int {
|
|
|
|
m := v.(map[string]interface{})
|
|
|
|
ps := m["ports"].([]interface{})
|
|
|
|
result := 0
|
|
|
|
for _, p := range ps {
|
|
|
|
result += p.(int)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
2014-12-12 23:21:20 +01:00
|
|
|
"ingress.#": "2",
|
|
|
|
"ingress.80.ports.#": "1",
|
|
|
|
"ingress.80.ports.0": "80",
|
|
|
|
"ingress.443.ports.#": "1",
|
|
|
|
"ingress.443.ports.0": "443",
|
2014-10-11 19:40:54 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
2014-12-12 23:21:20 +01:00
|
|
|
"ingress": []map[string]interface{}{
|
2014-10-11 19:40:54 +02:00
|
|
|
map[string]interface{}{
|
|
|
|
"ports": []interface{}{443},
|
|
|
|
},
|
|
|
|
map[string]interface{}{
|
|
|
|
"ports": []interface{}{80},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-08-28 00:03:42 +02:00
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-08-21 00:45:34 +02:00
|
|
|
/*
|
|
|
|
* List of structure decode
|
|
|
|
*/
|
2014-08-15 19:39:40 +02:00
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #29
|
2014-08-15 19:39:40 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ingress": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"from": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
2014-08-21 00:45:34 +02:00
|
|
|
"ingress": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"from": 8080,
|
2014-08-15 19:39:40 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-21 00:45:34 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ingress.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "0",
|
|
|
|
New: "1",
|
|
|
|
},
|
|
|
|
"ingress.0.from": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "8080",
|
|
|
|
},
|
2014-08-15 19:39:40 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-08-21 00:45:34 +02:00
|
|
|
Err: false,
|
2014-08-15 19:39:40 +02:00
|
|
|
},
|
2014-08-16 18:49:22 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ComputedWhen
|
|
|
|
*/
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #30
|
2014-08-16 18:49:22 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Computed: true,
|
|
|
|
ComputedWhen: []string{"port"},
|
|
|
|
},
|
|
|
|
|
|
|
|
"port": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-16 18:49:22 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
"port": "80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"port": 80,
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #31
|
2014-08-16 18:49:22 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Computed: true,
|
|
|
|
ComputedWhen: []string{"port"},
|
|
|
|
},
|
|
|
|
|
|
|
|
"port": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-16 18:49:22 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"port": "80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"port": 80,
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-16 18:49:22 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-08-16 22:32:21 +02:00
|
|
|
|
|
|
|
/* TODO
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Computed: true,
|
|
|
|
ComputedWhen: []string{"port"},
|
|
|
|
},
|
|
|
|
|
|
|
|
"port": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-16 22:32:21 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
"port": "80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"port": 8080,
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.ResourceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "foo",
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
"port": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "80",
|
|
|
|
New: "8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
*/
|
2014-08-19 00:07:09 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Maps
|
|
|
|
*/
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #32
|
2014-10-09 02:35:14 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"config_vars": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"config_vars": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
2014-12-16 02:35:16 +01:00
|
|
|
"config_vars.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "0",
|
|
|
|
New: "1",
|
|
|
|
},
|
|
|
|
|
2014-10-09 02:35:14 +02:00
|
|
|
"config_vars.bar": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #33
|
2014-10-09 03:25:31 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"config_vars": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"config_vars.foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"config_vars": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"config_vars.foo": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "bar",
|
|
|
|
NewRemoved: true,
|
|
|
|
},
|
|
|
|
"config_vars.bar": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #34
|
2014-10-21 08:52:22 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"vars": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"vars.foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"vars": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"vars.foo": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "bar",
|
|
|
|
New: "",
|
|
|
|
NewRemoved: true,
|
|
|
|
},
|
|
|
|
"vars.bar": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #35
|
2014-10-20 23:23:06 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"vars": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"vars.foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: nil,
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #36
|
2014-08-19 00:07:09 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"config_vars": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Elem: &Schema{Type: TypeMap},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-19 00:07:09 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"config_vars.#": "1",
|
|
|
|
"config_vars.0.foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"config_vars": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-19 00:07:09 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"config_vars.0.foo": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "bar",
|
|
|
|
NewRemoved: true,
|
|
|
|
},
|
|
|
|
"config_vars.0.bar": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-08-19 01:54:30 +02:00
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #37
|
2014-08-19 01:54:30 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"config_vars": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Elem: &Schema{Type: TypeMap},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-19 01:54:30 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"config_vars.#": "1",
|
|
|
|
"config_vars.0.foo": "bar",
|
|
|
|
"config_vars.0.bar": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-19 01:54:30 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"config_vars.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "1",
|
|
|
|
New: "0",
|
|
|
|
},
|
2014-12-16 02:35:16 +01:00
|
|
|
"config_vars.0.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "2",
|
|
|
|
New: "0",
|
|
|
|
},
|
2014-08-19 01:54:30 +02:00
|
|
|
"config_vars.0.foo": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "bar",
|
|
|
|
NewRemoved: true,
|
|
|
|
},
|
|
|
|
"config_vars.0.bar": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "baz",
|
|
|
|
NewRemoved: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-08-28 00:26:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ForceNews
|
|
|
|
*/
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #38
|
2014-08-28 00:26:15 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"address": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-28 00:26:15 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
"address": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-28 00:26:15 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "bar",
|
|
|
|
New: "foo",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"address": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "foo",
|
|
|
|
New: "",
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #39 Set
|
2014-08-28 00:26:15 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
2014-12-12 23:21:20 +01:00
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
2014-08-28 00:26:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-17 02:07:13 +02:00
|
|
|
State: &terraform.InstanceState{
|
2014-08-28 00:26:15 +02:00
|
|
|
Attributes: map[string]string{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
"ports.#": "1",
|
2014-12-12 23:21:20 +01:00
|
|
|
"ports.80": "80",
|
2014-08-28 00:26:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
},
|
|
|
|
|
2014-09-18 01:33:24 +02:00
|
|
|
Diff: &terraform.InstanceDiff{
|
2014-08-28 00:26:15 +02:00
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"availability_zone": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "bar",
|
|
|
|
New: "foo",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "1",
|
|
|
|
New: "",
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-12-12 15:24:29 +01:00
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
// #40 Set
|
2014-12-12 15:24:29 +01:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"instances": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Elem: &Schema{Type: TypeString},
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
Set: func(v interface{}) int {
|
2014-12-12 15:42:01 +01:00
|
|
|
return len(v.(string))
|
2014-12-12 15:24:29 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"instances.#": "0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"instances": []interface{}{"${var.foo}"},
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigVariables: map[string]string{
|
|
|
|
"var.foo": config.UnknownVariableValue,
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
2014-12-12 23:21:20 +01:00
|
|
|
"instances.#": &terraform.ResourceAttrDiff{
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
// #41 Set
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"route": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"index": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"gateway": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Set: func(v interface{}) int {
|
|
|
|
m := v.(map[string]interface{})
|
|
|
|
return m["index"].(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"route": []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"index": "1",
|
|
|
|
"gateway": "${var.foo}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigVariables: map[string]string{
|
|
|
|
"var.foo": config.UnknownVariableValue,
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"route.#": &terraform.ResourceAttrDiff{
|
2014-12-12 15:24:29 +01:00
|
|
|
Old: "0",
|
|
|
|
New: "1",
|
|
|
|
},
|
2014-12-12 23:21:20 +01:00
|
|
|
"route.~1.index": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "1",
|
|
|
|
},
|
|
|
|
"route.~1.gateway": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "${var.foo}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-12-12 15:24:29 +01:00
|
|
|
|
2014-12-12 23:21:20 +01:00
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
// #42 Set
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"route": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"index": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"gateway": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Set: func(v interface{}) int {
|
|
|
|
m := v.(map[string]interface{})
|
|
|
|
return m["index"].(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"route": []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"index": "1",
|
|
|
|
"gateway": []interface{}{
|
|
|
|
"${var.foo}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigVariables: map[string]string{
|
|
|
|
"var.foo": config.UnknownVariableValue,
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"route.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "0",
|
|
|
|
New: "1",
|
|
|
|
},
|
|
|
|
"route.~1.index": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "1",
|
|
|
|
},
|
|
|
|
"route.~1.gateway.#": &terraform.ResourceAttrDiff{
|
2014-12-12 15:24:29 +01:00
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-12-16 02:35:16 +01:00
|
|
|
|
|
|
|
// #43 - Computed maps
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"vars": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: nil,
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"vars.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-12-16 18:05:16 +01:00
|
|
|
|
|
|
|
// #44 - Computed maps
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"vars": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"vars.#": "0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"vars": map[string]interface{}{
|
|
|
|
"bar": "${var.foo}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigVariables: map[string]string{
|
|
|
|
"var.foo": config.UnknownVariableValue,
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"vars.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-12-17 00:56:40 +01:00
|
|
|
|
|
|
|
// #45 - Empty
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-01-11 21:51:48 +01:00
|
|
|
|
|
|
|
// #46 - Float
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"some_threshold": &Schema{
|
|
|
|
Type: TypeFloat,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"some_threshold": "567.8",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"some_threshold": 12.34,
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
2015-01-14 18:32:03 +01:00
|
|
|
"some_threshold": &terraform.ResourceAttrDiff{
|
2015-01-11 21:51:48 +01:00
|
|
|
Old: "567.8",
|
|
|
|
New: "12.34",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-01-27 21:23:49 +01:00
|
|
|
|
|
|
|
// #47 - https://github.com/hashicorp/terraform/issues/824
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"block_device": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"device_name": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
"delete_on_termination": &Schema{
|
|
|
|
Type: TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
Default: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Set: func(v interface{}) int {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
m := v.(map[string]interface{})
|
|
|
|
buf.WriteString(fmt.Sprintf("%s-", m["device_name"].(string)))
|
|
|
|
buf.WriteString(fmt.Sprintf("%t-", m["delete_on_termination"].(bool)))
|
|
|
|
return hashcode.String(buf.String())
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"block_device.#": "2",
|
|
|
|
"block_device.616397234.delete_on_termination": "true",
|
|
|
|
"block_device.616397234.device_name": "/dev/sda1",
|
|
|
|
"block_device.2801811477.delete_on_termination": "true",
|
|
|
|
"block_device.2801811477.device_name": "/dev/sdx",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"block_device": []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"device_name": "/dev/sda1",
|
|
|
|
},
|
|
|
|
map[string]interface{}{
|
|
|
|
"device_name": "/dev/sdx",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Diff: nil,
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-02-17 20:10:45 +01:00
|
|
|
|
2015-02-17 20:12:45 +01:00
|
|
|
// #48 - Zero value in state shouldn't result in diff
|
2015-02-17 20:10:45 +01:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"port": &Schema{
|
|
|
|
Type: TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"port": "false",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-02-17 20:12:45 +01:00
|
|
|
|
2015-02-18 21:54:08 +01:00
|
|
|
// #49 Set - Same as #48 but for sets
|
2015-02-17 20:12:45 +01:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"route": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"index": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"gateway": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Set: func(v interface{}) int {
|
|
|
|
m := v.(map[string]interface{})
|
|
|
|
return m["index"].(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"route.#": "0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-02-17 22:15:30 +01:00
|
|
|
|
2015-02-17 22:17:23 +01:00
|
|
|
// #50 - A set computed element shouldn't cause a diff
|
2015-02-17 22:15:30 +01:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"active": &Schema{
|
|
|
|
Type: TypeBool,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"active": "true",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-02-17 23:45:18 +01:00
|
|
|
|
2015-02-17 23:46:24 +01:00
|
|
|
// #51 - An empty set should show up in the diff
|
2015-02-17 23:45:18 +01:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"instances": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Elem: &Schema{Type: TypeString},
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
Set: func(v interface{}) int {
|
|
|
|
return len(v.(string))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2015-02-18 21:54:08 +01:00
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"instances.#": "1",
|
|
|
|
"instances.3": "foo",
|
|
|
|
},
|
|
|
|
},
|
2015-02-17 23:45:18 +01:00
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"instances.#": &terraform.ResourceAttrDiff{
|
2015-02-18 21:54:08 +01:00
|
|
|
Old: "1",
|
2015-02-17 23:45:18 +01:00
|
|
|
New: "0",
|
|
|
|
RequiresNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-02-18 00:22:45 +01:00
|
|
|
|
|
|
|
// #52 - Map with empty value
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"vars": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"vars": map[string]interface{}{
|
|
|
|
"foo": "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"vars.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "0",
|
|
|
|
New: "1",
|
|
|
|
},
|
|
|
|
"vars.foo": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-02-18 21:54:08 +01:00
|
|
|
|
|
|
|
// #53 - Unset bool, not in state
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"force": &Schema{
|
|
|
|
Type: TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
// #54 - Unset set, not in state
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"metadata_keys": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(interface{}) int { return 0 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-02-18 23:10:12 +01:00
|
|
|
|
|
|
|
// #55 - Unset list in state, should not show up computed
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"metadata_keys": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: &terraform.InstanceState{
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"metadata_keys.#": "0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Diff: nil,
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2015-02-28 06:51:14 +01:00
|
|
|
|
|
|
|
// #56 - Set element computed substring
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
State: nil,
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": []interface{}{1, "${var.foo}32"},
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigVariables: map[string]string{
|
|
|
|
"var.foo": config.UnknownVariableValue,
|
|
|
|
},
|
|
|
|
|
|
|
|
Diff: &terraform.InstanceDiff{
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
"ports.#": &terraform.ResourceAttrDiff{
|
|
|
|
Old: "",
|
|
|
|
New: "",
|
|
|
|
NewComputed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-08-15 04:55:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
|
|
|
c, err := config.NewRawConfig(tc.Config)
|
|
|
|
if err != nil {
|
2014-12-12 23:21:20 +01:00
|
|
|
t.Fatalf("#%d err: %s", i, err)
|
2014-08-15 04:55:47 +02:00
|
|
|
}
|
|
|
|
|
2014-08-31 02:03:01 +02:00
|
|
|
if len(tc.ConfigVariables) > 0 {
|
2015-01-15 07:01:42 +01:00
|
|
|
vars := make(map[string]ast.Variable)
|
2015-01-15 00:28:36 +01:00
|
|
|
for k, v := range tc.ConfigVariables {
|
2015-01-15 07:01:42 +01:00
|
|
|
vars[k] = ast.Variable{Value: v, Type: ast.TypeString}
|
2015-01-15 00:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := c.Interpolate(vars); err != nil {
|
2014-12-12 23:21:20 +01:00
|
|
|
t.Fatalf("#%d err: %s", i, err)
|
2014-08-31 02:03:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 04:55:47 +02:00
|
|
|
d, err := schemaMap(tc.Schema).Diff(
|
|
|
|
tc.State, terraform.NewResourceConfig(c))
|
|
|
|
if (err != nil) != tc.Err {
|
2014-08-21 00:45:34 +02:00
|
|
|
t.Fatalf("#%d err: %s", i, err)
|
2014-08-15 04:55:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(tc.Diff, d) {
|
|
|
|
t.Fatalf("#%d: bad:\n\n%#v", i, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 07:00:16 +02:00
|
|
|
|
2014-09-29 19:25:43 +02:00
|
|
|
func TestSchemaMap_Input(t *testing.T) {
|
2015-01-27 21:23:49 +01:00
|
|
|
cases := map[string]struct {
|
2014-09-29 19:25:43 +02:00
|
|
|
Schema map[string]*Schema
|
|
|
|
Config map[string]interface{}
|
|
|
|
Input map[string]string
|
|
|
|
Result map[string]interface{}
|
|
|
|
Err bool
|
|
|
|
}{
|
|
|
|
/*
|
|
|
|
* String decode
|
|
|
|
*/
|
|
|
|
|
2015-01-27 21:23:49 +01:00
|
|
|
"uses input on optional field with no config": {
|
2014-09-29 20:16:19 +02:00
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Input: map[string]string{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: map[string]interface{}{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2015-01-27 21:23:49 +01:00
|
|
|
"input ignored when config has a value": {
|
2014-09-29 19:25:43 +02:00
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
},
|
|
|
|
|
|
|
|
Input: map[string]string{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
},
|
|
|
|
|
2014-10-18 23:54:42 +02:00
|
|
|
Result: map[string]interface{}{},
|
2014-09-29 19:25:43 +02:00
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-10-13 02:37:52 +02:00
|
|
|
|
2015-01-27 21:23:49 +01:00
|
|
|
"input ignored when schema has a default": {
|
2014-10-13 02:37:52 +02:00
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Default: "foo",
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Input: map[string]string{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: map[string]interface{}{},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2015-01-27 21:23:49 +01:00
|
|
|
"input ignored when default function returns a value": {
|
2014-10-13 02:37:52 +02:00
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
DefaultFunc: func() (interface{}, error) {
|
|
|
|
return "foo", nil
|
|
|
|
},
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Input: map[string]string{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: map[string]interface{}{},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2015-01-27 21:23:49 +01:00
|
|
|
"input used when default function returns nil": {
|
2014-10-13 02:37:52 +02:00
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
DefaultFunc: func() (interface{}, error) {
|
|
|
|
return nil, nil
|
|
|
|
},
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Input: map[string]string{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
},
|
|
|
|
|
|
|
|
Result: map[string]interface{}{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-09-29 19:25:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
2014-09-29 20:16:19 +02:00
|
|
|
if tc.Config == nil {
|
|
|
|
tc.Config = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
|
2014-09-29 19:25:43 +02:00
|
|
|
c, err := config.NewRawConfig(tc.Config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
input := new(terraform.MockUIInput)
|
|
|
|
input.InputReturnMap = tc.Input
|
|
|
|
|
2014-10-18 23:54:42 +02:00
|
|
|
rc := terraform.NewResourceConfig(c)
|
|
|
|
rc.Config = make(map[string]interface{})
|
|
|
|
|
|
|
|
actual, err := schemaMap(tc.Schema).Input(input, rc)
|
2014-09-29 19:25:43 +02:00
|
|
|
if (err != nil) != tc.Err {
|
2015-01-27 21:23:49 +01:00
|
|
|
t.Fatalf("#%v err: %s", i, err)
|
2014-09-29 19:25:43 +02:00
|
|
|
}
|
|
|
|
|
2014-10-18 23:54:42 +02:00
|
|
|
if !reflect.DeepEqual(tc.Result, actual.Config) {
|
2015-01-27 21:23:49 +01:00
|
|
|
t.Fatalf("#%v: bad:\n\ngot: %#v\nexpected: %#v", i, actual.Config, tc.Result)
|
2014-09-29 19:25:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-17 23:50:44 +02:00
|
|
|
func TestSchemaMap_InternalValidate(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
In map[string]*Schema
|
|
|
|
Err bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
|
|
|
// No optional and no required
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
2014-08-25 01:52:51 +02:00
|
|
|
// No optional and no required
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
2014-08-17 23:50:44 +02:00
|
|
|
// Missing Type
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Required but computed
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Looks good
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
2014-09-10 06:17:29 +02:00
|
|
|
// Computed but has default
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
Default: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
2014-09-10 06:33:08 +02:00
|
|
|
// Required but has default
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Required: true,
|
|
|
|
Default: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
2014-08-17 23:50:44 +02:00
|
|
|
// List element not set
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
2014-09-10 06:17:29 +02:00
|
|
|
// List default
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Default: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
2014-08-17 23:50:44 +02:00
|
|
|
// List element computed
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
2014-08-25 01:52:51 +02:00
|
|
|
Type: TypeList,
|
|
|
|
Optional: true,
|
2014-08-17 23:50:44 +02:00
|
|
|
Elem: &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
2014-08-21 06:13:18 +02:00
|
|
|
// List element with Set set
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
2014-08-25 01:52:51 +02:00
|
|
|
Type: TypeList,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(interface{}) int { return 0 },
|
|
|
|
Optional: true,
|
2014-08-21 06:13:18 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Set element with no Set set
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
2014-08-25 01:52:51 +02:00
|
|
|
Type: TypeSet,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Optional: true,
|
2014-08-21 06:13:18 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
2014-08-17 23:50:44 +02:00
|
|
|
// Required but computed
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
ComputedWhen: []string{"foo"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Sub-resource invalid
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
2014-08-25 01:52:51 +02:00
|
|
|
Type: TypeList,
|
|
|
|
Optional: true,
|
2014-08-17 23:50:44 +02:00
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"foo": new(Schema),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Sub-resource valid
|
|
|
|
{
|
|
|
|
map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
2014-08-25 01:52:51 +02:00
|
|
|
Type: TypeList,
|
|
|
|
Optional: true,
|
2014-08-17 23:50:44 +02:00
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"foo": &Schema{
|
2014-08-25 01:52:51 +02:00
|
|
|
Type: TypeInt,
|
|
|
|
Optional: true,
|
2014-08-17 23:50:44 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
|
|
|
err := schemaMap(tc.In).InternalValidate()
|
|
|
|
if (err != nil) != tc.Err {
|
2014-08-25 01:52:51 +02:00
|
|
|
t.Fatalf("%d: bad: %s\n\n%#v", i, err, tc.In)
|
2014-08-17 23:50:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-16 07:00:16 +02:00
|
|
|
func TestSchemaMap_Validate(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Schema map[string]*Schema
|
|
|
|
Config map[string]interface{}
|
2014-10-16 23:04:45 +02:00
|
|
|
Vars map[string]string
|
2014-08-16 07:00:16 +02:00
|
|
|
Warn bool
|
|
|
|
Err bool
|
|
|
|
}{
|
2015-02-18 18:41:55 +01:00
|
|
|
// #0 Good
|
2014-08-16 07:00:16 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"availability_zone": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #1 Good, because the var is not set and that error will come elsewhere
|
2014-10-16 23:04:45 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"size": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"size": "${var.foo}",
|
|
|
|
},
|
|
|
|
|
|
|
|
Vars: map[string]string{
|
|
|
|
"var.foo": config.UnknownVariableValue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #2 Required field not set
|
2014-08-16 07:00:16 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #3 Invalid type
|
2014-08-16 07:00:16 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"port": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"port": "I am invalid",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #4
|
2014-10-20 04:56:46 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"user_data": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"user_data": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #5 Bad type, interpolated
|
2014-10-16 23:04:45 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"size": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"size": "${var.foo}",
|
|
|
|
},
|
|
|
|
|
|
|
|
Vars: map[string]string{
|
|
|
|
"var.foo": "nope",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #6 Required but has DefaultFunc
|
2014-09-10 06:33:08 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: func() (interface{}, error) {
|
|
|
|
return "foo", nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: nil,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #7 Required but has DefaultFunc return nil
|
2014-09-10 06:33:08 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: func() (interface{}, error) {
|
|
|
|
return nil, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: nil,
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #8 Optional sub-resource
|
2014-08-16 07:00:16 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ingress": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"from": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #9 Not a list
|
2014-08-16 07:00:16 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ingress": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"from": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ingress": "foo",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #10 Required sub-resource field
|
2014-08-16 07:00:16 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ingress": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"from": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ingress": []interface{}{
|
|
|
|
map[string]interface{}{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #11 Good sub-resource
|
2014-08-16 07:00:16 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ingress": &Schema{
|
2014-08-16 18:18:45 +02:00
|
|
|
Type: TypeList,
|
|
|
|
Optional: true,
|
2014-08-16 07:00:16 +02:00
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"from": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ingress": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"from": 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
2014-08-16 07:15:10 +02:00
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #12 Invalid/unknown field
|
2014-08-16 07:15:10 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
2014-08-16 18:18:45 +02:00
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #13 Computed field set
|
2014-08-16 18:18:45 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"availability_zone": &Schema{
|
|
|
|
Type: TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"availability_zone": "bar",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
2014-10-18 08:23:50 +02:00
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #14 Not a set
|
2014-10-18 08:23:50 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ports": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Elem: &Schema{Type: TypeInt},
|
|
|
|
Set: func(a interface{}) int {
|
|
|
|
return a.(int)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ports": "foo",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
2014-10-20 05:33:00 +02:00
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #15 Maps
|
2014-10-20 05:33:00 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"user_data": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"user_data": "foo",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #16
|
2014-10-20 05:33:00 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"user_data": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"user_data": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #17
|
2014-10-20 05:33:00 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"user_data": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"user_data": map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #18
|
2014-10-20 05:33:00 +02:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"user_data": &Schema{
|
|
|
|
Type: TypeMap,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"user_data": []interface{}{
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
2015-01-12 13:57:47 +01:00
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #19
|
2015-01-12 13:57:47 +01:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"security_groups": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
Elem: &Schema{Type: TypeString},
|
|
|
|
Set: func(v interface{}) int {
|
|
|
|
return len(v.(string))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"security_groups": []interface{}{"${var.foo}"},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: false,
|
|
|
|
},
|
|
|
|
|
2015-02-18 18:41:55 +01:00
|
|
|
// #20
|
2015-01-12 13:57:47 +01:00
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"security_groups": &Schema{
|
|
|
|
Type: TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
Elem: &Schema{Type: TypeString},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"security_groups": "${var.foo}",
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
2015-02-18 18:41:55 +01:00
|
|
|
|
|
|
|
// #21 Bad, subresource should not allow unknown elements
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ingress": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"port": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ingress": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"port": 80,
|
|
|
|
"other": "yes",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
// #22 Bad, subresource should not allow invalid types
|
|
|
|
{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"ingress": &Schema{
|
|
|
|
Type: TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &Resource{
|
|
|
|
Schema: map[string]*Schema{
|
|
|
|
"port": &Schema{
|
|
|
|
Type: TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"ingress": []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"port": "bad",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Err: true,
|
|
|
|
},
|
2014-08-16 07:00:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
|
|
|
c, err := config.NewRawConfig(tc.Config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2014-10-16 23:04:45 +02:00
|
|
|
if tc.Vars != nil {
|
2015-01-15 07:01:42 +01:00
|
|
|
vars := make(map[string]ast.Variable)
|
2015-01-15 00:28:36 +01:00
|
|
|
for k, v := range tc.Vars {
|
2015-01-15 07:01:42 +01:00
|
|
|
vars[k] = ast.Variable{Value: v, Type: ast.TypeString}
|
2015-01-15 00:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := c.Interpolate(vars); err != nil {
|
2014-10-16 23:04:45 +02:00
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 07:00:16 +02:00
|
|
|
|
|
|
|
ws, es := schemaMap(tc.Schema).Validate(terraform.NewResourceConfig(c))
|
|
|
|
if (len(es) > 0) != tc.Err {
|
|
|
|
if len(es) == 0 {
|
|
|
|
t.Errorf("%d: no errors", i)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range es {
|
|
|
|
t.Errorf("%d: err: %s", i, e)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len(ws) > 0) != tc.Warn {
|
|
|
|
t.Fatalf("%d: ws: %#v", i, ws)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|