【发布时间】: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.7和1.1.6更新状态文件.. 完美运行...
标签: terraform