I’m using the terraform plugin framework.
I have this (simplified) resource schema:
type Thing struct{}
func (t *Thing) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"organization_id": schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"cluster_id": schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
},
}
I’ve implemented resource.ResourceWithValidateConfig.
Here is ValidateConfig()
. Please note I’m just showing the debug code. I really do need to validate multiple attributes on the resource.
func (t *Thing) ValidateConfig(
ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse,
) {
fmt.Println("###DEBUG### ValidateConfig")
var config ThingModel
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
}
if config.OrganizationId.IsUnknown() {
fmt.Println("###DEBUG### config.OrganizationId is unknown")
}
When I run terraform plan
I see this output:
TF_LOG=WARN terraform plan
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│ - repo/repo in ~/bin
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
2024-09-25T11:36:49.401-0700 [WARN] unexpected data: registry.terraform.io/blah/provider:stdout="###DEBUG### ValidateConfig"
2024-09-25T11:36:49.402-0700 [WARN] unexpected data: registry.terraform.io/blah/provider:stdout="###DEBUG### config.OrganizationId is unknown"
In my terraform script I do have organization_id
configured (otherwise I would get Missing required argument
error).
Why is config.OrganizationId
unknown in ValidateConfig
?