gpt4 book ai didi

google-cloud-platform - Terraform random_string 作为 linux 机器的密码

转载 作者:行者123 更新时间:2023-12-03 23:01:46 26 4
gpt4 key购买 nike

我想用它为 gcp 中的 linux 机器生成一个随 secret 码。

我的问题是之后如何获取密码。我应该为此使用输出还是存储在其他地方?我在互联网上看到这段代码,然后问自己他们是怎么知道密码的。

resource "random_string" "master_password" {
length = 16
special = true
}

resource "google_container_cluster" "test" {
name = "test"
zone = "europe-west1-d"

master_auth {
username = "client"
password = "${random_string.master_password.result}"
}

node_pool = [{
name = "pool"
autoscaling = {
min_node_count = 1
max_node_count = 3
}

node_config {
disk_size_gb = 100
machine_type = "n1-standard-2"

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",
]

labels {
test = "true"
}
}
}]
}

最佳答案

密码将存储在您的状态文件中。您可以在那里挖掘它,但它在文件中的确切位置完全有可能在 Terraform 版本之间发生变化。

正如您提到的,获得一致输出的最佳方法是使用输出 block 。然后,当您执行 terraform apply 时,将会有一个很好的人类可读的密码输出。请注意,任何有权访问您的状态的人都可以访问该密码,因此请确保状态安全。

如果您使用远程状态(例如在 S3 存储桶中),您还可以使用 terraform_remote_state从另一个 Terraform 运行中访问它。您将需要显式地输出 值,您希望从terraform_remote_state 获得这些值。

最后,请注意,如果某些东西捕获了您的 terraform apply 的输出,它也会捕获该输出,因为 terraform apply 写入 STDOUT。如果您使用 CI 工具,可能会发生这种情况。只是需要注意的事情。

关于google-cloud-platform - Terraform random_string 作为 linux 机器的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49672323/

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