Adr*_*ron 9 configuration terraform
我有两个环境变量.一个是TF_VAR_UN
另一个是TF_VAR_PW
.然后我有一个看起来像这样的terraform文件.
resource "google_container_cluster" "primary" {
name = "marcellus-wallace"
zone = "us-central1-a"
initial_node_count = 3
master_auth {
username = ${env.TF_VAR_UN}
password = ${env.TF_VAR_PW}
}
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring"
]
}
}
Run Code Online (Sandbox Code Playgroud)
这两个值我想用环境变量替换TF_VAR_UN
和TF_VAR_PW
是值的用户名和密码.我尝试了上面显示的内容,没有成功,我玩弄了一些其他的东西,但总是得到语法问题.
Lia*_*iam 15
我会尝试更像这样的东西,这似乎更接近文档.
variable "UN" {}
variable "PW" {}
resource "google_container_cluster" "primary" {
name = "marcellus-wallace"
zone = "us-central1-a"
initial_node_count = 3
master_auth {
username = "${var.UN}"
password = "${var.PW}"
}
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring"
]
}
Run Code Online (Sandbox Code Playgroud)
CLI命令如下所示.
TF_VAR_UN=foo TF_VAR_PW=bar terraform apply
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以执行以下操作来使其正常工作。
variable "db_password" { type= string }
Run Code Online (Sandbox Code Playgroud)
"db_password":"${var.db_password}"
Run Code Online (Sandbox Code Playgroud)
export TF_VAR_db_password="##password##"
Run Code Online (Sandbox Code Playgroud)
terraform plan
或者terraform apply
使用插值语法会引发 terraform 警告v0.12.18
。现在您不需要使用插值语法。您可以将其引用为var.hello
.
注意: 从语言的角度要理解的一件重要事情是,您不能使用环境变量声明变量。您只能使用环境变量为脚本中声明的变量赋值。例如,假设您有以下 .tf 脚本
variable "hello" {
type=string
}
现在,如果环境有一个变量 TF_VAR_hello="foobar",在运行时变量 hello 的值将是 "foobar"。如果在没有声明变量的情况下分配变量,则不会有任何影响。
归档时间: |
|
查看次数: |
15741 次 |
最近记录: |