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,230 points
1,781 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,440 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,440 points
3,712 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,440 points
8,222 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,440 points
2,624 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,440 points
2,177 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,440 points
4,357 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,440 points
525 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,440 points
653 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,440 points
2,335 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,440 points
2,456 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