Skip to content

Commit

Permalink
generate: remove additional handling of numeric values
Browse files Browse the repository at this point in the history
In previous versions of our schema converter, we needed to handle the scenario
where a key inside of a map would contain a numeric value.

Note: This is only required for `TypeMap`s because it is the wild west and you
lose most of the validation with the Terraform internals when using maps.

```
resource "..." "..." {
  foo = {
    bar1 = "baz"
  }
}
```

While numeric characters in attribute keys are permitted in HCL, they must be
quoted. Inadvertently, it looks like this was also being applied to the
attribute values. While a good measure, this isn't as important as we have
better measures to detect the value type and infer it appropriately.

This commit removes the additional handling and instead relies on the explicit
`.(type)` check instead which covers the key _and_ value.
  • Loading branch information
jacobbednarz committed May 14, 2024
1 parent c3959bc commit 8902e2f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions internal/app/cf-terraforming/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,11 @@ func writeAttrLine(key string, value interface{}, parentName string, body *hclwr

ctyMap := make(map[string]cty.Value)
for _, v := range sortedKeys {
if hasNumber(v) {
ctyMap[fmt.Sprintf("%s", v)] = cty.StringVal(values[v].(string))
} else {
switch val := values[v].(type) {
case string:
ctyMap[v] = cty.StringVal(val)
case float64:
ctyMap[v] = cty.NumberFloatVal(val)
}
switch val := values[v].(type) {
case string:
ctyMap[v] = cty.StringVal(val)
case float64:
ctyMap[v] = cty.NumberFloatVal(val)
}
}
body.SetAttributeValue(key, cty.ObjectVal(ctyMap))
Expand Down

0 comments on commit 8902e2f

Please sign in to comment.