diff --git a/go.mod b/go.mod index 0181e80d..e4ec7918 100644 --- a/go.mod +++ b/go.mod @@ -36,10 +36,10 @@ replace ( require ( github.com/Masterminds/sprig v2.22.0+incompatible - github.com/aws/aws-sdk-go v1.39.6 + github.com/aws/aws-sdk-go v1.40.0 github.com/google/go-cmp v0.5.6 github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0 - golang.org/x/tools v0.1.4 + golang.org/x/tools v0.1.5 k8s.io/api v0.21.0 k8s.io/apimachinery v0.21.0 k8s.io/client-go v0.21.0 diff --git a/go.sum b/go.sum index 259ba5e7..017e7c47 100644 --- a/go.sum +++ b/go.sum @@ -187,8 +187,8 @@ github.com/aws/aws-sdk-go v1.31.12/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZve github.com/aws/aws-sdk-go v1.34.30/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= github.com/aws/aws-sdk-go v1.35.24/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k= github.com/aws/aws-sdk-go v1.38.29/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= -github.com/aws/aws-sdk-go v1.39.6 h1:7NoOv+XsP/7A6Yaieg8r2+bnPD3ZTARa/5tHl8N8JKY= -github.com/aws/aws-sdk-go v1.39.6/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= +github.com/aws/aws-sdk-go v1.40.0 h1:nTCSQAeahNt15SOYxuDwJ8XvMhOU3Uqe7eJUPv7+Vsk= +github.com/aws/aws-sdk-go v1.40.0/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -1560,8 +1560,8 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= -golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/hack/gen-tf-code/templates/schema.tpl b/hack/gen-tf-code/templates/schema.tpl index 452f53bd..888b6b65 100644 --- a/hack/gen-tf-code/templates/schema.tpl +++ b/hack/gen-tf-code/templates/schema.tpl @@ -38,7 +38,11 @@ var _ = Schema {{- else if isList . -}} List({{ template "schemaElem" .Elem }}) {{- else if isMap . -}} +{{- if or (isBool .Elem) (isInt .Elem) (isString .Elem) (isFloat .Elem) -}} Map({{ template "schemaElem" .Elem }}) +{{- else -}} +ComplexMap({{ template "schemaElem" .Elem }}) +{{- end -}} {{- else if isDuration . -}} Duration() {{- else if isQuantity . -}} @@ -164,6 +168,7 @@ func (in interface{}) {{ .String }} { return out }(in) {{- else if isMap . -}} +{{- if or (isBool .Elem) (isInt .Elem) (isString .Elem) (isFloat .Elem) -}} func (in interface{}) map[string]{{ .Elem.String }} { if in == nil { return nil @@ -179,6 +184,29 @@ func (in interface{}) map[string]{{ .Elem.String }} { } return nil }(in) +{{- else -}} +func (in interface{}) map[string]{{ .Elem.String }} { + if in == nil { + return nil + } + if in, ok := in.([]interface{}); ok { + if len(in) > 0 { + out := {{ .String }}{} + for _, in := range in { + if in, ok := in.(map[string]interface{}); ok { + key := ExpandString(in["key"]) + value := func(in interface{}) {{ .Elem.String }} { + return {{ template "expand" .Elem }} + }(in["value"]) + out[key] = value + } + } + return out + } + } + return nil +}(in) +{{- end -}} {{- else if isDuration . -}} ExpandDuration(in) {{- else if isQuantity . -}} @@ -241,6 +269,7 @@ func (in {{ .String }}) []interface{} { return out }(in) {{- else if isMap . -}} +{{- if or (isBool .Elem) (isInt .Elem) (isString .Elem) (isFloat .Elem) -}} func (in map[string]{{ .Elem.String }}) map[string]interface{} { if in == nil { return nil @@ -251,6 +280,21 @@ func (in map[string]{{ .Elem.String }}) map[string]interface{} { } return out }(in) +{{- else -}} +func (in map[string]{{ .Elem.String }}) []interface{} { + if in == nil { + return nil + } + var out []interface{} + for key, in := range in { + out = append(out, map[string]interface{}{ + "key": key, + "value": {{ template "flattenElem" .Elem }}, + }) + } + return out +}(in) +{{- end -}} {{- else if isDuration . -}} FlattenDuration(in) {{- else if isQuantity . -}} diff --git a/hack/gen-tf-code/templates/test.tpl b/hack/gen-tf-code/templates/test.tpl index f2908840..77154c82 100644 --- a/hack/gen-tf-code/templates/test.tpl +++ b/hack/gen-tf-code/templates/test.tpl @@ -42,7 +42,11 @@ nil {{- else if isList . -}} func() []interface{} { return nil }() {{- else if isMap . -}} +{{- if or (isBool .Elem) (isInt .Elem) (isString .Elem) (isFloat .Elem) -}} func() map[string]interface{} { return nil }() +{{- else -}} +func() []interface{} { return nil }() +{{- end -}} {{- else if isDuration . -}} "" {{- else if isQuantity . -}} @@ -68,7 +72,11 @@ nil {{- else if isList . -}} func() []interface{} { return nil }() {{- else if isMap . -}} +{{- if or (isBool .Elem) (isInt .Elem) (isString .Elem) (isFloat .Elem) -}} func() map[string]interface{} { return nil }() +{{- else -}} +func() []interface{} { return nil }() +{{- end -}} {{- else if isDuration . -}} "" {{- else if isQuantity . -}} diff --git a/pkg/schemas/kops/DataSource_ClusterSpec.generated.go b/pkg/schemas/kops/DataSource_ClusterSpec.generated.go index 6c6f37a8..59e44d48 100644 --- a/pkg/schemas/kops/DataSource_ClusterSpec.generated.go +++ b/pkg/schemas/kops/DataSource_ClusterSpec.generated.go @@ -43,7 +43,7 @@ func DataSourceClusterSpec() *schema.Resource { "kubernetes_api_access": ComputedList(String()), "isolate_masters": ComputedBool(), "update_policy": ComputedString(), - "external_policies": ComputedMap(List(String())), + "external_policies": ComputedComplexMap(List(String())), "additional_policies": ComputedMap(String()), "file_assets": ComputedList(DataSourceFileAssetSpec()), "etcd_cluster": ComputedList(DataSourceEtcdClusterSpec()), @@ -348,20 +348,26 @@ func ExpandDataSourceClusterSpec(in map[string]interface{}) kops.ClusterSpec { if in == nil { return nil } - if in, ok := in.(map[string]interface{}); ok { + if in, ok := in.([]interface{}); ok { if len(in) > 0 { out := map[string][]string{} - for key, in := range in { - out[key] = func(in interface{}) []string { - if in == nil { - return nil - } - var out []string - for _, in := range in.([]interface{}) { - out = append(out, string(ExpandString(in))) - } - return out - }(in) + for _, in := range in { + if in, ok := in.(map[string]interface{}); ok { + key := ExpandString(in["key"]) + value := func(in interface{}) []string { + return func(in interface{}) []string { + if in == nil { + return nil + } + var out []string + for _, in := range in.([]interface{}) { + out = append(out, string(ExpandString(in))) + } + return out + }(in) + }(in["value"]) + out[key] = value + } } return out } @@ -1225,19 +1231,22 @@ func FlattenDataSourceClusterSpecInto(in kops.ClusterSpec, out map[string]interf return nil } return func(in map[string][]string) interface{} { - return func(in map[string][]string) map[string]interface{} { + return func(in map[string][]string) []interface{} { if in == nil { return nil } - out := map[string]interface{}{} + var out []interface{} for key, in := range in { - out[key] = func(in []string) []interface{} { - var out []interface{} - for _, in := range in { - out = append(out, FlattenString(string(in))) - } - return out - }(in) + out = append(out, map[string]interface{}{ + "key": key, + "value": func(in []string) []interface{} { + var out []interface{} + for _, in := range in { + out = append(out, FlattenString(string(in))) + } + return out + }(in), + }) } return out }(in) diff --git a/pkg/schemas/kops/DataSource_ContainerdConfig.generated.go b/pkg/schemas/kops/DataSource_ContainerdConfig.generated.go index 4ca9edf5..56af0450 100644 --- a/pkg/schemas/kops/DataSource_ContainerdConfig.generated.go +++ b/pkg/schemas/kops/DataSource_ContainerdConfig.generated.go @@ -17,7 +17,7 @@ func DataSourceContainerdConfig() *schema.Resource { "config_override": ComputedString(), "log_level": ComputedString(), "packages": ComputedStruct(DataSourcePackagesConfig()), - "registry_mirrors": ComputedMap(List(String())), + "registry_mirrors": ComputedComplexMap(List(String())), "root": ComputedString(), "skip_install": ComputedBool(), "state": ComputedString(), @@ -113,20 +113,26 @@ func ExpandDataSourceContainerdConfig(in map[string]interface{}) kops.Containerd if in == nil { return nil } - if in, ok := in.(map[string]interface{}); ok { + if in, ok := in.([]interface{}); ok { if len(in) > 0 { out := map[string][]string{} - for key, in := range in { - out[key] = func(in interface{}) []string { - if in == nil { - return nil - } - var out []string - for _, in := range in.([]interface{}) { - out = append(out, string(ExpandString(in))) - } - return out - }(in) + for _, in := range in { + if in, ok := in.(map[string]interface{}); ok { + key := ExpandString(in["key"]) + value := func(in interface{}) []string { + return func(in interface{}) []string { + if in == nil { + return nil + } + var out []string + for _, in := range in.([]interface{}) { + out = append(out, string(ExpandString(in))) + } + return out + }(in) + }(in["value"]) + out[key] = value + } } return out } @@ -241,19 +247,22 @@ func FlattenDataSourceContainerdConfigInto(in kops.ContainerdConfig, out map[str }(in) }(in.Packages) out["registry_mirrors"] = func(in map[string][]string) interface{} { - return func(in map[string][]string) map[string]interface{} { + return func(in map[string][]string) []interface{} { if in == nil { return nil } - out := map[string]interface{}{} + var out []interface{} for key, in := range in { - out[key] = func(in []string) []interface{} { - var out []interface{} - for _, in := range in { - out = append(out, FlattenString(string(in))) - } - return out - }(in) + out = append(out, map[string]interface{}{ + "key": key, + "value": func(in []string) []interface{} { + var out []interface{} + for _, in := range in { + out = append(out, FlattenString(string(in))) + } + return out + }(in), + }) } return out }(in) diff --git a/pkg/schemas/kops/DataSource_ContainerdConfig.generated_test.go b/pkg/schemas/kops/DataSource_ContainerdConfig.generated_test.go index 89e769c6..27cf4c25 100644 --- a/pkg/schemas/kops/DataSource_ContainerdConfig.generated_test.go +++ b/pkg/schemas/kops/DataSource_ContainerdConfig.generated_test.go @@ -25,7 +25,7 @@ func TestExpandDataSourceContainerdConfig(t *testing.T) { "config_override": nil, "log_level": nil, "packages": nil, - "registry_mirrors": func() map[string]interface{} { return nil }(), + "registry_mirrors": func() []interface{} { return nil }(), "root": nil, "skip_install": false, "state": nil, @@ -51,7 +51,7 @@ func TestFlattenDataSourceContainerdConfigInto(t *testing.T) { "config_override": nil, "log_level": nil, "packages": nil, - "registry_mirrors": func() map[string]interface{} { return nil }(), + "registry_mirrors": func() []interface{} { return nil }(), "root": nil, "skip_install": false, "state": nil, @@ -189,7 +189,7 @@ func TestFlattenDataSourceContainerdConfig(t *testing.T) { "config_override": nil, "log_level": nil, "packages": nil, - "registry_mirrors": func() map[string]interface{} { return nil }(), + "registry_mirrors": func() []interface{} { return nil }(), "root": nil, "skip_install": false, "state": nil, diff --git a/pkg/schemas/kops/DataSource_KubeDNSConfig.generated.go b/pkg/schemas/kops/DataSource_KubeDNSConfig.generated.go index cbf61c3a..43c3b7c5 100644 --- a/pkg/schemas/kops/DataSource_KubeDNSConfig.generated.go +++ b/pkg/schemas/kops/DataSource_KubeDNSConfig.generated.go @@ -24,7 +24,7 @@ func DataSourceKubeDNSConfig() *schema.Resource { "replicas": ComputedInt(), "provider": ComputedString(), "server_ip": ComputedString(), - "stub_domains": ComputedMap(List(String())), + "stub_domains": ComputedComplexMap(List(String())), "upstream_nameservers": ComputedList(String()), "memory_request": ComputedQuantity(), "cpu_request": ComputedQuantity(), @@ -76,20 +76,26 @@ func ExpandDataSourceKubeDNSConfig(in map[string]interface{}) kops.KubeDNSConfig if in == nil { return nil } - if in, ok := in.(map[string]interface{}); ok { + if in, ok := in.([]interface{}); ok { if len(in) > 0 { out := map[string][]string{} - for key, in := range in { - out[key] = func(in interface{}) []string { - if in == nil { - return nil - } - var out []string - for _, in := range in.([]interface{}) { - out = append(out, string(ExpandString(in))) - } - return out - }(in) + for _, in := range in { + if in, ok := in.(map[string]interface{}); ok { + key := ExpandString(in["key"]) + value := func(in interface{}) []string { + return func(in interface{}) []string { + if in == nil { + return nil + } + var out []string + for _, in := range in.([]interface{}) { + out = append(out, string(ExpandString(in))) + } + return out + }(in) + }(in["value"]) + out[key] = value + } } return out } @@ -219,19 +225,22 @@ func FlattenDataSourceKubeDNSConfigInto(in kops.KubeDNSConfig, out map[string]in return FlattenString(string(in)) }(in.ServerIP) out["stub_domains"] = func(in map[string][]string) interface{} { - return func(in map[string][]string) map[string]interface{} { + return func(in map[string][]string) []interface{} { if in == nil { return nil } - out := map[string]interface{}{} + var out []interface{} for key, in := range in { - out[key] = func(in []string) []interface{} { - var out []interface{} - for _, in := range in { - out = append(out, FlattenString(string(in))) - } - return out - }(in) + out = append(out, map[string]interface{}{ + "key": key, + "value": func(in []string) []interface{} { + var out []interface{} + for _, in := range in { + out = append(out, FlattenString(string(in))) + } + return out + }(in), + }) } return out }(in) diff --git a/pkg/schemas/kops/DataSource_KubeDNSConfig.generated_test.go b/pkg/schemas/kops/DataSource_KubeDNSConfig.generated_test.go index ad79db66..5359c4e4 100644 --- a/pkg/schemas/kops/DataSource_KubeDNSConfig.generated_test.go +++ b/pkg/schemas/kops/DataSource_KubeDNSConfig.generated_test.go @@ -31,7 +31,7 @@ func TestExpandDataSourceKubeDNSConfig(t *testing.T) { "replicas": 0, "provider": "", "server_ip": "", - "stub_domains": func() map[string]interface{} { return nil }(), + "stub_domains": func() []interface{} { return nil }(), "upstream_nameservers": func() []interface{} { return nil }(), "memory_request": nil, "cpu_request": nil, @@ -64,7 +64,7 @@ func TestFlattenDataSourceKubeDNSConfigInto(t *testing.T) { "replicas": 0, "provider": "", "server_ip": "", - "stub_domains": func() map[string]interface{} { return nil }(), + "stub_domains": func() []interface{} { return nil }(), "upstream_nameservers": func() []interface{} { return nil }(), "memory_request": nil, "cpu_request": nil, @@ -286,7 +286,7 @@ func TestFlattenDataSourceKubeDNSConfig(t *testing.T) { "replicas": 0, "provider": "", "server_ip": "", - "stub_domains": func() map[string]interface{} { return nil }(), + "stub_domains": func() []interface{} { return nil }(), "upstream_nameservers": func() []interface{} { return nil }(), "memory_request": nil, "cpu_request": nil, diff --git a/pkg/schemas/kops/Resource_ClusterSpec.generated.go b/pkg/schemas/kops/Resource_ClusterSpec.generated.go index 069e24b7..fdccee8d 100644 --- a/pkg/schemas/kops/Resource_ClusterSpec.generated.go +++ b/pkg/schemas/kops/Resource_ClusterSpec.generated.go @@ -269,20 +269,26 @@ func ExpandResourceClusterSpec(in map[string]interface{}) kops.ClusterSpec { if in == nil { return nil } - if in, ok := in.(map[string]interface{}); ok { + if in, ok := in.([]interface{}); ok { if len(in) > 0 { out := map[string][]string{} - for key, in := range in { - out[key] = func(in interface{}) []string { - if in == nil { - return nil - } - var out []string - for _, in := range in.([]interface{}) { - out = append(out, string(ExpandString(in))) - } - return out - }(in) + for _, in := range in { + if in, ok := in.(map[string]interface{}); ok { + key := ExpandString(in["key"]) + value := func(in interface{}) []string { + return func(in interface{}) []string { + if in == nil { + return nil + } + var out []string + for _, in := range in.([]interface{}) { + out = append(out, string(ExpandString(in))) + } + return out + }(in) + }(in["value"]) + out[key] = value + } } return out } @@ -1146,19 +1152,22 @@ func FlattenResourceClusterSpecInto(in kops.ClusterSpec, out map[string]interfac return nil } return func(in map[string][]string) interface{} { - return func(in map[string][]string) map[string]interface{} { + return func(in map[string][]string) []interface{} { if in == nil { return nil } - out := map[string]interface{}{} + var out []interface{} for key, in := range in { - out[key] = func(in []string) []interface{} { - var out []interface{} - for _, in := range in { - out = append(out, FlattenString(string(in))) - } - return out - }(in) + out = append(out, map[string]interface{}{ + "key": key, + "value": func(in []string) []interface{} { + var out []interface{} + for _, in := range in { + out = append(out, FlattenString(string(in))) + } + return out + }(in), + }) } return out }(in) diff --git a/pkg/schemas/kops/Resource_ContainerdConfig.generated.go b/pkg/schemas/kops/Resource_ContainerdConfig.generated.go index 33d06f3f..4f6dfccf 100644 --- a/pkg/schemas/kops/Resource_ContainerdConfig.generated.go +++ b/pkg/schemas/kops/Resource_ContainerdConfig.generated.go @@ -17,7 +17,7 @@ func ResourceContainerdConfig() *schema.Resource { "config_override": OptionalString(), "log_level": OptionalString(), "packages": OptionalStruct(ResourcePackagesConfig()), - "registry_mirrors": OptionalMap(List(String())), + "registry_mirrors": OptionalComplexMap(List(String())), "root": OptionalString(), "skip_install": OptionalBool(), "state": OptionalString(), @@ -113,20 +113,26 @@ func ExpandResourceContainerdConfig(in map[string]interface{}) kops.ContainerdCo if in == nil { return nil } - if in, ok := in.(map[string]interface{}); ok { + if in, ok := in.([]interface{}); ok { if len(in) > 0 { out := map[string][]string{} - for key, in := range in { - out[key] = func(in interface{}) []string { - if in == nil { - return nil - } - var out []string - for _, in := range in.([]interface{}) { - out = append(out, string(ExpandString(in))) - } - return out - }(in) + for _, in := range in { + if in, ok := in.(map[string]interface{}); ok { + key := ExpandString(in["key"]) + value := func(in interface{}) []string { + return func(in interface{}) []string { + if in == nil { + return nil + } + var out []string + for _, in := range in.([]interface{}) { + out = append(out, string(ExpandString(in))) + } + return out + }(in) + }(in["value"]) + out[key] = value + } } return out } @@ -241,19 +247,22 @@ func FlattenResourceContainerdConfigInto(in kops.ContainerdConfig, out map[strin }(in) }(in.Packages) out["registry_mirrors"] = func(in map[string][]string) interface{} { - return func(in map[string][]string) map[string]interface{} { + return func(in map[string][]string) []interface{} { if in == nil { return nil } - out := map[string]interface{}{} + var out []interface{} for key, in := range in { - out[key] = func(in []string) []interface{} { - var out []interface{} - for _, in := range in { - out = append(out, FlattenString(string(in))) - } - return out - }(in) + out = append(out, map[string]interface{}{ + "key": key, + "value": func(in []string) []interface{} { + var out []interface{} + for _, in := range in { + out = append(out, FlattenString(string(in))) + } + return out + }(in), + }) } return out }(in) diff --git a/pkg/schemas/kops/Resource_ContainerdConfig.generated_test.go b/pkg/schemas/kops/Resource_ContainerdConfig.generated_test.go index dd4a8870..283c9e06 100644 --- a/pkg/schemas/kops/Resource_ContainerdConfig.generated_test.go +++ b/pkg/schemas/kops/Resource_ContainerdConfig.generated_test.go @@ -25,7 +25,7 @@ func TestExpandResourceContainerdConfig(t *testing.T) { "config_override": nil, "log_level": nil, "packages": nil, - "registry_mirrors": func() map[string]interface{} { return nil }(), + "registry_mirrors": func() []interface{} { return nil }(), "root": nil, "skip_install": false, "state": nil, @@ -51,7 +51,7 @@ func TestFlattenResourceContainerdConfigInto(t *testing.T) { "config_override": nil, "log_level": nil, "packages": nil, - "registry_mirrors": func() map[string]interface{} { return nil }(), + "registry_mirrors": func() []interface{} { return nil }(), "root": nil, "skip_install": false, "state": nil, @@ -189,7 +189,7 @@ func TestFlattenResourceContainerdConfig(t *testing.T) { "config_override": nil, "log_level": nil, "packages": nil, - "registry_mirrors": func() map[string]interface{} { return nil }(), + "registry_mirrors": func() []interface{} { return nil }(), "root": nil, "skip_install": false, "state": nil, diff --git a/pkg/schemas/kops/Resource_KubeDNSConfig.generated.go b/pkg/schemas/kops/Resource_KubeDNSConfig.generated.go index 881d3609..98d8f2bc 100644 --- a/pkg/schemas/kops/Resource_KubeDNSConfig.generated.go +++ b/pkg/schemas/kops/Resource_KubeDNSConfig.generated.go @@ -24,7 +24,7 @@ func ResourceKubeDNSConfig() *schema.Resource { "replicas": OptionalInt(), "provider": OptionalString(), "server_ip": OptionalString(), - "stub_domains": OptionalMap(List(String())), + "stub_domains": OptionalComplexMap(List(String())), "upstream_nameservers": OptionalList(String()), "memory_request": OptionalQuantity(), "cpu_request": OptionalQuantity(), @@ -76,20 +76,26 @@ func ExpandResourceKubeDNSConfig(in map[string]interface{}) kops.KubeDNSConfig { if in == nil { return nil } - if in, ok := in.(map[string]interface{}); ok { + if in, ok := in.([]interface{}); ok { if len(in) > 0 { out := map[string][]string{} - for key, in := range in { - out[key] = func(in interface{}) []string { - if in == nil { - return nil - } - var out []string - for _, in := range in.([]interface{}) { - out = append(out, string(ExpandString(in))) - } - return out - }(in) + for _, in := range in { + if in, ok := in.(map[string]interface{}); ok { + key := ExpandString(in["key"]) + value := func(in interface{}) []string { + return func(in interface{}) []string { + if in == nil { + return nil + } + var out []string + for _, in := range in.([]interface{}) { + out = append(out, string(ExpandString(in))) + } + return out + }(in) + }(in["value"]) + out[key] = value + } } return out } @@ -219,19 +225,22 @@ func FlattenResourceKubeDNSConfigInto(in kops.KubeDNSConfig, out map[string]inte return FlattenString(string(in)) }(in.ServerIP) out["stub_domains"] = func(in map[string][]string) interface{} { - return func(in map[string][]string) map[string]interface{} { + return func(in map[string][]string) []interface{} { if in == nil { return nil } - out := map[string]interface{}{} + var out []interface{} for key, in := range in { - out[key] = func(in []string) []interface{} { - var out []interface{} - for _, in := range in { - out = append(out, FlattenString(string(in))) - } - return out - }(in) + out = append(out, map[string]interface{}{ + "key": key, + "value": func(in []string) []interface{} { + var out []interface{} + for _, in := range in { + out = append(out, FlattenString(string(in))) + } + return out + }(in), + }) } return out }(in) diff --git a/pkg/schemas/kops/Resource_KubeDNSConfig.generated_test.go b/pkg/schemas/kops/Resource_KubeDNSConfig.generated_test.go index 0877456d..e5f1ecaa 100644 --- a/pkg/schemas/kops/Resource_KubeDNSConfig.generated_test.go +++ b/pkg/schemas/kops/Resource_KubeDNSConfig.generated_test.go @@ -31,7 +31,7 @@ func TestExpandResourceKubeDNSConfig(t *testing.T) { "replicas": 0, "provider": "", "server_ip": "", - "stub_domains": func() map[string]interface{} { return nil }(), + "stub_domains": func() []interface{} { return nil }(), "upstream_nameservers": func() []interface{} { return nil }(), "memory_request": nil, "cpu_request": nil, @@ -64,7 +64,7 @@ func TestFlattenResourceKubeDNSConfigInto(t *testing.T) { "replicas": 0, "provider": "", "server_ip": "", - "stub_domains": func() map[string]interface{} { return nil }(), + "stub_domains": func() []interface{} { return nil }(), "upstream_nameservers": func() []interface{} { return nil }(), "memory_request": nil, "cpu_request": nil, @@ -286,7 +286,7 @@ func TestFlattenResourceKubeDNSConfig(t *testing.T) { "replicas": 0, "provider": "", "server_ip": "", - "stub_domains": func() map[string]interface{} { return nil }(), + "stub_domains": func() []interface{} { return nil }(), "upstream_nameservers": func() []interface{} { return nil }(), "memory_request": nil, "cpu_request": nil, diff --git a/pkg/schemas/resources/DataSource_Cluster.generated.go b/pkg/schemas/resources/DataSource_Cluster.generated.go index e91f7985..d7704b8d 100644 --- a/pkg/schemas/resources/DataSource_Cluster.generated.go +++ b/pkg/schemas/resources/DataSource_Cluster.generated.go @@ -45,7 +45,7 @@ func DataSourceCluster() *schema.Resource { "kubernetes_api_access": ComputedList(String()), "isolate_masters": ComputedBool(), "update_policy": ComputedString(), - "external_policies": ComputedMap(List(String())), + "external_policies": ComputedComplexMap(List(String())), "additional_policies": ComputedMap(String()), "file_assets": ComputedList(kopsschemas.DataSourceFileAssetSpec()), "etcd_cluster": ComputedList(kopsschemas.DataSourceEtcdClusterSpec()), diff --git a/pkg/schemas/resources/Resource_Cluster.generated.go b/pkg/schemas/resources/Resource_Cluster.generated.go index 3887123d..bfaa13ca 100644 --- a/pkg/schemas/resources/Resource_Cluster.generated.go +++ b/pkg/schemas/resources/Resource_Cluster.generated.go @@ -45,7 +45,7 @@ func ResourceCluster() *schema.Resource { "kubernetes_api_access": OptionalList(String()), "isolate_masters": OptionalBool(), "update_policy": OptionalString(), - "external_policies": OptionalMap(List(String())), + "external_policies": OptionalComplexMap(List(String())), "additional_policies": OptionalMap(String()), "file_assets": OptionalList(kopsschemas.ResourceFileAssetSpec()), "etcd_cluster": RequiredList(kopsschemas.ResourceEtcdClusterSpec()), diff --git a/pkg/schemas/zzz_utils.go b/pkg/schemas/zzz_utils.go index 2177f202..54ea9c3c 100644 --- a/pkg/schemas/zzz_utils.go +++ b/pkg/schemas/zzz_utils.go @@ -30,6 +30,16 @@ func Nullable(in *schema.Schema) *schema.Schema { ) } +func ComplexMapElem(in *schema.Schema) *schema.Resource { + in.Required = true + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": RequiredString(), + "value": in, + }, + } +} + // Tools func Schema(t schema.ValueType, elem interface{}, required, optional, computed bool, maxItems int) *schema.Schema { @@ -145,7 +155,7 @@ func RequiredMap(elem *schema.Schema) *schema.Schema { } func OptionalMap(elem *schema.Schema) *schema.Schema { - return Schema(schema.TypeMap, nil, false, true, false, 0) + return Schema(schema.TypeMap, elem, false, true, false, 0) } func ComputedMap(elem *schema.Schema) *schema.Schema { @@ -156,6 +166,16 @@ func OptionalComputedMap(elem *schema.Schema) *schema.Schema { return Schema(schema.TypeMap, elem, false, true, true, 0) } +// ComplexMap + +func OptionalComplexMap(elem *schema.Schema) *schema.Schema { + return Schema(schema.TypeList, ComplexMapElem(elem), false, true, false, 0) +} + +func ComputedComplexMap(elem *schema.Schema) *schema.Schema { + return Schema(schema.TypeList, ComplexMapElem(elem), false, true, true, 0) +} + // Struct func RequiredStruct(elem *schema.Resource) *schema.Schema { diff --git a/tests/external-policies/cluster.tf b/tests/external-policies/cluster.tf index e418a423..5844e979 100644 --- a/tests/external-policies/cluster.tf +++ b/tests/external-policies/cluster.tf @@ -10,8 +10,9 @@ resource "kops_cluster" "cluster" { allow_container_registry = true } - external_policies = { - node = [ + external_policies { + key = "node" + value = [ "arn:aws:iam::123456789000:policy/test-policy-1", "arn:aws:iam::123456789000:policy/test-policy-2" ]