Skip to content

fborello-lambda/terraform_handson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform HandsOn

graph LR;
    A[Compute Instance] <--> B[VPC Peering] <--> C[Cloud SQL Instance]
Loading

HandsOn project using GCP to provide a server that connects to a Postgres Database. The Postgres Database acn only be accessed via the server.

Core concepts are put into practice, such as subnetworks, VPCs and even the way of connecting the DB with the VPC network created.

How

  1. First of all, create a GCP project, then define the project_id variable inside a file named terraform.tfvars:
project_id = "project_name"
  1. Create a bucket using GCP.
  2. Create the file backend.conf, and set with the information of the created bucket:
cp backend.conf.example backend.conf
  1. Create an ssh-key, name the .pub as follows ./ssh_keys/gcp.pub

  2. Init Terraform's state

terraform init -backend-config=backend.conf 
  1. Apply the changes needed to set the resources:
terraform apply

Now, after all resources have been initialized, ssh into the VM. After the terraform apply the output should be:

compute_instance_public_ip = "public_ip"
internal_ipv4 = "postgres_ip"

Use the compute_instance_public_ip to access the VM:

ssh -i priv_key dev@public_ip

Inside the VM, install psql:

sudo apt install postgresql-client

Finally, inspect the created database, it will ask for the password, the default is password:

psql -h "postgres_ip" -U dev -d db_policy1 -p 5432

Inside the postgres cli, we can type \l to inspect the db_policy1 db.

About

Terraform HandsOn using GCP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages