我有一个创建VM的模块。作为模块的变量,我希望有一个条件来选择是否将公共IP添加到VM接口。
这是我的main.tf(已整理)
module "vm_egress" {
source = "./modules/create_vm/"
vm_name = "my-vm"
vm_machine_type = "n1-standard-4"
vm_zone = "us-east-4a"
vm_subnetwork = "my-subnet"
vm_private_ip = "10.0.0.2"
# Conditional for public IP on network. If true, set access_config to {}.
apply_public_ip = "true"
}
这是我的模块(已精简)
resource "google_compute_instance" "vmseries" {
name = "${var.vm_name}"
machine_type = "${var.vm_machine_type}"
zone = "${var.vm_zone}"
network_interface {
subnetwork = "${var.vm_subnetwork}"
network_ip = "${var.vm_private_ip"
# Set access_config based on boolean of "apply_public_ip"
access_config = {}
}
}
对此将提供任何帮助或指导!
谢谢。
答案 0 :(得分:0)
一种替代方法可能是创建单独的公共子网和私有子网,然后通过有条件的方式指定将VM部署到的子网。这样可以完成同一件事,并且避免了将公共VM和私有VM都放在同一子网中的麻烦。