如何引用terraform模块块中的对象变量列表
Variables.tf
variable "list_views_datasets" {
description = "List of Views in the Datasets"
type = list(object({
dataset_id = string
dataset_name = string
views = list(object({
view_id = string,
query = string,
use_legacy_sql = bool,
labels = map(string),
}))
}))
default = []
}tfvars:
list_views_datasets = [
{
dataset_id = "testservice"
dataset_name = "testservice"
views = [
{
view_id = "issue-data",
use_legacy_sql = false,
query = ".test.sql"
# unfortunately we have to repeat the project id, dataset id and table id in here.
labels = {
env = "dev"
billable = "true"
owner = "dev"
}
},
]
},Main.tf
module "bigquery_views" {
source = "terraform-google-modules/bigquery/google"
version = "4.3.0"
depends_on = [module.bigquery]
for_each = { for list_view in var.list_views_datasets : list_view.dataset_id => list_view }
dataset_id = each.value.dataset_id
dataset_name = each.value.dataset_name
description = var.views_description
project_id = var.project_id
location = var.location
views = {
view_id = each.value.views[view_id]
labels = each.value.views[labels]
query = file(each.value.views[query])
use_legacy_sql = each.value.views[use_legacy_sql]
}
dataset_labels = var.dataset_labels
access = [
{
role = "roles/bigquery.dataOwner"
special_group = "projectOwners"
}
]
}现在我计划引用模块块中的变量,但我不确定我是否在mobule块
中相应地引用了视图、查询、标签值。
发布于 2021-05-26 00:16:01
遗憾的是,你不能这样做,。您必须将整个list_views_datasets作为一个变量传递到模块中,或者在模块级别使用for_each。在第二种情况下,您将创建多个模块。
https://stackoverflow.com/questions/67687214
复制相似问题