StackGuardian / StackGuardian/terraform-provider-stackguardian
bug: workflow_template_revision create sends driftCron: "" when drift_cron is unset, API returns 400
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 4
- Forks
- 3
- Avg merge
- 3d 9m
- Merged PRs (30d)
- 12
Description
Provider version
1.12.1 (code on main / 1.12.2-rc4 is identical)
Terraform / OpenTofu version
Terraform v1.14.9 on darwin_arm64
Which API region?
EU
Affected resources or data sources
stackguardian_workflow_template_revision (likely also stackguardian_workflow_git and stackguardian_stack_template_revision, which use the same terraform_config conversion)
Terraform configuration
resource "stackguardian_workflow_template" "example" {
template_name = "my-template"
source_config_kind = "TERRAFORM"
is_public = "0"
}
resource "stackguardian_workflow_template_revision" "v1" {
template_id = stackguardian_workflow_template.example.id
source_config_kind = "TERRAFORM"
is_public = "0"
user_job_cpu = 512
user_job_memory = 1024
terraform_config = {
terraform_version = "1.5.7"
}
}
What did you expect to happen?
The revision is created with terraformVersion set and no drift schedule, since drift_cron is optional and was not configured.
What actually happened?
terraform apply fails on create:
Error: failed to create template revision
on main.tf line 35, in resource "stackguardian_workflow_template_revision" "v1":
35: resource "stackguardian_workflow_template_revision" "v1" {
400: {"msg":"TerraformConfig.driftCron: This field may not be blank.","data":{"fieldErrors":{"TerraformConfig.driftCron":["This field may not be blank."]}}}
Root cause: in internal/resource/workflow_template_revision/model.go, ConvertTerraformConfigToAPI decodes the object with
terraformConfigObj.As(ctx, &terraformConfigModel, basetypes.ObjectAsOptions{
UnhandledNullAsEmpty: true,
UnhandledUnknownAsEmpty: true,
})
At create time the Optional+Computed sub-attributes of terraform_config (drift_cron, terraform_plan_options, terraform_init_options, terraform_bin_path, ...) are unknown in the plan, so they are decoded as "". DriftCron: terraformConfigModel.DriftCron.ValueStringPointer() then yields a non-nil pointer to an empty string, and omitempty on *string in sg-sdk-go (TerraformConfig.DriftCron, v1.5.6) does not drop a non-nil pointer. The request therefore carries "driftCron": "", which the API rejects.
Suggested fix: drop UnhandledNullAsEmpty / UnhandledUnknownAsEmpty (or check IsNull() || IsUnknown() per field) so unset string fields stay nil and are omitted from the payload. The same pattern in the other Convert*ToAPI helpers is worth auditing.
Related: #136 (perpetual diff / computed fields becoming unknown on this resource), #135 (import does not set template_id).
Before submitting
- I have removed all credentials and org-identifying values from the above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in internal/resource/workflow_template_revision/model.go at ConvertTerraformConfigToAPI, then compare the terraform_config conversion used by stackguardian_workflow_git and stackguardian_stack_template_revision. Verify that unset Optional+Computed fields remain absent from the create payload, especially driftCron, and that the API accepts the resulting request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, terraform
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100