I am making custom terraform provider, there is a optional input for the labels, but what I find the challenge is that strings use .ValueString() to retrieve the values from main.tf, uncertain what to use for types.MapType.
Here is the code:
type ResourceModel struct {
InstanceName types.String `tfsdk:"instance_name"`
Id types.String `tfsdk:"id"`
Labels types.MapType `tfsdk:"labels"`
}
func (r *vmResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"instance_name": schema.StringAttribute{
Required: true,
},
"id": schema.StringAttribute{
Required: true,
},
"labels":schema.MapAttribute{
Optional: true,
},
},
}
}
var plan ResourceModel
diags := req.Plan.Get(ctx, &plan)
if resp.Diagnostics.HasError() {
return
}
request := VmCreate{
InstanceName: plan.InstanceName.ValueString(),
Id: plan.Id.ValueString(),
Labels: plan.Labels.????
}
Tried to find the solution but all i tried failed.