gpt4 book ai didi

Terraform: "Variables may not be used here"在 terraform init 期间

转载 作者:行者123 更新时间:2023-12-04 03:42:07 24 4
gpt4 key购买 nike

我正在使用 Terraform 雪花插件。我想用${terraform.workspace} terraform 中的变量范围。

terraform {
required_providers {
snowflake = {
source = "chanzuckerberg/snowflake"
version = "0.20.0"
}
}
backend "s3" {
bucket = "data-pf-terraform-backend-${terraform.workspace}"
key = "backend/singlife/landing"
region = "ap-southeast-1"
dynamodb_table = "data-pf-snowflake-terraform-state-lock-${terraform.workspace}"
}
}
但我收到了这个错误。变量在此范围内不可用?
Error: Variables not allowed

on provider.tf line 9, in terraform:
9: bucket = "data-pf-terraform-backend-${terraform.workspace}"

Variables may not be used here.


Error: Variables not allowed

on provider.tf line 12, in terraform:
12: dynamodb_table = "data-pf-snowflake-terraform-state-lock-${terraform.workspace}"

Variables may not be used here.

最佳答案

terraform backend docs状态:

A backend block cannot refer to named values (like input variables, locals, or data source attributes).


然而, s3 backend docs向您展示如何根据当前工作区对一些 s3 存储进行分区,以便每个工作区都有自己独立的状态文件。您不能为每个工作区指定一个不同的存储桶。您只能为所有工作区指定一个存储桶,但 s3 后端会添加 workspace prefix to the path :

When using a non-default workspace, the state path will be /workspace_key_prefix/workspace_name/key (see also the workspace_key_prefix configuration).


一张发电机 table 足以满足所有工作空间的需求。所以只需使用:
  backend "s3" {
bucket = "data-pf-terraform-backend"
key = "terraform.tfstate"
region = "ap-southeast-1"
dynamodb_table = "data-pf-snowflake-terraform-state-lock"
}
并在部署前适当切换工作区。

关于Terraform: "Variables may not be used here"在 terraform init 期间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65838989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com