This repository contains a workshop for learning Infrastructure as Code (IaC) using Terraform and the Cloud Development Kit for Terraform (CDKTF) to manage Google Cloud Platform (GCP) resources.
This workshop guides you through a progressive learning journey:
- Step 1: Basic Terraform with HCL (HashiCorp Configuration Language)
- Step 2: CDKTF with TypeScript
- Step 3: Advanced CDKTF with environment variables and remote state management
Each step builds on the previous one, demonstrating how to create the same infrastructure (GCP Pub/Sub topics and schemas) using different approaches and increasing levels of sophistication.
- Terraform (v1.0.0+)
- Node.js (v14.0+)
- CDKTF CLI
- Google Cloud SDK
- A Google Cloud Platform account with a project
- Appropriate permissions to create Pub/Sub resources and Storage Buckets
Located in the step1
directory, this step introduces basic Terraform concepts using HCL to define:
- A GCP Pub/Sub topic
- A GCP Pub/Sub schema
- A GCP Pub/Sub topic with the schema attached
This step focuses on understanding the basic structure of Terraform configurations, including providers, resources, variables, and outputs.
Located in the step2
directory, this step introduces CDKTF with TypeScript to define the same infrastructure as in Step 1. Key concepts include:
- Using a programming language (TypeScript) instead of HCL
- Defining infrastructure as code using object-oriented programming
- Understanding CDKTF constructs and how they map to Terraform resources
Located in the step3
directory, this step enhances the CDKTF project with:
- Environment-specific deployments (stage/prod)
- Resource naming with environment prefixes
- Remote state management using a GCP Storage Bucket
This step demonstrates how to build more sophisticated infrastructure deployments with proper environment separation and state management.
- Clone this repository
- Follow the instructions in each step's README.md file, starting with Step 1
For the best learning experience, follow these steps:
- Start with Step 1 to understand basic Terraform concepts
- Move to Step 2 to learn how to use CDKTF with TypeScript
- Complete Step 3 to understand advanced concepts like environment variables and remote state
Each step includes detailed instructions in its own README.md file.
This repository includes a presentation slide deck (presentation/cdktf-presentation.md
) created with Marp that provides an overview of Infrastructure as Code, Terraform, and CDKTF concepts.
The repository includes a script for generating simple, clean images with a single focused item, specifically designed for presentation slides using OpenAI's DALL-E:
# Generate a simple image with a single focused item for a presentation slide
node scripts/generate-image.js -p "Your image description" -o "presentation/images/output.png" --style minimal
# Generate a flat-style image with a single focused item
node scripts/generate-image.js -p "Your image description" -o "presentation/images/output.png" --style flat
See the Image Generation Script README for more details and options.
There are several ways to present the Marp slide deck:
-
You can use Marp CLI with npx without installing it globally:
npx @marp-team/marp-cli
-
Convert the presentation to HTML (for viewing in a browser):
npx @marp-team/marp-cli presentation/cdktf-presentation.md --output presentation.html
-
Convert to PDF:
npx @marp-team/marp-cli presentation/cdktf-presentation.md --pdf
-
Convert to PowerPoint:
npx @marp-team/marp-cli presentation/cdktf-presentation.md --pptx
-
Start a live server for presenting (with hot reload):
npx @marp-team/marp-cli -s presentation/cdktf-presentation.md
- Install the Marp for VS Code extension
- Open
presentation/cdktf-presentation.md
in VS Code - Use the "Marp: Export slide deck..." command from the command palette (Ctrl+Shift+P or Cmd+Shift+P)
- Choose your preferred export format (HTML, PDF, PPTX)
- For presentation mode, click the "Open Preview to the Side" button or use the "Marp: Open preview" command
- Use the arrow keys to navigate between slides
- Press
f
to enter fullscreen mode when presenting from HTML - Press
p
to toggle presenter notes view (if presenter notes are included)
- Terraform Documentation
- CDKTF Documentation
- Google Cloud Pub/Sub Documentation
- TypeScript Documentation
- Marp Documentation
- Marp CLI Documentation
- This workshop is designed for educational purposes
- The examples are simplified to focus on learning concepts
- In a production environment, you would likely add more security features and follow best practices for secret management