Open ChetHosey opened 6 years ago
Unfortunately I don't have a PR at this point, but did put together a demo provider to test these ideas.
Key sections:
def create
@resource.class.parameters.each do |attr|
attr = attr.to_sym
next if attr == :name
@property_hash[attr] = @resource[attr]
end
super
end
def self.prefetch(resources = {})
providers = instances.each_with_object({}) do |instance, hash|
hash[instance.uniqueness_key] = instance
end
catalog = resources.values.first.catalog
catalog_entries = catalog.vertices.select do |resource|
resource.provider.class == self
end
catalog_entries.each do |resource|
resource.provider = providers[resource.uniqueness_key] if providers[resource.uniqueness_key]
end
end
def uniqueness_key
self.class.resource_type.key_attributes.sort_by { |attribute_name| attribute_name.to_s }.map { |attribute_name| send attribute_name }
end
See the linked provider file for comments and attribution.
Composite namevars aren't currently supported, as the current prefetch method only uses the value of the first key_attribute to match providers and catalog entries.
A few changes may be needed to support composite namevars:
Update
create
method so that it also copies parameters. Currently only properties are copied to the provider. Parameters are needed if any are written withinparse_file
.prefetch
would need to use all key attribute values, not just the value of the first namevar.