terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Reconfigure required when switching directories

Open dsfrederic opened this issue 1 year ago • 1 comments

Terraform Version

Terraform v1.2.5
on linux_amd64
+ provider registry.terraform.io/azure/azapi v1.0.0
+ provider registry.terraform.io/databricks/databricks v1.6.1
+ provider registry.terraform.io/hashicorp/azuread v2.29.0
+ provider registry.terraform.io/hashicorp/azurerm v3.22.0

Your version of Terraform is out of date! The latest version
is 1.3.3. You can update by downloading from https://www.terraform.io/downloads.html

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.22.0"
    }

    databricks = {
      source  = "databricks/databricks"
      version = "~>1.6.0"
    }

    azuread = {
      source  = "hashicorp/azuread"
      version = "> 2.15.0"
    }
  }

  backend "azurerm" {
    resource_group_name  = "**************"
    storage_account_name = "**************"
    container_name       = "**************"
    key                  = "**************"
    subscription_id      = "**************"
  }
}

Debug Output

2022-10-27T12:01:14.436Z [INFO]  Terraform version: 1.2.5
2022-10-27T12:01:14.436Z [DEBUG] using github.com/hashicorp/go-tfe v1.0.0
2022-10-27T12:01:14.436Z [DEBUG] using github.com/hashicorp/hcl/v2 v2.12.0
2022-10-27T12:01:14.436Z [DEBUG] using github.com/hashicorp/terraform-config-inspect v0.0.0-20210209133302-4fd17a0faac2
2022-10-27T12:01:14.436Z [DEBUG] using github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
2022-10-27T12:01:14.436Z [DEBUG] using github.com/zclconf/go-cty v1.10.0
2022-10-27T12:01:14.436Z [INFO]  Go runtime version: go1.18.1
2022-10-27T12:01:14.436Z [INFO]  CLI args: []string{"terraform", "apply", "--var-file", "../../root.tfvars"}
2022-10-27T12:01:14.436Z [TRACE] Stdout is a terminal of width 119
2022-10-27T12:01:14.436Z [TRACE] Stderr is a terminal of width 119
2022-10-27T12:01:14.436Z [TRACE] Stdin is a terminal
2022-10-27T12:01:14.436Z [DEBUG] Attempting to open CLI config file: /home/vscode/.terraformrc
2022-10-27T12:01:14.436Z [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2022-10-27T12:01:14.436Z [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2022-10-27T12:01:14.436Z [DEBUG] ignoring non-existing provider search directory /home/vscode/.terraform.d/plugins
2022-10-27T12:01:14.436Z [DEBUG] ignoring non-existing provider search directory /home/vscode/.local/share/terraform/plugins
2022-10-27T12:01:14.436Z [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2022-10-27T12:01:14.436Z [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2022-10-27T12:01:14.437Z [INFO]  CLI command args: []string{"apply", "--var-file", "../../root.tfvars"}
2022-10-27T12:01:14.446Z [TRACE] Meta.Backend: built configuration for "azurerm" backend with hash value 485025875
2022-10-27T12:01:14.446Z [TRACE] Preserving existing state lineage "f6c5aba6-f7e6-d215-3de0-361d1eb40609"
2022-10-27T12:01:14.446Z [TRACE] Preserving existing state lineage "f6c5aba6-f7e6-d215-3de0-361d1eb40609"
2022-10-27T12:01:14.446Z [TRACE] Meta.Backend: working directory was previously initialized for "azurerm" backend
2022-10-27T12:01:14.447Z [TRACE] backendConfigNeedsMigration: configuration values have changed, so migration is required
2022-10-27T12:01:14.447Z [TRACE] Meta.Backend: backend configuration has changed (from type "azurerm" to type "azurerm")
╷
│ Error: Backend initialization required: please run "terraform init"
│ 
│ Reason: Backend configuration block has changed
│ 
│ 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 set up the new configuration, copy existing state, etc. Please run
│ "terraform init" with either the "-reconfigure" or "-migrate-state" flags to
│ use the current configuration.
│ 
│ 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.
╵

Especially this line i find strange: 2022-10-27T12:01:14.447Z [TRACE] Meta.Backend: backend configuration has changed (from type "azurerm" to type "azurerm")

Expected Behavior

I did not expect the requirement to add the -reconfigure flag because my configuration did not change.

Actual Behavior

Error: Backend initialization required

Steps to Reproduce

  1. cd DIR1
  2. Terraform init
  3. Terraform apply
  4. cd DIR2
  5. Terraform init
  6. cd DIR1
  7. terraform init

This init requires the -reconfigure flag while the configuration did not change.

Additional Context

No response

References

No response

dsfrederic avatar Oct 27 '22 12:10 dsfrederic

HI @dsfrederic,

Thanks for filing the issue. I'm not able to replicate the problem from the given information. Were there any -backend-config parameters given during the first init? Have you by chance set TF_DATA_DIR in your environment?

Thanks!

jbardin avatar Oct 27 '22 13:10 jbardin

@jbardin

I do not make use of the -backend-config params.

It seems like $TF_DATA_DIR is set. What's the impact of this?

> echo $TF_DATA_DIR               
/home/vscode/.terraform.cache

dsfrederic avatar Nov 02 '22 08:11 dsfrederic

TF_DATA_DIR tells terraform where to store per-working-directory data. If you change working directories then and run init, you are overwriting the data stored in TF_DATA_DIR, and will need to repeat the process again next time working the working directory changes. If you are not using shared backend config for all working directories, I would suggest not setting that environment variable.

Thanks!

jbardin avatar Nov 02 '22 17:11 jbardin

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Dec 03 '22 02:12 github-actions[bot]