【发布时间】:2021-07-22 08:09:59
【问题描述】:
我正在尝试在 Azure 上设置一个简单的 Terraform 后端。我能写,但似乎阅读并没有真正起作用。例如,我尝试添加一个名为test_a 的azurerm_resource_group,然后添加terraform init 和terraform apply,它已正确存储在Azure 上的存储桶中。
我修改了我的代码并将我的资源名称更改为 test_b 然后 terraform init 和 terraform apply 和 terraform 销毁了我的 test_a 并添加了我的 test_b 资源。 “Apply complete! Resources: 1 added, 0 changed, 1 destroyed.”。可能是什么问题?我可以看到,每当我运行我的terraform init 命令时,它仍然会生成一个.terraform 文件夹,里面有一个terraform.tfstate。
main.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>2.0"
}
azuread = {
source = "hashicorp/azuread"
version = "~>1.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test_a" {
name = "testing-resources"
location = "West Europe"
}
backend_config.tf
terraform {
required_version = ">= 0.12.6"
backend "azurerm" {
subscription_id = "a095c3dd-xxx"
resource_group_name = "terraform"
storage_account_name = "terraform963"
container_name = "tfstate"
key = "terraform.tfstate"
}
}
terraform.tfstate(存储在 Azure 中)
{
"version": 4,
"terraform_version": "0.14.3",
"serial": 4,
"lineage": "1fcb0f9a-7c26-xxx",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "azurerm_resource_group",
"name": "test_b",
"provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "/subscriptions/a095c3dd-xxx/resourceGroups/testing-resources",
"location": "westeurope",
"name": "testing-resources",
"tags": null,
"timeouts": null
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczxxx="
}
]
}
]
}
【问题讨论】:
标签: azure terraform terraform-provider-azure