簡體   English   中英

Terraform 和 GCP - 在現有的共享 VPC 和子網中創建新的計算 VM

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM