← From Zero to Deployed Alle LektionenAll lessons Setup ModelleModels

Phase 2 · Bauen mit Agenten

16 · Mit Terraform deployen

Du bringst deine App live — eine öffentliche HTTPS-URL, die jeder im Browser öffnen kann.

Phase 2 · Building with agents

16 · Deploy with Terraform

You bring your app live — a public HTTPS URL anyone can open in a browser.

Das ist die Ziellinie: Deine App läuft nicht mehr nur bei dir, sondern für alle. Hier zahlt sich alles aus Phase 1 aus — HTTPS, Container, Cloud, Terraform.

Die Idee

Bisher läuft die App in deiner Werkstatt (dein Laptop). Jetzt stellst du sie ins Schaufenster an der Straße (das Internet), mit einer Adresse, die jeder besuchen kann.

Für den Instagram-Klon heißt „live“: Du schickst einem Freund einen Link, er öffnet ihn am Handy, sieht deinen Feed, postet selbst ein Foto — und es bleibt gespeichert, weil es in der Cloud liegt.

So funktioniert es

Der Weg in wenigen Zügen:

  1. Container bauen (das Dockerfile aus Lektion 06).
  2. Code zu GitHub pushen (sauberer Zwischenstand).
  3. Image in die Cloud legen und Terraform ausführen (Cloud Run + Cloud SQL + Budget-Alarm).
  4. terraform apply → du bekommst eine öffentliche HTTPS-URL.
gcloud builds submit --tag REGION-docker.pkg.dev/PROJECT/app:latest
terraform plan       # Vorschau lesen
terraform apply      # bauen, gibt die URL aus
flowchart LR
    A[Container] --> B[Image in der Cloud]
    B --> C[terraform apply]
    C --> D[Cloud Run + Cloud SQL]
    D --> E[https://…run.app]

Cloud Run vergibt automatisch eine run.app-URL mit HTTPS. Prüfe ehrlich: URL auf dem Handy über Mobilfunk öffnen (nicht im eigenen WLAN).

So steuerst du es

Geheimnisse (DB-Passwort) kommen über Variablen, nie in die Datei. Richte einen Budget-Alarm ein — er mailt dir, bevor echtes Geld fließt. Wenn du fertig bist: terraform destroy räumt alles ab. Cloud Run ruht ohnehin auf null; destroy stoppt zusätzlich die kleinen Dauerkosten der Datenbank.

So sagst du es dem Agenten:

„Bereite das Deployment vor: Container bauen, Image hochladen, Terraform für Cloud Run + Cloud SQL, inklusive Budget-Alarm.“

„Zeig mir terraform plan und die erwartete öffentliche URL, bevor wir apply ausführen.“

„Stelle sicher, dass die App auf PORT lauscht und über HTTPS erreichbar ist.“

Typischer Fehler: die App lauscht nicht auf PORT (siehe Lektion 06) — dann deployt sie, ist aber nicht erreichbar. Oder das Passwort landet in der .tf-Datei statt in einer Variable.

Kurz-Check

  1. Was ist der sichtbare Erfolg dieses Schritts?
  2. Wofür ist der Budget-Alarm da?
  3. Wie prüfst du ehrlich, dass die App wirklich öffentlich ist?
Antworten anzeigen
  1. Eine öffentliche HTTPS-URL, die jeder im Browser öffnen kann.
  2. Er warnt per Mail, bevor echte Kosten entstehen.
  3. Die URL auf dem Handy über Mobilfunk (nicht im eigenen WLAN) öffnen.

This is the finish line: your app no longer runs only for you, but for everyone. Here everything from Phase 1 pays off — HTTPS, container, cloud, Terraform.

The idea

So far the app runs in your workshop (your laptop). Now you put it in the shop window on the street (the internet), with an address anyone can visit.

For the Instagram clone, "live" means: you send a friend a link, they open it on their phone, see your feed, post a photo themselves — and it stays saved, because it lives in the cloud.

How it works

The path in a few moves:

  1. Build the container (the Dockerfile from lesson 06).
  2. Push code to GitHub (a clean checkpoint).
  3. Put the image in the cloud and run Terraform (Cloud Run + Cloud SQL + budget alert).
  4. terraform apply → you get a public HTTPS URL.
gcloud builds submit --tag REGION-docker.pkg.dev/PROJECT/app:latest
terraform plan       # read the preview
terraform apply      # build; prints the URL
flowchart LR
    A[Container] --> B[Image in the cloud]
    B --> C[terraform apply]
    C --> D[Cloud Run + Cloud SQL]
    D --> E[https://…run.app]

Cloud Run automatically assigns a run.app URL with HTTPS. Check honestly: open the URL on your phone over cellular (not on your own wifi).

How you steer it

Secrets (the DB password) come from variables, never in the file. Set a budget alert — it emails you before real money is spent. When you are done: terraform destroy clears everything. Cloud Run idles to zero anyway; destroy also stops the small ongoing database cost.

How to tell the agent:

"Prepare the deployment: build the container, push the image, Terraform for Cloud Run + Cloud SQL, including a budget alert."

"Show me terraform plan and the expected public URL before we run apply."

"Make sure the app listens on PORT and is reachable over HTTPS."

Common mistake: the app does not listen on PORT (see lesson 06) — then it deploys but is unreachable. Or the password ends up in the .tf file instead of a variable.

Quick check

  1. What is the visible success of this step?
  2. What is the budget alert for?
  3. How do you honestly check the app is really public?
Show answers
  1. A public HTTPS URL anyone can open in a browser.
  2. It warns by email before real costs occur.
  3. Open the URL on your phone over cellular (not on your own wifi).