Skip to content

Commit

Permalink
Fix: Error on non-string values in yaml_list_of_strings - serialize…
Browse files Browse the repository at this point in the history
… them to flow-style YAML

Closes #4
  • Loading branch information
ashald committed Apr 20, 2019
1 parent 4008ab5 commit 4867782
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 2.0.2 - 2019-04-20

### Fixed

- Error on non-string values in `yaml_list_of_strings` - serialize them to flow-style YAML

## 2.0.1 - 2019-04-12

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion yaml/data_source_yaml_list_of_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func dataSourceList() *schema.Resource {
func readYamlList(d *schema.ResourceData, m interface{}) error {
input := d.Get(FieldInput).(string)

var parsed []string
var parsed []interface{}

err := yml.Unmarshal([]byte(input), &parsed)
if err != nil {
Expand Down
26 changes: 22 additions & 4 deletions yaml/data_source_yaml_list_of_strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"reflect"
)

const listInput = `
const inputListOfStrings = `
output "result" { value="${data.yaml_list_of_strings.doc.output}" }
data "yaml_list_of_strings" "doc" {
Expand All @@ -20,17 +20,35 @@ EOF
}
`

const inputListOfMaps = `
output "result" { value="${data.yaml_list_of_strings.doc.output}" }
data "yaml_list_of_strings" "doc" {
input = <<EOF
- foo: 123
- bar: 456
EOF
}
`

func TestListOfStringsDataSource(t *testing.T) {
expected := []string{"foo", "bar"}
expectedListOfStrings := []string{"foo", "bar"}
expectedListOfMaps := []string{"{foo: 123}", "{bar: 456}"}

resource.Test(t, resource.TestCase{
IsUnitTest: true,
Providers: testProviders,
Steps: []resource.TestStep{
{
Config: listInput,
Config: inputListOfStrings,
Check: resource.ComposeTestCheckFunc(
testListOutputEquals("result", expectedListOfStrings),
),
},
{
Config: inputListOfMaps,
Check: resource.ComposeTestCheckFunc(
testListOutputEquals("result", expected),
testListOutputEquals("result", expectedListOfMaps),
),
},
},
Expand Down

0 comments on commit 4867782

Please sign in to comment.