Skip to content

Commit

Permalink
1. fix panic for list variable with no type definition in terraform c…
Browse files Browse the repository at this point in the history
…onfig (#654)

2. add tests for cty-converters
  • Loading branch information
patilpankaj212 authored Apr 13, 2021
1 parent 1d1addf commit 5abf9af
Show file tree
Hide file tree
Showing 2 changed files with 510 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/iac-providers/terraform/commons/cty-converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ctyToSlice(ctyVal cty.Value) (interface{}, error) {
var val []interface{}
var allErrs error

if ctyVal.Type().IsListType() {
if ctyVal.Type().IsListType() || ctyVal.Type().IsTupleType() || ctyVal.Type().IsSetType() {
for _, v := range ctyVal.AsValueSlice() {
for _, converter := range ctyNativeConverterFuncs {
resolved, err := converter(v)
Expand All @@ -88,6 +88,10 @@ func ctyToSlice(ctyVal cty.Value) (interface{}, error) {
// native golang value and create a new map[string]interface{}
func ctyToMap(ctyVal cty.Value) (interface{}, error) {

if !(ctyVal.Type().IsMapType() || ctyVal.Type().IsObjectType()) {
return nil, fmt.Errorf("not map type")
}

var (
ctyValMap = ctyVal.AsValueMap() // map[string]cty.Value
val = make(map[string]interface{})
Expand Down
Loading

0 comments on commit 5abf9af

Please sign in to comment.