Skip to content

Commit

Permalink
fix incorrect loop exit
Browse files Browse the repository at this point in the history
  • Loading branch information
patilpankaj212 committed Jan 14, 2021
1 parent d2cb1a8 commit c02bd36
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
25 changes: 14 additions & 11 deletions pkg/iac-providers/terraform/v12/cty-converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,25 @@ func ctyToBool(ctyVal cty.Value) (interface{}, error) {
// interfce{}
func ctyToSlice(ctyVal cty.Value) (interface{}, error) {
var val []interface{}
var allErrs error

if strings.Contains(ctyVal.Type().FriendlyName(), "list") {
var allErrs error
if len(ctyVal.AsValueSlice()) > 0 {
for _, v := range ctyVal.AsValueSlice() {
for _, converter := range ctyNativeConverterFuncs {
resolved, err := converter(v)
if err == nil {
val = append(val, resolved)
return val, nil
}
allErrs = errors.Wrap(allErrs, err.Error())
for _, v := range ctyVal.AsValueSlice() {
for _, converter := range ctyNativeConverterFuncs {
resolved, err := converter(v)
if err == nil {
val = append(val, resolved)
break
}
allErrs = errors.Wrap(allErrs, err.Error())
}
}
if allErrs != nil {
return nil, allErrs
}
return val, nil
}
return val, fmt.Errorf("list doesn't contain any elements")
return val, fmt.Errorf("incorrect type")
}

// ctyToMap tries to converts the incoming cty.Value into map[string]cty.Value
Expand Down
51 changes: 26 additions & 25 deletions pkg/iac-providers/terraform/v12/testdata/tfjson/list-vars-test.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
{
"aws_instance": [
{
"id": "aws_instance.app",
"name": "app",
"source": "main.tf",
"line": 5,
"type": "aws_instance",
"config": {
"ami": "${data.aws_ami.amazon_linux.id}",
"count": [
1
],
"instance_type": "blah_instance",
"subnet_id": [
"10.0.0.0/8"
],
"tags": {
"a": "b",
"c": "d"
},
"vpc_security_group_ids": "${var.security_group_ids}"
"aws_instance": [
{
"id": "aws_instance.app",
"name": "app",
"source": "main.tf",
"line": 5,
"type": "aws_instance",
"config": {
"ami": "${data.aws_ami.amazon_linux.id}",
"count": [
1,
2
],
"instance_type": "blah_instance",
"subnet_id": [
"10.0.0.0/8"
],
"tags": {
"a": "b",
"c": "d"
},
"skip_rules": null
}
]
}
"vpc_security_group_ids": "${var.security_group_ids}"
},
"skip_rules": null
}
]
}

0 comments on commit c02bd36

Please sign in to comment.