【问题标题】:Terraform 1.1.7 - Error: Backend configuration changedTerraform 1.1.7 - 错误:后端配置已更改
【发布时间】:2022-06-20 23:03:50
【问题描述】:

我在尝试针对 Azure 运行 Terraform v1.1.7 时遇到问题。 这是第一次运行,“工件”后端中没有状态文件。

当我使用 Terraform 0.13 运行时,它会运行,最后,脚本会将状态文件放在 Nexus 中,管道的下一次运行会获取状态文件并使用它,更新它然后放回去到 Nexus。

所以这是在 terraform 0.13 下工作的。 我现在做错了什么?

main.tf:

provider "azurerm" {
  subscription_id = var.credentials.subscription_id
  tenant_id       = var.credentials.tenant_id
  client_id       = var.credentials.client_id
  client_secret   = var.credentials.client_secret
  features {
    key_vault {
      purge_soft_delete_on_destroy = true
    }
  }
}

...

状态保存在 Nexus 中,状态文件如下所示:

terraform {
  backend "artifactory" {
    url      = "https://nexusbox/nexus/repository/"
    repo     = "terraform"
    subpath  = "component/vault"
    username = "theusername"
    password = "somegiberrish"
  }
}


#>/usr/bin/terraform version
Terraform v1.1.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/azurerm v2.99.0
+ provider registry.terraform.io/hashicorp/random v3.1.2

问题:

#> terraform init
Initializing modules...

Initializing the backend...
╷
│ Error: Backend configuration changed
│
│ A change in the backend configuration has been detected, which may require 
 migrating existing state.
│
│ If you wish to attempt automatic migration of the state, use "terraform init - 
 migrate-state".
│ If you wish to store the current configuration with no changes to the state, use 
 "terraform init -reconfigure".
╵

当前工作目录外观:

total 20 
-rw-r--r--. 1 jenkins jenkins 5022 Mar 23 10:14 main.tf 
-rw-r--r--. 1 jenkins jenkins 237  Mar 23 10:43 state.tf
-rw-r--r--. 1 jenkins jenkins 2303 Mar 23 10:43 terraform.tfvars.json
-rw-r--r--. 1 jenkins jenkins 2156 Mar 23 10:14 variables.tf

有什么想法吗?

谢谢。

【问题讨论】:

  • 嗯,后端变了吗?
  • 那里什么都没有。它将在 terraform 完成并且脚本将状态上传到 nexusbox 时。如果您要说的是错误来自没有状态的事实,请您告诉我如何重新编写计划,以便第二次运行 terraform 时,它会知道使用来自的状态文件连结盒?
  • 当前目录下是否有 Terraform 状态文件,如果有,是否为空?
  • 还会创建一个 .terraform 目录,其中还会包含状态文件的详细信息,看看那里是否发生了变化。
  • 我无法在本地复制。尝试使用0.13.6 首先使用artifactory 后端,然后尝试使用1.1.71.1.6 更新状态文件.. 完美运行...

标签: terraform


【解决方案1】:

我也遇到过这个问题。在我的情况下,在我删除存储库本地副本中的所有 .terragrunt-cache 目录并再次运行 terragrunt plan 后,它就消失了。

我正在使用:

$ terragrunt --version
terragrunt version v0.38.0
$ terraform --version
Terraform v1.2.3
on linux_amd64
 + provider registry.terraform.io/hashicorp/azuread v2.20.0
 + provider registry.terraform.io/hashicorp/azurerm v3.3.0

【讨论】:

    猜你喜欢
    • 2019-08-22
    • 2018-11-21
    • 2021-09-26
    • 2021-04-04
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2018-09-16
    • 2021-03-03
    相关资源
    最近更新 更多