StackGuardian / StackGuardian/terraform-provider-stackguardian

bug: workflow_template_revision import does not set template_id, forcing replacement on next plan

Open Beginner friendly
#135 0 comments 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 (the ImportState 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

Terraform configuration
resource "stackguardian_workflow_template" "example" {
  id                 = "my-template-abc123"
  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
}

import {
  to = stackguardian_workflow_template_revision.v1
  id = "my-template-abc123:1"
}
What did you expect to happen?

terraform plan shows the revision being imported with no further changes, since the configuration matches the existing revision.

What actually happened?

The import succeeds, but template_id is left null in state. Because template_id is RequiresReplace, the very next plan wants to destroy the imported revision and recreate it:

  # stackguardian_workflow_template_revision.v1 must be replaced
  # (imported from "my-template-abc123:1")
  # Warning: this will destroy the imported resource
-/+ resource "stackguardian_workflow_template_revision" "v1" {
      ...
      + template_id                  = "my-template-abc123" # forces replacement
      ...
    }

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

The same happens with terraform import stackguardian_workflow_template_revision.v1 my-template-abc123:1.

Root cause: ImportState in internal/resource/workflow_template_revision/resource.go only sets id:

func (r *workflowTemplateRevisionResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
	resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...)
}

and Read copies template_id from prior state (revisionModel.TemplateId = state.TemplateId), so it is never populated from the <template-name>:<revision> ID.

Suggested fix: in ImportState, split req.ID on the last : and set template_id to the prefix (and error if there is no :). The same pattern may affect stackguardian_stack_template_revision and stackguardian_workflow_step_template_revision.

Workaround used: import with the CLI, then terraform state pull, set template_id on the revision instance, bump serial, terraform state push. Since Read preserves the state value, the patch persists.

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 in internal/resource/workflow_template_revision/resource.go, focusing on ImportState and the existing Read behavior. Check the related stack_template_revision and workflow_step_template_revision resources for the same pattern. Done means importing an ID such as my-template-abc123:1 populates template_id without a replacement on the next plan, while malformed IDs produce an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
devops, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.