Hi Everyone,
I am looking into possible solutions of dynamically generating resources and data-sources based on meta information provided by a product. A template based approach could be a solution to generate the provider, but this would mean for every version of the product the provider needs to be regenerated from templates. Since meta information (json format) is available via the API of the product I am considering generating structs and schemas used for resources and data-sources based on this meta information. There are however a few things blocking me that I would like to discuss and or get your opinion on:
-
Reading plan data into the model, or getting and saving data into Terraform state requires a struct to be passed to the corresponding function. When this struct is generated with the function reflect.StructOf(), values are not mapped correctly and errors are triggered. Executing a type assertion of reflect.Value in the Into() function in
internal/reflect/into.go
and the FromValue() function ininternal/reflect/outof.go
allows for the values to be mapped correctly. Is it a design choice to not allow structs that are created reflect.StructOf()? Would it be a possibility to add type assertion into these functions? -
During my investigation I have temporarily embedded the meta files in the provider, which allowed me to try dynamic struct creation with the reflect.StructOf() function. From a proof of concept point of view this seems to work. Ideally I would now like to request the meta files from the api of the product, thus removing the need of embedding of meta files. In this case I would need the provider configuration details to connect to the api for meta data retrieval. During the creation of the resource functions ( same applies for data sources ) the provider configuration is not available and thus I am unable to retrieve the meta information. Is there a way to access provider configuration during this phase?
Kind regards,