spacelift-io / terraform-provider-spacelift

Terraform provider to interact with Spacelift
MIT License
70 stars 26 forks source link

Unable to Change Existing Stack workflow from TERRAFORM_FOSS to CUSTOM #547

Open HighwayofLife opened 1 month ago

HighwayofLife commented 1 month ago

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:

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

truszkowski commented 1 month ago

@HighwayofLife Thanks for the report. We had a similar issue with changing the tool for Terragrunt PR. The fix is part of that PR.