如何将静态 IP 映射到 terraform google 计算引擎实例? [英] How to map static IP to terraform google compute engine instance?

查看:23
本文介绍了如何将静态 IP 映射到 terraform google 计算引擎实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 terraform 与 google vm 提供程序一起使用.我想将现有的静态 IP 分配给 VM.

I'm using terraform with google vm provider. I want to assign existing Static IP to a VM.

代码:

resource "google_compute_instance" "test2" {
  name         = "dns-proxy-nfs"
  machine_type = "n1-standard-1"
  zone         = "${var.region}"

  disk {
    image = "centos-7-v20170719"
  }

  metadata {
    ssh-keys = "myuser:${file("~/.ssh/id_rsa.pub")}"
  }

  network_interface {
    network = "default"
    access_config {
      address = "130.251.4.123"
    }
  }
}

但它因错误而失败:

google_compute_instance.test2:network_interface.0.access_config.0:无效或未知密钥:地址

google_compute_instance.test2: network_interface.0.access_config.0: invalid or unknown key: address

我该如何解决这个问题?

How can I fix this?

推荐答案

您也可以让 terraform 为您创建静态 IP 地址,然后通过对象名称将其分配给实例.

You could also allow terraform to create the static IP address for you and then assign it to the instance by object name.

resource "google_compute_address" "test-static-ip-address" {
  name = "my-test-static-ip-address"
}

resource "google_compute_instance" "test2" {
  name         = "dns-proxy-nfs"
  machine_type = "n1-standard-1"
  zone         = "${var.region}"

  disk {
    image = "centos-7-v20170719"
  }

  metadata {
    ssh-keys = "myuser:${file("~/.ssh/id_rsa.pub")}"
  }

  network_interface {
    network = "default"
    access_config {
      nat_ip = "${google_compute_address.test-static-ip-address.address}"
    }
  }
}

这篇关于如何将静态 IP 映射到 terraform google 计算引擎实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆