Open singhujjwal opened 5 years ago
I am following the documentation present here for various modules https://github.com/gruntwork-io/terragrunt#interpolation-syntax
The easiest way to reproduce the problem
terragrunt init -reconfigure -backend-config="workspace_key_prefix=ujjwal
terragrunt workspace new ujjwal
terragrunt apply
This throws an error saying
Backend config has changed from map[region:us-east-1 workspace_key_prefix:ujjwal bucket:distplat-phoenix-live dynamodb_table:df04-phoenix-live encrypt:%!s(bool=true) key:vpc-main/terraform.tfstate] to map[bucket:distplat-phoenix-live key:vpc-main/terraform.tfstate region:us-east-1 encrypt:%!s(bool=true) dynamodb_table:df04-phoenix-live]
Terraform has detected that the configuration specified for the backend
has changed. Terraform will now check for existing state in the backends.
When I say yes to the prompt, i see in s3 there is a folder created with name "env:" and all the .tfstate file is present there.
My terraform.tfvars in the root directory has the below contents
terragrunt = {
remote_state {
backend = "s3"
config {
bucket = "xxxxxxx"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "yyyyyy"
s3_bucket_tags {
owner = "Ujjwal Singh"
name = "Terraform state storage"
}
dynamodb_table_tags {
owner = "Ujjwal"
name = "Terraform lock for vpc"
}
}
}
}
Any help is much appreciated.
Thanks for filing the issue and the detailed repro steps. This is the key hint as to what is happening:
Backend config has changed from map[region:us-east-1 workspace_key_prefix:ujjwal bucket:distplat-phoenix-live dynamodb_table:df04-phoenix-live encrypt:%!s(bool=true) key:vpc-main/terraform.tfstate] to map[bucket:distplat-phoenix-live key:vpc-main/terraform.tfstate region:us-east-1 encrypt:%!s(bool=true) dynamodb_table:df04-phoenix-live]
Terraform has detected that the configuration specified for the backend
has changed. Terraform will now check for existing state in the backends.
Using Terraform workspaces is modifying the config to contain a workspace_key_prefix
, which Terragrunt is not handling correctly, and assumes is a diff. We've not caught this before as Terragrunt is typically used as an alternative to Terraform workspaces. A PR to fix the config check in Terragrunt to ignore workspace_key_prefix
is very welcome.
Thanks for taking a look at this.
Hi, I am trying to use s3 as backend for terragrunt to use and it seems after the
terragrunt init
theterragrunt apply
is missing a key in the map to identify the backend and reports thatBackend has changed
and creates another backendIt seems the
workspace_key_prefix:distplat-live-df04-phoenix
this getting lost by the terragrunt apply/plan commands. Also in s3 instead of using the workspace_prefix value it gets set toenv:
as LockID string in dynamoDB tabledistplat-phoenix-live/env:/distplat-live-df04-phoenix/vpc-main/terraform.tfstate-md5
Please let me know if i am doing anything wrong here. Thanks