From b217624d83cad75fd7a9eae770ef744b685fdb42 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 22 Feb 2019 16:52:11 -0800 Subject: [PATCH] config/configupgrade: Test to show that list unwrapping works for sets This was already working but we had no tests to prove it. --- configs/configschema/decoder_spec.go | 14 +++++++++----- .../valid/redundant-list/input/redundant-list.tf | 12 ++++++++++++ .../valid/redundant-list/want/redundant-list.tf | 12 ++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/configs/configschema/decoder_spec.go b/configs/configschema/decoder_spec.go index 4b431e073..f77026445 100644 --- a/configs/configschema/decoder_spec.go +++ b/configs/configschema/decoder_spec.go @@ -19,11 +19,7 @@ func (b *Block) DecoderSpec() hcldec.Spec { } for name, attrS := range b.Attributes { - ret[name] = &hcldec.AttrSpec{ - Name: name, - Type: attrS.Type, - Required: attrS.Required, - } + ret[name] = attrS.decoderSpec(name) } for name, blockS := range b.BlockTypes { @@ -103,3 +99,11 @@ func (b *Block) DecoderSpec() hcldec.Spec { return ret } + +func (a *Attribute) decoderSpec(name string) hcldec.Spec { + return &hcldec.AttrSpec{ + Name: name, + Type: a.Type, + Required: a.Required, + } +} diff --git a/configs/configupgrade/test-fixtures/valid/redundant-list/input/redundant-list.tf b/configs/configupgrade/test-fixtures/valid/redundant-list/input/redundant-list.tf index 35e30466d..670c9569d 100644 --- a/configs/configupgrade/test-fixtures/valid/redundant-list/input/redundant-list.tf +++ b/configs/configupgrade/test-fixtures/valid/redundant-list/input/redundant-list.tf @@ -22,6 +22,18 @@ resource "test_instance" "bad4" { security_groups = ["${list("a", "b", "c")}"] } +resource "test_instance" "bad5" { + security_groups = ["${test_instance.bad1.subnet_ids}"] # this one references a set +} + +resource "test_instance" "bad6" { + subnet_ids = ["${test_instance.bad1.security_groups}"] # this one defines a set +} + +resource "test_instance" "bad7" { + subnet_ids = ["${test_instance.bad1.*.id}"] # this one defines a set +} + # The rest of these should keep the same amount of list-ness resource "test_instance" "ok1" { diff --git a/configs/configupgrade/test-fixtures/valid/redundant-list/want/redundant-list.tf b/configs/configupgrade/test-fixtures/valid/redundant-list/want/redundant-list.tf index 34724b978..fd974b98d 100644 --- a/configs/configupgrade/test-fixtures/valid/redundant-list/want/redundant-list.tf +++ b/configs/configupgrade/test-fixtures/valid/redundant-list/want/redundant-list.tf @@ -30,6 +30,18 @@ resource "test_instance" "bad4" { security_groups = ["a", "b", "c"] } +resource "test_instance" "bad5" { + security_groups = test_instance.bad1.subnet_ids # this one references a set +} + +resource "test_instance" "bad6" { + subnet_ids = test_instance.bad1.security_groups # this one defines a set +} + +resource "test_instance" "bad7" { + subnet_ids = test_instance.bad1.*.id # this one defines a set +} + # The rest of these should keep the same amount of list-ness resource "test_instance" "ok1" {