Skip to content

Ercan Ermis

notes for everyone

Menu
  • Cloud
    • Amazon Web Services
    • Google Cloud Platform
  • Linux
  • DevOps
  • Docker
  • Uncategorized
  • Contact Me
Menu

Google Cloud Platform Automation with Terraform Easily

Posted on April 30, 2021April 30, 2021 by Ercan

Once upon a time, when I was learning Google Cloud Platform, I just want to automate my workflow and deployments with terraform and, I wrote this IaaC (Infrastructure as a Code) to manage my infrastructure easily and fastly.

What can this do?

Creating a secure load balancer with SSL and turns the HTTP requests to HTTPS with 301 redirection code.
Creating an Instance Template and set everything about network, subnet, startup script.
Creating an Instance Group and manage them. If your instance group CPU is more or less than a value, the instance group manager will automatically scale up or scale down the VMs.
VM instances are running with private IP and, project-wide SSH access is not allowed on default. Managing the firewall rule for load balancer health check.

Requirements

  • Enable Compute Engine API if doesn’t enable.
  • Create Service account with `Editor role (or whatever you want) and export the key file.
  • Create Cloud Google Storage Bucket for keep the terraform state. If you want, you can add your service account as a member to bucket.
  • Create Compute Engine Image You can create a Debian 10 based VM and install nginx via sudo apt install -y nginx and test this terraform code. Don’t forget to sudo systemctl enable nginx command before turn your VM to image.

Usage

Here is the steps…

  1. Clone the repository


    git clone [email protected]:flightlesstux/gcp-instance-group-and-loadbalancer-w-terraform.git

  2. Authenticate to Google Platform if even google-sdk is not installed. It’s really useful for CI/CD pipelines! If you already logged in to your Google Cloud Platform project like gcloud auth login, you can skip this step.


    export GOOGLE_APPLICATION_CREDENTIALS=service-account-key.json

  3. Project ID is also declared via terraform but if you don’t export the value, you will probable get an error like below.


    export GOOGLE_PROJECT="0123456789012"

    │ Error: project: required field is not set
    │
    │ with google_compute_instance_group_manager.this,
    │ on group_manager.tf line 1, in resource "google_compute_instance_group_manager" "this":
    │ 1: resource "google_compute_instance_group_manager" "this" {



  4. Edit variable values


    variables.tf file.

  5. SSL Certificate Settings


    Paste your SSL certificate and the key file under certs folder . Loadbalancer needs to be secure! You can paste your Public key certificate and Certificate chain into certificate.crt.


  6. You can follow-up your production environment version easily with this variable. And also, Instance group need the new version for make a rolling update.


    export TF_VAR_deploy_version=v1

  7. Initilaze


    terraform init

  8. Let’s Deploy


    terraform apply or terraform apply -auto-approve


Repository Address

https://github.com/flightlesstux/gcp-instance-group-and-loadbalancer-w-terraform

I hope this article will help you.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • SSL CA Problem on CentOS7 Docker and Solution
  • What do I have?
  • I’m officially AWS Community Builder!
  • Deploy HA nginx to AWS ECS with Geolocation Routing via Terraform
  • Deploy nginx docker to AWS ECS with Terraform Automation
  • How to Install Node Exporter on Linux Server
  • FortiClient Problem on M1 MacBookPro Problem Solution
  • Connect your AWS to GCP with Terraform via IPSec Site-to-Site VPN
  • Google Cloud Platform Automation with Terraform Easily
  • How to secure your Amazon Web Services account
  • Install UGREEN USB Ethernet Adapter on macOS
  • Redirect 301 HTTPS on App Engine with nginx on Google Cloud Platform
  • Set two different Target Groups on AWS Load Balancer with Terraform
  • Extend your ec2 Linux disk without reboot on Amazon Web Services
  • Create a New Grant User on AWS RDS (MariaDB)
  • Amazon S3 CORS Settings with CloudFront on Amazon Web Services
  • Take your GitLab backup everyday if it works in Docker
  • Find large files in CentOS, ubuntu and MacOS easily
  • Fix “Error: rpmdb open failed” on CentOS or Amazon Linux 2
  • Error: No space left on the device when starting/stopping services only
  • Juniper SRX110H-VA VDSL2 Configuration Step by Step
  • Enable Logrotation for Docker Containers
  • Download specific file extension via wget easily on terminal
  • Find the exact size of certain files in Linux via terminal
  • Disable SELinux on CentOS 7 or CentOS 8
  • Hello Blog!

Tag Cloud

amazon linux 2 amazon web services automation aws aws community builder bug centos ci/cd cloud community connection container curl devops docker ec2 ecs fargate file size forticlient fortigate gcp gitlab google cloud platform ipsec isp juniper linux m1 macbookpro macos multi region network pipeline reliability route table security terraform turknet ubuntu vdsl2 vpn vpn problem vpn tunnel wget yum

Archive

  • March 2022 (1)
  • July 2021 (1)
  • May 2021 (6)
  • April 2021 (5)
  • February 2021 (1)
  • January 2021 (1)
  • September 2020 (2)
  • July 2020 (1)
  • April 2020 (1)
  • March 2020 (1)
  • February 2020 (1)
  • November 2019 (5)
©2022 Ercan Ermis | Built using WordPress and Responsive Blogily theme by Superb