bluethundr
bluethundr

Reputation: 1345

How do I assign a static internal IP to GCP Windows Server Instance using Terraform?

I have to create a static internal IP address for windows servers using Terraform and I am on version 12.

I have this code block that I use to create the servers:

resource "google_compute_instance" "instance1" {
  name         = var.instance_name1
  machine_type = var.machine_type
  zone         = var.zone1
  tags         = [var.instance_name1, var.env_name]
  boot_disk {
    initialize_params {
    size =  var.boot_disk_size
    image = data.google_compute_image.sqlserverimage.self_link
    }

    }

  network_interface {
  subnetwork = var.subnetwork
  subnetwork_project = var.subnetwork_project
 }
}

How can I alter this so that I can assign a static internal IP to a new windows GCP server in Terraform?

Upvotes: 1

Views: 126

Answers (3)

Janardhan
Janardhan

Reputation: 51

Specify address value. For example,

From address-with-subnetwork documentation:

resource "google_compute_address" "internal_with_subnet_and_address" {
  name         = "my-internal-address"
  subnetwork   = google_compute_subnetwork.default.id
  address_type = "INTERNAL"
  address      = "10.0.42.42"
  region       = "us-central1"
}

Reference: 5254774

Upvotes: 0

SAN
SAN

Reputation: 107

try once with nat_ip >> check the link below

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#nat_ip

Upvotes: 0

Simone Ripamonti
Simone Ripamonti

Reputation: 322

Have you tried using network_ip?

network_interface {
  subnetwork = var.subnetwork
  subnetwork_project = var.subnetwork_project
  network_ip = "1.2.3.4"
}

The chosen ip must be in the subnet range

Upvotes: 1

Related Questions