Merge pull request #908 from cloudskiff/better_generic_detail_fetcher
Allow to customize read attributes in detail fetchermain
commit
a8f9b1764e
|
@ -26,9 +26,15 @@ func NewGenericDetailsFetcher(resType resource.ResourceType, provider terraform.
|
|||
}
|
||||
|
||||
func (f *GenericDetailsFetcher) ReadDetails(res resource.Resource) (resource.Resource, error) {
|
||||
attributes := map[string]string{}
|
||||
if res.Schema().ResolveReadAttributesFunc != nil {
|
||||
abstractResource := res.(*resource.AbstractResource)
|
||||
attributes = res.Schema().ResolveReadAttributesFunc(abstractResource)
|
||||
}
|
||||
ctyVal, err := f.reader.ReadResource(terraform.ReadResourceArgs{
|
||||
Ty: f.resType,
|
||||
ID: res.TerraformId(),
|
||||
Ty: f.resType,
|
||||
ID: res.TerraformId(),
|
||||
Attributes: attributes,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, remoteerror.NewResourceScanningError(err, res.TerraformType(), res.TerraformId())
|
||||
|
|
|
@ -20,6 +20,7 @@ type Schema struct {
|
|||
Attributes map[string]AttributeSchema
|
||||
NormalizeFunc func(res *AbstractResource)
|
||||
HumanReadableAttributesFunc func(res *AbstractResource) map[string]string
|
||||
ResolveReadAttributesFunc func(res *AbstractResource) map[string]string
|
||||
}
|
||||
|
||||
func (s *Schema) IsComputedField(path []string) bool {
|
||||
|
@ -43,6 +44,7 @@ type SchemaRepositoryInterface interface {
|
|||
UpdateSchema(typ string, schemasMutators map[string]func(attributeSchema *AttributeSchema))
|
||||
SetNormalizeFunc(typ string, normalizeFunc func(res *AbstractResource))
|
||||
SetHumanReadableAttributesFunc(typ string, humanReadableAttributesFunc func(res *AbstractResource) map[string]string)
|
||||
SetResolveReadAttributesFunc(typ string, resolveReadAttributesFunc func(res *AbstractResource) map[string]string)
|
||||
}
|
||||
|
||||
type SchemaRepository struct {
|
||||
|
@ -134,3 +136,12 @@ func (r *SchemaRepository) SetHumanReadableAttributesFunc(typ string, humanReada
|
|||
}
|
||||
(*metadata).HumanReadableAttributesFunc = humanReadableAttributesFunc
|
||||
}
|
||||
|
||||
func (r *SchemaRepository) SetResolveReadAttributesFunc(typ string, resolveReadAttributesFunc func(res *AbstractResource) map[string]string) {
|
||||
metadata, exist := r.GetSchema(typ)
|
||||
if !exist {
|
||||
logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to add read resource attributes, no schema found")
|
||||
return
|
||||
}
|
||||
(*metadata).ResolveReadAttributesFunc = resolveReadAttributesFunc
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue