Terraspace .terraform.lock.hcl handling issue

Changing required privider version (e.g. downgrading aws = 3.57.0 to 3.52.0 but also upgrading version) return this error running terraspace:

Error: Provider requirements cannot be satisfied by locked dependencies

The following required providers are not installed:

- registry.terraform.io/hashicorp/aws (3.52.0)

Terraform reinitialization required detected. Will run `terraform init` and try again.
=> terraform init -get -input=false >> /tmp/terraspace/log/init/...log

Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider hashicorp/aws:
locked provider registry.terraform.io/hashicorp/aws 3.57.0 does not match
Terraform reinitialization required detected. Will run `terraform init` and try again.
=> terraform init -get -input=false >> /tmp/terraspace/log/init/...log

We cannot remove this error also removing .terraform.lock.hcl form terraspace cache stack directory or using:

terraspace clean all

As terraspace save somewhere lock file provider information and reuse on next run.
The only workaround we found was this:

cd .terraspace-cache/{region}/{env}/stacks/{stack_name}/
vim terraform.tf  -> set as versioni in terraform.tf you need (normally that on code in git)
terraform init -upgrade
rm -rf .terraform/

How can terraspace reintroduce error after terraspace clean all ?
There is a planning to support “-upgrade” for terraspace to avoid manual changes ?

Thank you

I found a repeatable test case:

Note: at test time latest aws provider version was 3.57.0

1. vi app/stacks/project1/config/terraform/terraform.tf
terraform {
  ...
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "3.52.0"
    }
  }
}

2. terraspace clean all --yes
3. terraform init project1

you’ll get error

It seems that terraspace run terraform init before compying terraform.tf with required_providers so terraform init download 3.57.0 and creates lock file with this aws provider version introducing issue of incompatible versione in subsequent init.

terraspace seems to parse every stacks linked by dependencies. I use dependency so I do not know if such issue is related to that.

I encountered the same issue today and used the workaround config/args/terraform.rb

command("init",
  args: ["-upgrade"],
)

Thank you @nickkadams, useful workaround waiting for terraform param. Not always -upgrade is needed.

Update: Released terraspace 1.0.0. It supports passing in -upgrade as a terraspace CLI option. Related PR: https://github.com/boltops-tools/terraspace/pull/172

Thank you. Much better to be able to decide when to use --upgrade