英文:
How to assign a STANDARD network interface to a compute instance on GCP using terraform?
问题
在使用标准网络的 Terraform 模板运行时:
resource "google_compute_address" "default_standard" {
name = "standard-address"
region = var.region
network_tier = "STANDARD"
}
# 创建虚拟机实例
resource "google_compute_instance" "my_instance" {
name = "my-instance"
machine_type = "e2-micro" # 免费套餐实例
zone = var.zone
boot_disk {
initialize_params {
image = "debian-11-bullseye-v20230509"
}
}
network_interface {
network = "default"
access_config {
// 公共 IP
nat_ip = google_compute_address.default_standard.address
}
}
}
出现错误:
错误: 创建实例时出错: googleapi: 错误 400: 无效的资源使用: '外部 IP 地址:35.211.106.69 的网络层级为 STANDARD,与实例访问配置中的 PREMIUM 网络层级不匹配',invalidResourceUsage
我该怎么办?
英文:
When running a terraform template using a STANDARD network like:
resource "google_compute_address" "default_standard" {
name = "standard-address"
region = var.region
network_tier = "STANDARD"
}
# Create a virtual machine instance
resource "google_compute_instance" "my_instance" {
name = "my-instance"
machine_type = "e2-micro" # Free tier instance
zone = var.zone
boot_disk {
initialize_params {
image = "debian-11-bullseye-v20230509"
}
}
network_interface {
network = "default"
access_config {
// Public IP
nat_ip = google_compute_address.default_standard.address
}
}
}
Gives the error:
Error: Error creating instance: googleapi: Error 400: Invalid resource usage: 'External IP address: 35.211.106.69 has a different network tier STANDARD from the network tier in instance access config PREMIUM.'., invalidResourceUsage
What can I do?
答案1
得分: 1
我找到了问题,实际的实例定义必须包括它将允许的网络类型:
resource "google_compute_address" "default_standard" {
name = "standard-address"
region = var.region
network_tier = "STANDARD"
}
# 创建一个虚拟机实例
resource "google_compute_instance" "my_instance" {
name = "my-instance"
machine_type = "e2-micro" # 免费套餐实例
zone = var.zone
boot_disk {
initialize_params {
image = "debian-11-bullseye-v20230509"
}
}
network_interface {
network = "default"
access_config {
// 公共IP
nat_ip = google_compute_address.default_standard.address
network_tier = "STANDARD"
}
}
}
英文:
Found the problem, the actual instance definition has to include the type of network it will allow:
resource "google_compute_address" "default_standard" {
name = "standard-address"
region = var.region
network_tier = "STANDARD"
}
# Create a virtual machine instance
resource "google_compute_instance" "my_instance" {
name = "my-instance"
machine_type = "e2-micro" # Free tier instance
zone = var.zone
boot_disk {
initialize_params {
image = "debian-11-bullseye-v20230509"
}
}
network_interface {
network = "default"
access_config {
// Public IP
nat_ip = google_compute_address.default_standard.address
network_tier = "STANDARD"
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论