Deploy Flask App on Google Cloud Run with Terraform
Jay Sheth

Jay Sheth @jay_sheth

About: DevOps and Cloud Enthusiasts

Joined:
Apr 24, 2023

Deploy Flask App on Google Cloud Run with Terraform

Publish Date: Jul 15 '24
31 4

Prerequisite:

  1. GCP Account
  2. Install Google Cloud SDK
  3. Terraform Installed on Developer Desktop
  4. Python on Developer Desktop

In GCP Console:

  1. Create new Project named my-first-project on GCP console
    GCP Console
    GCP Console

  2. We will enable the following APIs for our project to work, run the below mentioned commands in Google Cloud CLI

  • Cloud Run
  • Artifact Registry
  • Cloud Build

    GCP commands

On Developer Desktop:

  1. Create a simple Flask Application
  • Create an app.py file

  • Create a Dockerfile

In GCP Console:

  1. Go to Artifact Registry
  2. Click on Create Repository Artifact Registry
  • Give name to repository ($REPO_NAME)
  • Select Docker in Format
  • Select Standard in Mode
  • Select Regional in Location Type
  • Select us-west1 in Region
  • Click on Create

On Developer Desktop

  1. In the folder where we created the Dockerfile; run the following commands
    Docker commands

  2. We will create Terraform project

  • Create terraform.tf for configuring the providers

  • Create main.tf containing the cloud run configuration

  • Create variable.tf containing the variables

  • Create data.tf containing the data

  • Create output.tf containing the output

  • Create terraform.tfvars containing the variable values

  • Now run the following commands in your terminal
    Terraform commands

Output

Flask application

Destroy Infrastructure

To destroy the infrastructure, run the following commands in your terminal
Terraform commands

👋👋BYE👋👋

Comments 4 total

  • Deepa
    DeepaJul 16, 2024

    Helpful for beginners 💯

  • Amit
    AmitJul 16, 2024

    Gr8 content 👏

  • Parth Sheth
    Parth ShethJul 16, 2024

    Very helpful and informative!

  • sangya lalwani
    sangya lalwaniJul 16, 2024

    Crisp and perfect! Thanks for sharing this!

Add comment