不支持的属性 - Terraform GCP
Unsupported attribute - Terraform GCP
我正在尝试使用模块在 GCP 中使用自定义网络创建 VM,但我收到 unsupported attribute
错误。下面是模块文件夹
下的subnet.tf文件
resource "google_compute_subnetwork" "this" {
name = var.subnet_name
ip_cidr_range = var.subnet_cidr_range
region = var.subnet_region
network = google_compute_network.this.name
depends_on = [
google_compute_network.this
]
}
resource "google_compute_subnetwork" "private" {
name = "private-subnetwork"
ip_cidr_range = "192.168.2.0/24"
region = var.subnet_region
network = google_compute_network.this.name
purpose = "PRIVATE"
depends_on = [
google_compute_network.this
]
}
使用根目录下main.tf模块的代码如下
module "vpc-network" {
source = "../../modules/vpc"
....
....
}
resource "google_compute_instance" "name" {
name = "windows-server"
description = "Test Windows server"
zone = "us-east1-a"
machine_type = "n1-standard-2"
boot_disk {
initialize_params {
image = "windows-cloud/windows-2019"
}
}
network_interface {
network = module.vpc-network.subnet_name
subnetwork = module.vpc-network.private_ip
access_config {
//
}
}
}
当我 运行 terraform plan 下面的错误出现。让我知道哪里出错了,模块中的 output.tf 包含 module.vpc-netowrk.subnet_name
和 module.vpc-netowrk.private_ip
的输出值
╷
│ Error: Unsupported attribute
│
│ on vpc.tf line 31, in resource "google_compute_instance" "name":
│ 31: subnetwork = module.vpc-network.private_ip
│ ├────────────────
│ │ module.vpc-network is a object, known only after apply
│
│ This object does not have an attribute named "private_ip".
我的错误是在 output.tf
文件中。
详细信息不正确
output "private_ip" {
value = google_compute_network.private.name
description = "private IP for the instance"
}
正确的细节
output "private_ip" {
value = google_compute_subnetwork.private.self_link
description = "private IP for the instance"
}
我正在尝试使用模块在 GCP 中使用自定义网络创建 VM,但我收到 unsupported attribute
错误。下面是模块文件夹
resource "google_compute_subnetwork" "this" {
name = var.subnet_name
ip_cidr_range = var.subnet_cidr_range
region = var.subnet_region
network = google_compute_network.this.name
depends_on = [
google_compute_network.this
]
}
resource "google_compute_subnetwork" "private" {
name = "private-subnetwork"
ip_cidr_range = "192.168.2.0/24"
region = var.subnet_region
network = google_compute_network.this.name
purpose = "PRIVATE"
depends_on = [
google_compute_network.this
]
}
使用根目录下main.tf模块的代码如下
module "vpc-network" {
source = "../../modules/vpc"
....
....
}
resource "google_compute_instance" "name" {
name = "windows-server"
description = "Test Windows server"
zone = "us-east1-a"
machine_type = "n1-standard-2"
boot_disk {
initialize_params {
image = "windows-cloud/windows-2019"
}
}
network_interface {
network = module.vpc-network.subnet_name
subnetwork = module.vpc-network.private_ip
access_config {
//
}
}
}
当我 运行 terraform plan 下面的错误出现。让我知道哪里出错了,模块中的 output.tf 包含 module.vpc-netowrk.subnet_name
和 module.vpc-netowrk.private_ip
╷
│ Error: Unsupported attribute
│
│ on vpc.tf line 31, in resource "google_compute_instance" "name":
│ 31: subnetwork = module.vpc-network.private_ip
│ ├────────────────
│ │ module.vpc-network is a object, known only after apply
│
│ This object does not have an attribute named "private_ip".
我的错误是在 output.tf
文件中。
详细信息不正确
output "private_ip" {
value = google_compute_network.private.name
description = "private IP for the instance"
}
正确的细节
output "private_ip" {
value = google_compute_subnetwork.private.self_link
description = "private IP for the instance"
}