mercari / hcledit

Go package to edit HCL configuration
MIT License
45 stars 15 forks source link

[improvement] readvalue is restricted to only primitive or a list of primitive types #134

Open piggybankwang opened 3 weeks ago

piggybankwang commented 3 weeks ago

Hi we realize this function https://github.com/mercari/hcledit/blob/main/internal/converter/converter.go can only return primitive and list of primitive types we'd like to help contribute to read values like map of map, list of map so we can handle READ more complex field

i.e.

if ctyVal.IsNull() {
        return nil, nil
    } else if ctyVal.IsMapType() || ctyVal.IsObjectType() {
        return GetAttributeMapValues(ctyVal)
    } else if ctyVal.IsListType() || ctyVal.IsTupleType() {
        return GetAttributeSliceValues(ctyVal.AsValueSlice())
    } else if ctyVal.IsSetType() {
        return GetAttributeSliceValues(ctyVal.AsValueSet().Values())
    } else if ctyVal.IsPrimitiveType() {
        switch ctyVal {
        case cty.Bool:
            return ctyVal.True() == true, nil
        case cty.String:
            return ctyVal.AsString(), nil
        case cty.Number:
            return GetAttributeNumValue(ctyVal), nil
        }
    }