StackGuardian / StackGuardian/terraform-provider-stackguardian

bug: workflow_template_revision shows perpetual diff when alias is unset (API returns "")

Open
#136 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
4
Forks
3
Avg merge
3d 9m
Merged PRs (30d)
12

Description

Provider version

1.12.1

Terraform / OpenTofu version

Terraform v1.14.9 on darwin_arm64

Which API region?

EU

Affected resources or data sources

stackguardian_workflow_template_revision

Terraform configuration
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"
  }
}

(The revision was imported and template_id patched into state as described in #135. The alias attribute is not set in configuration.)

What did you expect to happen?

terraform plan reports "No changes" for a revision whose configuration matches the API.

What actually happened?

Every plan shows an in-place update. The API returns alias = "" for a revision created without an alias, the config omits it, and the provider diffs "" -> null. That single diff then cascades: all Computed attributes without UseStateForUnknown are marked (known after apply), including id itself:

  ~ resource "stackguardian_workflow_template_revision" "v1" {
      - alias                        = "" -> null
      + deployment_platform_config   = (known after apply)
      + environment_variables        = (known after apply)
      ~ id                           = "my-template-abc123:1" -> (known after apply)
      + number_of_approvals_required = (known after apply)
      + tags                         = (known after apply)
      ~ terraform_config             = {
          + approval_pre_apply          = (known after apply)
          + drift_check                 = (known after apply)
          + drift_cron                  = (known after apply)
          ...
            # (1 unchanged attribute hidden)
        }
      + wf_steps_config              = (known after apply)
        # (11 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Setting alias = "" explicitly in configuration makes the plan clean, which confirms the empty-string vs null mismatch is the trigger.

Suggested fix: normalise empty-string alias (and other optional string fields returned as "") to null when flattening the API response in BuildAPIModelToWorkflowTemplateRevisionModel, or add a plan modifier that treats "" and null as equal. Adding UseStateForUnknown to the computed attributes (id in particular) would also stop an unrelated change from marking the ID as unknown.

Related: while testing, creating a revision with the config above failed with:

400: {"msg":"TerraformConfig.driftCron: This field may not be blank.","data":{"fieldErrors":{"TerraformConfig.driftCron":["This field may not be blank."]}}}

so the provider appears to send driftCron: "" when drift_cron is unset. Happy to open that as a separate issue if preferred.

Before submitting
  • I have removed all credentials and org-identifying values from the above.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at BuildAPIModelToWorkflowTemplateRevisionModel and trace how an unset alias and other optional strings are represented in the API model and Terraform state. Reproduce the reported terraform plan with alias omitted, then verify that an API response containing alias = "" produces no diff or cascading unknown values, including for id.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, terraform
Domain
devops, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.