【发布时间】:2021-06-08 12:29:23
【问题描述】:
我有包含以下内容的 lookups.tf 文件
locals {
roles_mapping = {
web = "we"
app = "as"
db = "db"
queue = "qu"
stream = "st"
}
environment_lookup = {
dev = "d"
test = "t"
int = "i"
prod = "p"
prd = "p"
uat = "a"
poc = "d"
dr = "r"
lab = "l"
}
region_lookup = {
"Australia East" = "aae"
"Australia Southeast" = "aas"
}
region_pairs = {
"Australia East" = "Australia Southeast"
"Australia Southeast" = "Australia East"
}
lookup_result = lookup(var.environment_lookup, var.environment)
tags = merge(
data.azurerm_resource_group.tf-azrg.tags, {
Directory = "bento.com",
PrivateDNSZone = var.private_dns_zone,
Immutable = "False",
ManagedOS = "True",
}
)
}
data "azurerm_log_analytics_workspace" "log_analytics" {
name = "abc-az-lad1"
resource_group_name = "abc-dev-aae"
}
现在,我有一个名为 variables.tf
的文件variable "environment" {
description = "The name of environment for the AKS Cluster"
type = string
default = "dev"
}
variable "identifier" {
description = "The identifier for the AKS Cluster"
type = number
default = 001
}
现在,我想在 main.tf 中引用 lookups.tf 和 variable.tf 的名称,如下所示
resource "azurerm_log_analytics_workspace" "tf-alaw" {
name = var.tla-la-local.lookup_result-var.identifier
location = data.azurerm_resource_group.tf-azrg.location
resource_group_name = data.azurerm_resource_group.tf-azrg.name
sku = var.la_sku
retention_in_days = 30
}
但是,我收到如下错误:
Error: Reference to the undeclared input variable
on ..\..\..\terraform-azurerm-aks\lookups.tf line 32, in locals:
32: lookup_result = lookup(var.environment_lookup, var.environment)
An input variable with the name "environment_lookup" has not been declared.
This variable can be declared with a variable "environment_lookup" {} block.
Error: Reference to the undeclared input variable
on ..\..\..\terraform-azurerm-aks\main.tf line 2, in resource "azurerm_log_analytics_workspace" "tf-alaw":
2: name = var.tla-la-local.lookup_result-var.identifier
An input variable with the name "tla-la-local" has not been declared. This
variable can be declared with a variable "tla-la-local" {} block.
请注意下面的名称,我期望 var.tla 指的是一个变量,然后是字符串/文本 -la- 现在 local.lookup_result 是来自本地的值,然后是文本 - 最后引用另一个变量 var.identifier
【问题讨论】:
标签: terraform