terraform-provider-spacelift icon indicating copy to clipboard operation
terraform-provider-spacelift copied to clipboard

Unable to Change Existing Stack workflow from TERRAFORM_FOSS to CUSTOM

Open HighwayofLife opened this issue 9 months ago • 1 comments

Overview

When attempting to update an existing stack that was created using the TERRAFORM_FOSS workflow tool, we realized that we needed features available only in Terraform v1.7.0+. We implemented a custom runner image and set the terraform_workflow_tool to CUSTOM. However, the subsequent plan and apply resulted in the following error:

Error: could not update stack: stack has 1 error: terraform: specifying version for custom tool workflow is not possible

Expected Behavior

When updating a Spacelift stack to use a custom runner image and setting terraform_workflow_tool to CUSTOM, the provider should allow the stack update without assuming a default Terraform version (1.5.7). Ideally, the provider should accept an empty string or null value for terraform_version to indicate no specific version requirement for the custom workflow tool, or when the terraform_workflow_tool is set to CUSTOM, the terraform_version input could be completely ignored.

Actual Behavior

Stack configuration:

resource "spacelift_stack" "example" {
  name                             = "Spacelift Example Stack"
  runner_image                     = "<redacted>.azurecr.io/spacelift-custom-runner:latest"
  terraform_workflow_tool          = "CUSTOM"
  worker_pool_id                   = "<redacted>"
  terraform_version = ""
...
}

This change is not reflected in the plan as the provider resets the default terraform version to 1.5.7 when no value (empty string or null) is provided to that input.

Plan output:

  ~ resource "spacelift_stack" "example" {
        id                               = "spacelift-example-stack"
        name                             = "Spacelift Example Stack"
      + runner_image                     = "<redacted>.azurecr.io/spacelift-custom-runner:latest"
      ~ terraform_workflow_tool          = "TERRAFORM_FOSS" -> "CUSTOM"
      + worker_pool_id                   = "<redacted>"
        # (30 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Attempting to apply the configuration above results in the following error:

Error: could not update stack: stack has 1 error: terraform: specifying version for custom tool workflow is not possible
│ 
│   with spacelift_stack.admin["spacelift-example-stack"],
│   on main.tf line 34, in resource "spacelift_stack" "example":
│   34: resource "spacelift_stack" "example" {

This error occurs because Spacelift sets a default Terraform version of 1.5.7 when terraform_version is not explicitly specified. Setting terraform_version to an empty string or null is ignored by the provider, leading to the conflict with the custom workflow tool.

Steps to Reproduce:

  1. Create a Spacelift stack with the TERRAFORM_FOSS workflow tool.
  2. Modify the stack configuration to use a custom runner_image and set terraform_workflow_tool to CUSTOM.
  3. Try to apply the updated configuration.

Possible Solutions:

  • Allow the terraform_version attribute to accept an empty string or null value when terraform_workflow_tool is set to CUSTOM, signifying no specific version requirement for the custom tool.
  • Ignore any previously set value of terraform_version when terraform_workflow_tool is set to CUSTOM.
  • Automatically set terraform_version to NULL when terraform_workflow_tool is set to CUSTOM.
  • Implement a mechanism to explicitly specify the Terraform version for custom workflow tools.

Additional Context:

A report on Slack showed that this was reproducible through the UI, although I was able to manually override the terraform_version/terraform_workflow_tool

HighwayofLife avatar May 07 '24 20:05 HighwayofLife