Skip to content

Commit

Permalink
fixing normalized json format
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Kanchwala committed Jul 23, 2020
1 parent cdbd444 commit 5180043
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions pkg/iac-providers/terraform/v12/convert.go
@@ -1,7 +1,7 @@
package tfv12

/*
Following code has been borrowed from:
Following code has been borrowed and modifed from:
https://github.com/tmccombs/hcl2json/blob/5c1402dc2b410e362afee45a3cf15dcb08bc1f2c/convert.go
*/

Expand Down Expand Up @@ -45,10 +45,18 @@ func (c *converter) convertBody(body *hclsyntax.Body) (jsonObj, error) {
}

for _, block := range body.Blocks {
err = c.convertBlock(block, out)
blockOut := make(jsonObj)
err = c.convertBlock(block, blockOut)
if err != nil {
return nil, err
}
if _, present := out[block.Type]; !present {
out[block.Type] = []jsonObj{blockOut}
} else {
list := out[block.Type].([]jsonObj)
list = append(list, blockOut)
out[block.Type] = list
}
}

return out, nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/iac-providers/terraform/v12/resource.go
Expand Up @@ -33,13 +33,14 @@ func CreateResourceConfig(managedResource *hclConfigs.Resource) (resourceConfig

// create a resource config
resourceConfig = output.ResourceConfig{
ID: fmt.Sprintf("%s.%s", managedResource.Type, managedResource.Name),
Name: managedResource.Name,
Type: managedResource.Type,
Source: managedResource.DeclRange.Filename,
Config: goOut,
}

// successful
zap.S().Debugf("successfully created resource config for resource '%s', file: '%s'", resourceConfig.Name, resourceConfig.Source)
zap.S().Debugf("created resource config for resource '%s', file: '%s'", resourceConfig.Name, resourceConfig.Source)
return resourceConfig, nil
}

0 comments on commit 5180043

Please sign in to comment.