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

You must define a backend block (it can be empty!) in your Terraform code or your remote state settings will have no effect #1826

Closed
smitthakkar96 opened this issue Sep 27, 2021 · 4 comments · Fixed by #1827
Labels
bug Something isn't working

Comments

@smitthakkar96
Copy link
Contributor

smitthakkar96 commented Sep 27, 2021

Maybe this is a duplicate but I am confused about all answers.

I am using terragrunt version 0.31.0 and terraform 1.0.1. My remote state settings are as follows:

remote_state = {
  backend = "s3"
  generate = {
    path      = "${get_terragrunt_dir()}/backend.tf"
    if_exists = "overwrite"
  }
  config = {
    encrypt = true
    bucket  = local.env_vars.bucket
    key     = "${local.env_vars.remote_state_path_prefix}/${replace(path_relative_to_include(), "../", "")}/terraform.tfstate"
    region  = local.env_vars.region
    profile = local.env_vars.account
  }
}

Above creates backend.tf like below

# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
terraform {
  backend "s3" {
    bucket  = "bucket-name"
    encrypt = true
    key     = "terragrunt/squads/billing/billing-asia-golden-signals/production/terraform.tfstate"
    profile = "aws-profile"
    region  = "eu-central-1"
  }
}

When I run terragrunt run-all plan for the first time it fails with below error:

time=2021-09-27T19:15:29Z level=info msg=Stack at squads/billing/billing-asia-golden-signals/production:
  => Module /apps/squads/billing/billing-asia-golden-signals/production (excluded: false, dependencies: [])
time=2021-09-27T19:15:30Z level=error msg=Module /apps/squads/billing/billing-asia-golden-signals/production has finished with an error: Found remote_state settings in /apps/squads/billing/billing-asia-golden-signals/production/terragrunt.hcl but no backend block in the Terraform code in /apps/squads/billing/billing-asia-golden-signals/production/.terragrunt-cache/jL-ok05zqKOgZxB9eaCJVfscinM/V6_t61o1qpIBPcpuPFw1qQ5n_hg/terraform/modules/golden-signals. You must define a backend block (it can be empty!) in your Terraform code or your remote state settings will have no effect! It should look something like this:

terraform {
  backend "s3" {}
}

 prefix=[/apps/squads/billing/billing-asia-golden-signals/production] 
time=2021-09-27T19:15:30Z level=error msg=1 error occurred:
        * Found remote_state settings in /apps/squads/billing/billing-asia-golden-signals/production/terragrunt.hcl but no backend block in the Terraform code in /apps/squads/billing/billing-asia-golden-signals/production/.terragrunt-cache/jL-ok05zqKOgZxB9eaCJVfscinM/V6_t61o1qpIBPcpuPFw1qQ5n_hg/terraform/modules/golden-signals. You must define a backend block (it can be empty!) in your Terraform code or your remote state settings will have no effect! It should look something like this:

terraform {
  backend "s3" {}
}




time=2021-09-27T19:15:30Z level=error msg=Unable to determine underlying exit code, so Terragrunt will exit with error code 1

In the second attempt everything runs fine I guess it's because backend.tf is present.

I tried digging in code and I don't understand the reason behind https://github.com/gruntwork-io/terragrunt/blob/fed8039a6f08c2816bd18d6377c77b379ccbc345/cli/cli_app.go#L467 this check (is it possible to maybe disable it). I even tried adding empty backend block to my module but when I do that I get below error

Initializing the backend...
bucket
  The name of the S3 bucket

  Enter a value: ╷
│ Error: Error asking for input to configure backend "s3": bucket: EOF
│ 
│ 
╵

╷
│ Error: "region": required field is not set
│ 
│ 
╵

╷
│ Error: "key": required field is not set
│ 
│ 
╵

╷
│ Error: "bucket": required field is not set
│ 
│ 
╵


time=2021-09-27T18:53:51Z level=error msg=1 error occurred:
        * exit status 1


make: *** [plan-all] Error 1

Even tried disable_init flag. Maybe I am doing something wrong or maybe there is a possible fix needed.

@yorinasub17

This comment has been minimized.

@yorinasub17
Copy link
Contributor

Ok this is probably a bug, and a potential fix is at #1827. You can follow that PR to be notified when this is released.

@smitthakkar96
Copy link
Contributor Author

smitthakkar96 commented Sep 27, 2021

Your fix fixes the problem. @yorinasub17 thanks for the prompt response hope it's rolled out soon.

@yorinasub17
Copy link
Contributor

Should be fixed in https://github.com/gruntwork-io/terragrunt/releases/tag/v0.32.5 (binaries should show up shortly, ~15-30 minutes).

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.

2 participants