Q:- To create a gcp compute VM with a network, subnetwork and a static_IP.
I’m trying to create a GCP VM instance with a reserved IP address through Terraform modules. Initially, I created a google_compute_address resource with a static IP. Now, how do I pass this reserved static IP address (from google_compute_address) to the compute VM Terraform configuration? Which additional variables would help in this use case? Please suggest any helpful references or resources related to this use case.
Which Terraform modules are you using to create the VM? A simple guideline you can follow is to reference one resource block to another in Terraform. In your case, it would look something like this (as shown in the Terraform documentation example) -
I agree with @mokit that the provided configuration will create a resource address and assign the created static IP address to the VM. However, the configuration was intended to output an Ephemeral External IP address. An example of how to create and attach a Reserved Internal IP static address to a VM is provided in the configuration below.
In response to your query, here are the variables or attributes that you need to configure:
/Block Interface for google compute instance
network_interface {
network = "xxxxxx" # Name of your VPC network
subnetwork = "xxxxx" #Name of your Subnetwork on your VPC
network_ip = google_compute_address.Internalstatic(Root ID).address
#Alternatively, you can specify an IP address; e.g., 10.0.0.8
}
}
Example of Reserved Internal Static IP address Configuration:
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.