我正在学习terraform部署和GCP,以简化部署。
我已经成功地部署了一个postgreSQL db。
现在,我正试图利用terraform输出将postgreSQL DB服务器生成的私有ip写入启动terraform的输出目录。我不清楚的是:
(1)输出是在同一个main.tf文件中定义的?
(2)输出参数从哪里引用?我找不到正确的aline文档。这样的话,我在应用:Error: Reference to undeclared resource时一直会遇到错误。
我的main.tf看起来像这样
resource "google_sql_database_instance" "main" {
name = "db"
database_version = "POSTGRES_12"
region = "us-west1"
settings {
availability_type = "REGIONAL"
tier = "db-custom-2-8192"
disk_size = "10"
disk_type = "PD_SSD"
disk_autoresize = "true"
}
}
output "instance_ip_addr" {
value = google_sql_database_instance.private_network.id
description = "The private IP address of the main server instance."
}发布于 2022-07-16 07:42:27
至于代码样式,通常会有一个名为outputs.tf的单独文件,在该文件中,您将在成功的应用程序之后添加希望输出的所有值。问题的第二部分分为两部分:
所以,在你的情况下,应该是:
output "instance_ip_addr" {
value = google_sql_database_instance.main.private_ip_address # <RESOURCE TYPE>.<NAME>.<ATTRIBUTE>
description = "The private IP address of the main server instance."
}发布于 2022-07-16 07:39:32
要引用资源的属性,应该放置如下内容:
[resource type].[resource name].[attribute]在这种情况下,输出应该是:
output "instance_ip_addr" {
value = google_sql_database_instance.main.private_ip_address
description = "The private IP address of the main server instance."
}输出属性列在文献资料中。把它放在main.tf中是可以的。
https://stackoverflow.com/questions/73002346
复制相似问题