How to create GCP instance with public IP with terraform

0 votes
Hi Guys,

I am new to Terraform. I want to create a GCP instance with public IP. How can I do that?
Dec 1, 2020 in Terraform by akhtar
• 38,260 points
2,033 views

1 answer to this question.

0 votes

Hi@akhtar,

You need to specify "access_config" under "network_interface" to assign external IP to the GCE instance. 

resource "google_compute_network" "default" {
  name = "my-network"
}
resource "google_compute_subnetwork" "default" {
  name          = "my-subnet"
  ip_cidr_range = "10.0.0.0/16"
  region        = "us-central1"
  network       = google_compute_network.default.id
}
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"
}
answered Dec 1, 2020 by MD
• 95,460 points

Related Questions In Terraform

0 votes
1 answer

How to launch EC2 windows instance with powershell script using terraform?

Hi, In your Terraform code, you have written ...READ MORE

answered Jul 21, 2020 in Terraform by MD
• 95,460 points
4,306 views
0 votes
1 answer

How to attach Elastic IP in EC2 instance using Terraform code?

Hi@akhtar, You can use aws_eip resource in your ...READ MORE

answered Jul 22, 2020 in Terraform by MD
• 95,460 points
8,575 views
+2 votes
1 answer

How to attach an elastic load balancer with ec2 instance using Terraform?

Hi@akhtar, You can use aws_elb_attachment resource in Terraform. ...READ MORE

answered Aug 17, 2020 in Terraform by MD
• 95,460 points
2,895 views
0 votes
1 answer

How to create a service account in GCP using Terraform?

Hi@akhtar, You can create a service account in ...READ MORE

answered Sep 13, 2020 in Terraform by MD
• 95,460 points
2,431 views
0 votes
1 answer
0 votes
1 answer

Error:No credentials loaded. To use your gcloud credentials, run 'gcloud auth application-default login'.

Hi@akhtar, You are trying to connect the GCP ...READ MORE

answered Sep 12, 2020 in Terraform by MD
• 95,460 points
4,645 views
0 votes
1 answer

How to use GCP provider in Terraform?

Hi@akhtar, Terraform supports many providers to deploy the ...READ MORE

answered Sep 12, 2020 in Terraform by MD
• 95,460 points
709 views
0 votes
1 answer

How to launch an instance in GCP using Terraform?

Hi@akhtar, You can use the google_compute_instance resource in ...READ MORE

answered Sep 12, 2020 in Terraform by MD
• 95,460 points
839 views
0 votes
1 answer

How to create Filestore instance in GCP using Terraform?

Hi@akhtar, You can manage services in the GCP ...READ MORE

answered Sep 14, 2020 in Terraform by MD
• 95,460 points
2,618 views
0 votes
1 answer

How to create a rds snapshot from running rds instance in AWS using terraform?

Hi, I think you can use aws_db_instance resource to ...READ MORE

answered Jul 20, 2020 in Terraform by MD
• 95,460 points
2,665 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP