![](/img/trans.png)
[英]Create gke cluster with existing shared vpc network using terraform
[英]Terraform and GCP - Create new Compute VM in existing Shared VPC and Subnet
如何创建新的计算实例并将其与现有的共享 VPC/子网关联? 共享的 VPC/子网已存在于另一个项目中。
我的 TF 块:
resource "google_compute_instance" "computevm1" {
name = "test-compute-vm1"
zone = "us-west1-a"
machine_type = "e2-standard-1"
network_interface {
network = "isolated-vpc"
}
boot_disk {
initialize_params {
image = "ubuntu-2004-focal-v20211212"
size = 20
}
}
}
我得到的错误:
The referenced network resource cannot be found., invalid
对于 HCL 属性网络,指定要在其中创建实例的项目中的 VPC 的网络名称。子网将自动从区域中选择。 创建实例时,共享 VPC 没有什么特别之处。
假设您的共享 VPC 在默认网络上启用:
network_interface {
network = "default"
}
如果不同,请更改名称。
您可以使用数据在 tf 文件中导入网络和子网,例如
data "google_compute_network" "main-default-vpc" {
name = "default"
project = "project-id"
}
data "google_compute_subnetwork" "subnet-for-vms" {
name = "name_of_subnet"
project = "project-id"
region = "us-central1"
你可以在你的network_interface中调用它们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.