如何使用 Terraform 将标准网络接口分配给 Google Cloud 平台上的计算实例?

huangapple go评论86阅读模式
英文:

How to assign a STANDARD network interface to a compute instance on GCP using terraform?

问题

在使用标准网络的 Terraform 模板运行时:

  1. resource "google_compute_address" "default_standard" {
  2. name = "standard-address"
  3. region = var.region
  4. network_tier = "STANDARD"
  5. }
  6. # 创建虚拟机实例
  7. resource "google_compute_instance" "my_instance" {
  8. name = "my-instance"
  9. machine_type = "e2-micro" # 免费套餐实例
  10. zone = var.zone
  11. boot_disk {
  12. initialize_params {
  13. image = "debian-11-bullseye-v20230509"
  14. }
  15. }
  16. network_interface {
  17. network = "default"
  18. access_config {
  19. // 公共 IP
  20. nat_ip = google_compute_address.default_standard.address
  21. }
  22. }
  23. }

出现错误:

错误: 创建实例时出错: googleapi: 错误 400: 无效的资源使用: '外部 IP 地址:35.211.106.69 的网络层级为 STANDARD,与实例访问配置中的 PREMIUM 网络层级不匹配',invalidResourceUsage

我该怎么办?

英文:

When running a terraform template using a STANDARD network like:

  1. resource "google_compute_address" "default_standard" {
  2. name = "standard-address"
  3. region = var.region
  4. network_tier = "STANDARD"
  5. }
  6. # Create a virtual machine instance
  7. resource "google_compute_instance" "my_instance" {
  8. name = "my-instance"
  9. machine_type = "e2-micro" # Free tier instance
  10. zone = var.zone
  11. boot_disk {
  12. initialize_params {
  13. image = "debian-11-bullseye-v20230509"
  14. }
  15. }
  16. network_interface {
  17. network = "default"
  18. access_config {
  19. // Public IP
  20. nat_ip = google_compute_address.default_standard.address
  21. }
  22. }
  23. }

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

我找到了问题,实际的实例定义必须包括它将允许的网络类型:

  1. resource "google_compute_address" "default_standard" {
  2. name = "standard-address"
  3. region = var.region
  4. network_tier = "STANDARD"
  5. }
  6. # 创建一个虚拟机实例
  7. resource "google_compute_instance" "my_instance" {
  8. name = "my-instance"
  9. machine_type = "e2-micro" # 免费套餐实例
  10. zone = var.zone
  11. boot_disk {
  12. initialize_params {
  13. image = "debian-11-bullseye-v20230509"
  14. }
  15. }
  16. network_interface {
  17. network = "default"
  18. access_config {
  19. // 公共IP
  20. nat_ip = google_compute_address.default_standard.address
  21. network_tier = "STANDARD"
  22. }
  23. }
  24. }
英文:

Found the problem, the actual instance definition has to include the type of network it will allow:

  1. resource "google_compute_address" "default_standard" {
  2. name = "standard-address"
  3. region = var.region
  4. network_tier = "STANDARD"
  5. }
  6. # Create a virtual machine instance
  7. resource "google_compute_instance" "my_instance" {
  8. name = "my-instance"
  9. machine_type = "e2-micro" # Free tier instance
  10. zone = var.zone
  11. boot_disk {
  12. initialize_params {
  13. image = "debian-11-bullseye-v20230509"
  14. }
  15. }
  16. network_interface {
  17. network = "default"
  18. access_config {
  19. // Public IP
  20. nat_ip = google_compute_address.default_standard.address
  21. network_tier = "STANDARD"
  22. }
  23. }
  24. }

huangapple
  • 本文由 发表于 2023年6月6日 12:02:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76411375.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定