Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3 backend causes issue with terraform always thinking backend configuration has changed #51

Closed
paulrobello opened this issue Mar 11, 2024 · 10 comments · Fixed by #52
Closed
Assignees
Labels
bug Something isn't working

Comments

@paulrobello
Copy link

When using tflocal version 1.18.0 with a s3 backend every time i run a terraform command i get
Error: Backend initialization required: please run "terraform init"
Reason: Backend configuration block has changed

running init completes without error but then the very next command has same error.

This issues does not happen with version 0.17.1

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.20.0"
    }
  }
  backend "s3" {
    region  = "us-east-1"
    bucket  = "ls-iac-state-us-east-1"
    key     = "global-iac/project/lcl/terraform.tfstate"
    encrypt = true
  }
}
@lakkeger
Copy link
Contributor

lakkeger commented Mar 11, 2024

Hi @paulrobello,
Thanks for reaching out.
Your backend probably was set up with the now deprecated options of endpoint,iam_endpoint,sts_endpoint,dynamodb_endpoint.
tflocal from version 0.18 is generating the override file with the new options recommended by the Terraform documentation (here).
To be able to use the new version and the backend options you must "reinitialize" your backend with the -migrate-state option and Terraform will automatically migrate the existing statefile. (Or if the statefile can be dropped, you can use the -reconfigure option too.)
Alternatively you can use a terraform version <1.6 with terraform-local and the above mentioned backend options will be used.

Let us know if this has helped to resolve your issue.

@lakkeger lakkeger self-assigned this Mar 11, 2024
@lakkeger lakkeger added the question Further information is requested label Mar 11, 2024
@paulrobello
Copy link
Author

My backend is setup exactly as I pasted above, no endpoints.
I use this before issuing any other commands and this command succeeds but all others say backend changed.

tflocal  init -upgrade -reconfigure

@lakkeger
Copy link
Contributor

lakkeger commented Mar 12, 2024

@paulrobello Can you please provide some information on your environment, as I'm unable to reproduce it?
See screenshot below with your code applied on the following versions:
MacOS 14.4
Terraform 1.5.7 -> 1.7.4 (made a switch from old to new to reproduce the error)
tflocal 0.18.0
Localstack 3.2.0
image
Additionally could you please provide the exact steps, command by command and the configuration of your Localstack instance?

@paulrobello
Copy link
Author

reproducer repo created https://github.com/paulrobello/tflocal_s3_backend_bug

@cabeaulac
Copy link

Reproducer failed for me. Digging into it.

@cabeaulac
Copy link

I see the apply worked. It's the call to output that's failing.

@cabeaulac
Copy link

Ok. I see there's a dependency problem.
If you pip install this https://github.com/localstack-samples/multi-iac-devops/blob/main/devops-tooling/requirements.txt
then the issue goes away.
@lakkeger

@cabeaulac
Copy link

Confirmed. terraform-local==0.17.1 tflocal output command works. terraform-local==0.18.0 does not. See screen shot.

Screenshot 2024-03-13 at 1 04 16 PM

@lakkeger
Copy link
Contributor

This sample was useful @cabeaulac. Found the source of the error. I turned around the logic and I added an env variable to exclude a subcommand from proxying.

@lakkeger lakkeger linked a pull request Mar 13, 2024 that will close this issue
@lakkeger lakkeger added bug Something isn't working and removed question Further information is requested labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants