Skip to main content

Command Palette

Search for a command to run...

Day_8 : Deploying a Docker Environment on Google Cloud Platform with Terraform

Updated
3 min read
Day_8 : Deploying a Docker Environment on Google Cloud Platform with Terraform
N
🚀 Greetings World! 🌐 Meet a dynamic Frontend Developer, UI/UX Designer, and avid explorer of Cloud & DevOps realms! Uncover the journey of a professional deeply passionate about crafting seamless user experiences, designing visually stunning interfaces, and navigating the cloud with a DevOps mindset. 🔧 Skills Snapshot: - Frontend Mastery: HTML, CSS, and JavaScript expert, specializing in React, Angular, and Vue.js. - Design Wizardry: Proficient in wireframing, prototyping, and Adobe Creative Suite and Figma for captivating designs. - Cloud Maestro: Fluent in AWS, Azure, and Google Cloud Platform, adept at architecting scalable solutions. - DevOps Guru: Skilled in Docker, Kubernetes, Jenkins, and Git, contributing to efficient development workflows. 🔗 Let's Connect: Open to collaborating on exciting projects and sharing industry insights, I invite connections for networking or discussions. Reach out for potential collaborations. 📧 Contact Me: -Portfolio:[https://www.nehalingole.in/] - GitHub: [GitHub Profile](https://github.com/Ingole712521) - Email: [nehalingole2001@gmail.com](mailto:nehalingole2001@gmail.com) - Mobile: 7397966719 - Figma: [Figma Profile](https://www.figma.com/@nehalingole) - Twitter: [Twitter Profile](https://twitter.com/IngoleNehal) - HashNode: [HashNode Profile](https://hashnode.com/@Nehal71) - LinkedIn : [LinkedIn Profile](https://www.linkedin.com/in/nehal-ingole/)

Introduction

In today’s rapidly evolving technological landscape, the ability to quickly deploy and manage infrastructure is crucial. Infrastructure as Code (IaC) tools like Terraform allow developers and system administrators to automate the provisioning and configuration of cloud resources, enabling more efficient and consistent deployments. In this blog post, we’ll explore how to use Terraform to deploy a Docker environment on Google Cloud Platform (GCP).

Code file :- https://github.com/Ingole712521/Terraform_Expert/tree/main/Day_8_GCP


Explanation

Google Cloud Platform (GCP) offers a plethora of services and features for building, deploying, and managing applications in the cloud. Docker, on the other hand, is a popular containerization platform that enables developers to package their applications and dependencies into lightweight, portable containers.

In this tutorial, we will leverage Terraform, a widely-used IaC tool, to automate the deployment of a virtual machine (VM) instance on GCP and install Docker on it. Let's break down the Terraform configuration file step by step:

data "google_compute_image" "demo" {
  family  = "ubuntu-2204-lts"
  project = "ubuntu-os-cloud"
}

Here, we're defining a data source to retrieve the Ubuntu 22.04 LTS image from the Google Cloud Platform project "ubuntu-os-cloud".

locals {
  region            = var.region
  availability_zone = var.zone
}

This block defines local variables for the region and availability zone based on input variables.

resource "tls_private_key" "ssh" {
  algorithm = "RSA"
}

This resource generates an RSA private key that will be used for SSH access to the VM instance.

resource "google_compute_instance" "demo" {
  // Configuration for the Google Compute Engine VM instance
}

This block defines a Google Compute Engine instance resource named "demo".

metadata_startup_script = <<EOT
  // Shell script to be executed on instance startup
EOT

Here, we define a startup script that will be executed when the VM instance starts. This script updates the package list and installs Docker CE.

resource "google_compute_firewall" "demo-ssh-ipv4" {
  // Configuration for the firewall rule allowing SSH traffic
}

This block defines a firewall rule that allows SSH traffic to the VM instance.

resource "local_file" "local_ssh_key" {
  // Configuration for saving the generated private key to a local file
}

This block saves the generated private key to a local file on the machine running Terraform.

output "instance_ip" {
  // Output variable for the instance's public IP address
}

This block defines an output variable for the public IP address of the VM instance.

output "instance_ssh_key" {
  // Output variable for the path to the generated SSH private key file
}

This block defines an output variable for the path to the generated SSH private key file.


Demo

Main.tf file

varible.tf file

provider.tf file

Final Result :-

  1. ssh_key creation

  1. Output of main.tf file

  1. Output from GCP

  2. Deleting


Video

Conclusion

Terraform simplifies the deployment of Docker environments on Google Cloud Platform (GCP), offering efficiency and consistency. This tutorial has walked through the Terraform configuration, showcasing how it orchestrates the provisioning of GCP resources. Additionally, a video demonstration accompanies this guide, providing a visual walkthrough of the deployment process. By leveraging Terraform and GCP, developers can automate infrastructure management, focusing more on building and deploying applications. Happy deploying!

Connect with us:

More from this blog

R

Read & Learn

88 posts

Get ready for a journey through the captivating realms of projects and technology!

💡 Our upcoming blogs are your ticket to a world of insights, coding wizardry, and a dash of innovation.