【发布时间】:2016-11-24 07:49:51
【问题描述】:
我之前使用过 terraform,其中 terraform 可以将 tfstate 文件放在 S3 中。 terraform 是否也支持 azure blob 存储作为后端?将后端设置为 azure blob 存储的命令是什么?
【问题讨论】:
我之前使用过 terraform,其中 terraform 可以将 tfstate 文件放在 S3 中。 terraform 是否也支持 azure blob 存储作为后端?将后端设置为 azure blob 存储的命令是什么?
【问题讨论】:
截至Terraform 0.7(当前尚未发布,但您可以从源代码编译)对 Azure blob 存储的支持已达到added。
【讨论】:
这个问题需要一些命令,所以我添加了更多细节以防有人需要。我正在使用 Terraform v0.12.24 和 azurerm 提供程序 v2.6.0。你需要两件事:
至于第二点,main.tf 中的 terraform 块应该包含一个“azurerm”后端:
terraform {
required_version = "=0.12.24"
backend "azurerm" {
storage_account_name = "abcd1234"
container_name = "tfstatecontainer"
key = "example.prod.terraform.tfstate"
}
provider "azurerm" {
version = "=2.6.0"
features {}
subscription_id = var.subscription_id
}
在调用计划或应用之前,使用 bash 导出初始化 ARM_ACCESS_KEY 变量:
export ARM_ACCESS_KEY=<storage access key>
最后,运行init命令:
terraform init
现在,如果您运行 terraform plan,您将看到在容器中创建的 tfstate。 Azure 内置了文件锁定功能,以防有人同时尝试更新状态文件。
【讨论】: