adding `human_readable_attributes` to JSON output

Related: https://github.com/snyk/driftctl/issues/1325
main
AJ 2022-02-21 13:15:13 +00:00
parent af2268a7a9
commit 353c189005
1 changed files with 15 additions and 6 deletions

View File

@ -101,6 +101,7 @@ type ResourceFactory interface {
type SerializableResource struct {
Id string `json:"id"`
Type string `json:"type"`
ReadableAttributes map[string]string `json:"human_readable_attributes,omitempty"`
Source *SerializableSource `json:"source,omitempty"`
}
@ -116,10 +117,18 @@ func NewSerializableResource(res *Resource) *SerializableResource {
return &SerializableResource{
Id: res.ResourceId(),
Type: res.ResourceType(),
ReadableAttributes: formatReadableAttributes(res),
Source: src,
}
}
func formatReadableAttributes(res *Resource) map[string]string {
if res.Schema() == nil || res.Schema().HumanReadableAttributesFunc == nil {
return map[string]string{}
}
return res.Schema().HumanReadableAttributesFunc(res)
}
type NormalizedResource interface {
NormalizeForState() (Resource, error)
NormalizeForProvider() (Resource, error)