GCP CDKTF Plugin
The @stacksolo/plugin-gcp-cdktf is the core plugin that generates Terraform CDK code for GCP resources.
Quick Start
Section titled “Quick Start”{ "project": { "plugins": ["@stacksolo/plugin-gcp-cdktf"], "networks": [{ "name": "main", "functions": [{ "name": "api" }] }] }}Resources
Section titled “Resources”| Config | GCP Resource |
|---|---|
storageBuckets | Cloud Storage |
functions | Cloud Functions Gen2 |
uis | Firebase Hosting |
containers | Cloud Run |
loadBalancer | HTTP(S) Load Balancer |
Storage Buckets
Section titled “Storage Buckets”Create Cloud Storage buckets within a network. These can be used as trigger sources for functions.
{ "networks": [{ "name": "main", "storageBuckets": [ { "name": "myapp-uploads" }, { "name": "myapp-processed" } ] }]}Bucket Options
Section titled “Bucket Options”| Property | Type | Default | Description |
|---|---|---|---|
name | string | - | Bucket name (required, globally unique) |
location | string | region | Bucket location |
storageClass | string | STANDARD | STANDARD, NEARLINE, COLDLINE, ARCHIVE |
versioning | boolean | false | Enable object versioning |
uniformBucketLevelAccess | boolean | true | Use uniform IAM access |
Cloud Functions
Section titled “Cloud Functions”Deploy Cloud Functions Gen2 with HTTP or event triggers.
HTTP Function
Section titled “HTTP Function”{ "functions": [{ "name": "api", "entryPoint": "handler", "allowUnauthenticated": true }]}Storage-Triggered Function
Section titled “Storage-Triggered Function”Process files automatically when uploaded to a bucket:
{ "networks": [{ "name": "main", "storageBuckets": [ { "name": "myapp-uploads" }, { "name": "myapp-processed" } ], "functions": [{ "name": "processor", "entryPoint": "handler", "memory": "1Gi", "timeout": 300, "trigger": { "type": "storage", "bucket": "myapp-uploads", "event": "finalize" }, "env": { "OUTPUT_BUCKET": "myapp-processed" } }] }]}Storage trigger events:
| Event | When triggered |
|---|---|
finalize | File created or overwritten (default) |
delete | File deleted |
archive | File archived (versioned buckets) |
metadataUpdate | File metadata changed |
The plugin automatically:
- Enables Eventarc API
- Grants IAM permissions for GCS to publish events
- Grants the function permission to receive events
- Configures the Eventarc trigger
Load Balancer
Section titled “Load Balancer”The load balancer routes traffic to your functions, containers, and UIs based on URL paths.
Basic Config
Section titled “Basic Config”{ "loadBalancer": { "name": "gateway", "routes": [ { "path": "/api/*", "functionName": "api" }, { "path": "/*", "uiName": "web" } ] }}With HTTPS and Custom Domain
Section titled “With HTTPS and Custom Domain”{ "loadBalancer": { "name": "gateway", "domain": "app.example.com", "enableHttps": true, "redirectHttpToHttps": true, "routes": [ { "path": "/*", "functionName": "api" } ] }}With Automatic Cloudflare DNS
Section titled “With Automatic Cloudflare DNS”When using the Cloudflare Plugin, DNS records are created automatically:
{ "project": { "cloudflare": { "zoneId": "your-zone-id", "apiToken": "@secret/cloudflare-api-token" }, "networks": [{ "name": "main", "loadBalancer": { "name": "gateway", "domain": "app.example.com", "enableHttps": true, "dns": { "provider": "cloudflare", "proxied": true }, "routes": [{ "path": "/*", "functionName": "api" }] } }] }}Load Balancer Options
Section titled “Load Balancer Options”| Property | Type | Default | Description |
|---|---|---|---|
name | string | - | Load balancer name (required) |
routes | array | - | URL path to backend mappings (required) |
domain | string | - | Custom domain for HTTPS |
enableHttps | boolean | false | Enable managed SSL certificate |
redirectHttpToHttps | boolean | false | Redirect HTTP to HTTPS |
dns.provider | string | - | DNS provider (cloudflare) |
dns.proxied | boolean | true | Enable Cloudflare proxy |
Generated Code
Section titled “Generated Code”Code is generated to .stacksolo/cdktf/ using Terraform CDK (TypeScript).
# View generated codecat .stacksolo/cdktf/main.ts
# Run terraform commands directlycd .stacksolo/cdktf && npx cdktf planRequired APIs
Section titled “Required APIs”These GCP APIs are enabled automatically:
- Cloud Functions
- Cloud Build
- Cloud Run
- Cloud Storage
- Compute Engine
- Eventarc (for storage/pubsub triggers)
Learn More
Section titled “Learn More”- Source code
- Config Schema - All configuration options
- Deployment Guide