Skip to content

usrbinkat/pulumi-iac-gcp-cloud-run

Repository files navigation

Google Cloud Run with Pulumi

Open in GitHub Codespaces

License Pulumi

Powered by Pulumi + Devcontainers

The Pulumi Devcontainer is designed with deep VS Code and Github Codespaces integration to streamline common Pulumi IaC development environments.

Getting Started

Overview

This document describes building and deploying the microservices demo application(Online Boutique) to Cloud Run.

Objectives

  • Minimize code changes.
  • Ensure the internal microservices are private and keep the network traffic inside the Google network (serverless VPC connectors will be used).
  • Redis cache will be deployed to Memorystore(Redis).
  • Use Infrastructure-as-code(Pulumi) to deploy the solution.

Architecture

Architecture

Dev Environment

Github Codespaces

Open in GitHub Codespaces

Codespaces is the easiest way to get started quickly. Simply click the button above to open this repository in a new Codespace and then follow the First time setup instructions below.

VSCode Devcontainer

To use this repo with VSCode in a local Devcontainer with Docker, clone this repository and open in VSCode, follow prompts on screen to open in the Devcontainer.

To use the Dev Container in VS Code, you will need to install the Remote - Containers extension, and follow the official tutorial here to begin.

Local Environment

Alternatively, use this IaC repository locally as is and maintain your dependencies according to your own preferences and requirements.

Once your IaC and dependencies are met, proceed to Setup.

Setup

  1. Pulumi Login
pulumi login
  1. Create a new stack
pulumi stack select --create --stack workshop-cloudrun
  1. Install NPM dependencies
npm install
  1. Google Cloud login
# Setup gcloud cli
gcloud init

# Configure gcloud cli
# Set GCP project ID:
# - eg: export PROJECT_ID=<YOUR GCP PROJECT ID>
export PROJECT_ID='pulumi-devrel'
gcloud config set project $PROJECT_ID
gcloud auth application-default login
gcloud auth configure-docker
  1. Pulumi configure stack gcp:project value
pulumi config set gcp:project $PROJECT_ID

Deploy

pulumi up -y

By default, the service deployments will use the container images listed in the release/kubernetes-manifests.yaml file.

If you want to build the container images from the source code, you can set the flag build_image_from_src to true using the following command:

pulumi config set build_image_from_src true

Note: This step will NOT work in CloudShell since CloudShell does not have sufficient disk space to build all the container images.

Clean up

If you don't want to delete the whole project, run the following command to delete the resources:

pulumi destroy -y

Reference

Demo code based on original work by @xiangshen-dk from github.com/shenxiang-demo/microservices-demo/.../serverless/pulumi