terragrunt: Terragrunt does not create local backend

We are using Terragrunt to create the infrastructure for an AWS service. Our setup scripts allow us to configure a remote S3 backend or just use a local one (for instance, to do a quick test that is not supposed to be shared with other developers).

While everything works fine when we use the S3 backend, Terragrunt seems not to be capable of initializing the local backend.

We are using Terraform 0.9.8 and Terragrunt 0.12.20.

main.tf contains the following configuration section for the backend:

terraform {
  backend "local" {}
}

And terraform.tfvars just contains:

terragrunt = {
}

When running

terragrunt init
terragrunt get
terragrunt plan

the following error is obtained:

[terragrunt] [SomePath\terraform] 2017/06/13 11:11:01 Running command: terraform --version
[terragrunt] 2017/06/13 11:11:01 Reading Terragrunt config file at SomePath/terraform/terraform.tfvars
[terragrunt] 2017/06/13 11:11:01 Running 'init' manually is not necessary: Terragrunt will call it automatically when needed before running other Terraform commands
[terragrunt] [SomePath\terraform] 2017/06/13 11:11:01 Running command: terraform --version
[terragrunt] 2017/06/13 11:11:01 Reading Terragrunt config file at SomePath/terraform/terraform.tfvars
[terragrunt] 2017/06/13 11:11:01 Running command: terraform get
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: git::https://SomeUrl/scm/ct/terraformmodules.git?ref=v0.0.6
Get: file://SomePath/terraform/.terraform/modules/13a6f4a5ee3a99f75f6182d39132639f/modules/n_list
Get: file://SomePath/terraform/.terraform/modules/fbeb1acb7f91b66962a4d6b122b47dce/modules/n_list
Get: file://SomePath/terraform/.terraform/modules/52edc4f80b92e0ca511331074ba5648a/modules/n_list
Get: file://SomePath/terraform/.terraform/modules/d8d44e535eee15bb64a069f15f76dceb/modules/n_list
Get: file://SomePath/terraform/.terraform/modules/0295f53ae0c7fa1e039102d1173dd61d/modules/n_list
[terragrunt] [SomePath\terraform] 2017/06/13 11:11:02 Running command: terraform --version
[terragrunt] 2017/06/13 11:11:02 Reading Terragrunt config file at SomePath/terraform/terraform.tfvars
[terragrunt] 2017/06/13 11:11:02 Running command: terraform plan
Backend reinitialization required. Please run "terraform init".
Reason: Initial configuration of the requested backend "local"

The "backend" is the interface that Terraform uses to store state,
perform operations, etc. If this message is showing up, it means that the
Terraform configuration you're using is using a custom configuration for
the Terraform backend.

Changes to backend configurations require reinitialization. This allows
Terraform to setup the new configuration, copy existing state, etc. This is
only done during "terraform init". Please run that command now then try again.

If the change reason above is incorrect, please verify your configuration
hasn't changed and try again. At this point, no changes to your existing
configuration or state have been made.

Failed to load backend: Initialization required. Please see the error message above.
[terragrunt] 2017/06/13 11:11:03 exit status 1

Is this a bug, or are we not configuring the local backend properly?

The error occurs when cloning a fresh copy of the repository (i.e., no .terraform directory is present).

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 26 (13 by maintainers)

Most upvoted comments

Ah, I think the issue is that Terragrunt doesn’t try to configure a backend unless you have a remote_state block defined. See if defining an empty block does the trick:

terragrunt = {
  remote_state {
    backend = "local"
    config {}
  }
}

Related: #2179

remote_state works too

remote_state {
  backend = "local"
  config = {
    path = "${get_parent_terragrunt_dir()}/${path_relative_to_include()}/terraform.tfstate"
  }

  generate = {
    path = "backend.tf"
    if_exists = "overwrite"
  }
}

IMO this (local backends) should be documented.

Note: I linked to this issue in a SO answer.

Interested in this as well with the same use-case as @john-mcgowan-wowza

As we do our initial development, I want to specify backend "local" {} but transition to "s3" in live; having to touch my module repositories to do that feels very wrong.

This is blocking me from using terragrunt. My infrastructure modules shouldn’t be hard-linked to a specific backend type. Some live infrastructure scenarios will need remote and some will need local. (e.g. We shouldn’t be spinning S3 buckets for each person’s local minikube cluster).

Looking for workarounds.

Using latest v0.13.2 terragrunt and terraform v0.10.4
terragrunt will not init/create the local backend in the specified path.

remote_state { backend = "local" config { path = "/somelocalpath/remote-state/na4-perfstage1" } }

Pretty much no matter what I do I can’t get the local file to exist. I’ve looked for terraform issues around this - and didn’t see any, however, I think it’s a terraform problem, as I see the command [terragrunt] 2017/09/08 18:01:55 Running command: terraform init -backend-config=path=mypath/blah