DEV Community

aravind-dussani99
aravind-dussani99

Posted on

Configure terraform with GCP

Context:
Will configure the terraform with GCP in this post.

Steps:

  1. Integrate terraform with GCP
  2. Enable the required GCP APIs
  3. Create a VPC and Subnet

Integrate terraform with GCP:

There are multiple ways to authenticate with GCP like gcloud auth or service account& key. Will use gcloud auth in this post.

We would be using the below mentioned information in this post.

Terraform resources:
1. Terraform block
2. Google, google-beta Provider
3. API enable resource
4. Network, Subnetwork resources

GCP information:
1. ProjectId
2. Region

*Gcloud auth: *

Create the provider.tf with google provider and required version and run the gcloud auth login.

authenticateterraformwithgcp

Proceed for further steps to authenticate terraform with GCP.

allowgoogleauthlibrary

Enable the required GCP APIs:

Will use the google_service_project resource to enable the required iam, workstation apis.

enable apis

Create a VPC and Subnet:

Use the mentioned google_compute_network , google_compute_subnetwork terraform resources to create the VPC and subnets in given gcp project.

terraformvpcsubnet

Resources - References:

Final words:

Feel free to comment your queries here or at LinkedIn . Thanks.

Top comments (0)