I am writing a Custom Terraform Provider for Ansible Forms using the Terraform plugin framework (GitHub - hashicorp/terraform-plugin-framework: A next-generation framework for building Terraform providers. v1.8.0). How can I read JSON string in a field with type types.Dynamic
? The JSON string itself contains a map where values types are different.
Here is my DS model:
type JobDataSourceModel struct {
CxProfileName types.String `tfsdk:"cx_profile_name"`
...
Extravars types.Dynamic `tfsdk:"extravars"`
...
}
Here is Schema()
method:
func (d *JobDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
...
"extravars": schema.DynamicAttribute{
MarkdownDescription: "",
Computed: true,
},
...
},
}
}
Read()
method:
func (d *JobDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data JobDataSourceModel
...
data.Extravars = types.DynamicValue(restInfo.Data.Extravars)
...
}