Terraform 请注明“;虚线;节点池的k8s标签?
Kubernetes支持元数据标签键中的点(例如Terraform 请注明“;虚线;节点池的k8s标签?,terraform,google-kubernetes-engine,Terraform,Google Kubernetes Engine,Kubernetes支持元数据标签键中的点(例如app.role),事实上这似乎是一种常见的约定 terraform配置语言(0.12)不支持参数名称中的点,因此无法指定此表单的标签。例如,在google\u container\u node\u pool配置中,我想指定以下内容: resource "google_container_node_pool" "my-node-pool" { ... labels = { app.role = web } } 有解决办法吗 注
app.role
),事实上这似乎是一种常见的约定
terraform配置语言(0.12)不支持参数名称中的点,因此无法指定此表单的标签。例如,在google\u container\u node\u pool
配置中,我想指定以下内容:
resource "google_container_node_pool" "my-node-pool" {
...
labels = {
app.role = web
}
}
有解决办法吗
注意:斜杠(/
)在k8s标签中也很常见
更新:万一有人在路上遇到同样的问题,我会找出问题的根源。我忽略了=
,将标签
参数错误地指定为块。所以看起来是这样的:
labels {
"app.role" = "web"
}
这产生了以下错误,将我引向了错误的方向:
Error: Invalid argument name
on main.tf line 45, in resource "google_container_node_pool" "primary_preemptible_nodes":
45: "app.role" = "web"
Argument names must not be quoted.
我注意到并修复了缺少的
=
,但我没有将映射键与参数名称的语法不同的问题放在一起。我验证了@ydaetskcoR的建议,即用引号括起标签是有效的。下面是定义我创建的节点池的代码段(使用Terraform v0.11.13):
编辑:我还验证了terraform 0.12.3也可以使用同样的方法 如果你计划好了会怎么样?您能否编辑问题中的任何适用错误?我认为你应该能够将
app.role
用引号括起来,比如“app.role”=“web”
,这样应该可以很好地工作。这太奇怪了。我敢发誓我试过了,但没用。不过,它现在起作用了。谢谢
resource "google_container_node_pool" "node_pool" {
cluster = "${google_container_cluster.cluster.name}"
zone = "${var.cluster_location}"
initial_node_count = "${var.node_count}"
autoscaling {
min_node_count = 1
max_node_count = 5
}
management {
auto_repair = true
auto_upgrade = true
}
node_config {
machine_type = "${var.machine_type}"
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/devstorage.read_only",
]
metadata {
disable-legacy-endpoints = "true"
}
labels = {
"app.role" = "web"
}
}
}