A shared wildcard certificate only stays shared if nobody can quietly add a second one. On GCP, all it takes is one pull request that drops a google_compute_managed_ssl_certificate and its own forwarding rule into a service directory, and certificate sprawl is back. Code review won’t catch every one of those. A plan gate will, and that’s the core of this guide. You’ll build a Terraform onboarding module that can’t create certificates or frontends, then add a CI check that rejects any plan that tries. ArgoCD then keeps the GKE side in line with Git.
The stack builds on the shared load balancer and certificate map from the cert map consolidation step of this series. It uses Terragrunt units for the infrastructure, a jq gate over the plan JSON, and an app-of-apps for the workloads. Along the way it covers the Certificate Manager inventory, drift detection and measured ArgoCD self-heal timing. Every command below was run on GCP and a GKE Autopilot cluster in December 2026 with OpenTofu 1.13, Terragrunt 1.1 and Argo CD 3.6, and the five errors we hit are reproduced with their fixes.
Lay out the stack
You split ownership so that only two Terragrunt units are allowed to create TLS or frontend resources. Each service unit creates its DNS record, NEG and backend service and nothing else. The load balancer unit reads every service’s host rule and composes the one URL map. The companion repo c4geeks/gcp-cert-guardrails holds every file shown here, with this layout:
live/lab/shared-certs: Cloud DNS zone, wildcard cert, cert map, global IPlive/lab/marketandlive/lab/docs: one service each, Cloud Run and internet NEG backendslive/lab/gxlb: URL map, HTTPS proxy, forwarding ruleci/sprawl-gate.sh: the plan gateargocd/andapps/: the app-of-apps and the GKE workload
Fork the repo first. The ArgoCD Applications later in this guide follow whatever repository their repoURL names, and you need push access to try the Git sync and decommission steps, so point them at your fork. Then point gcloud and OpenTofu at your project and enable the APIs the stack calls:
export GOOGLE_PROJECT=your-gcp-project-id
gcloud config set project $GOOGLE_PROJECT
gcloud auth application-default login
gcloud services enable compute.googleapis.com dns.googleapis.com certificatemanager.googleapis.com run.googleapis.com container.googleapis.com cloudasset.googleapis.com
Clone your fork and export the rest of the values root.hcl and the shared-certs unit read. The state bucket needs to exist before the first plan, and the wildcard cert can be the one you issued with DNS authorization in Certificate Manager. For a throwaway lab, a self-signed pair works because the load balancer serves whatever you upload:
git clone https://github.com/your-github-user/gcp-cert-guardrails.git
cd gcp-cert-guardrails
export TG_STATE_BUCKET=${GOOGLE_PROJECT}-tfstate
gcloud storage buckets create gs://${TG_STATE_BUCKET} --location europe-west1 --uniform-bucket-level-access
mkdir -p certs
openssl req -x509 -newkey rsa:2048 -nodes -days 90 -subj "/CN=*.cfg-lab.computingforgeeks.com" -addext "subjectAltName=DNS:*.cfg-lab.computingforgeeks.com,DNS:cfg-lab.computingforgeeks.com" -keyout certs/wildcard.key -out certs/wildcard.pem
export WILDCARD_CERT_PEM=$PWD/certs/wildcard.pem WILDCARD_KEY_PEM=$PWD/certs/wildcard.key
Because the market unit routes to a Cloud Run service, you deploy that first. Our project’s organization policy refuses allUsers invoker bindings, which is common in company projects, so the second command switches the service to skip the IAM invoker check instead. Ingress stays limited to internal traffic and the load balancer:
gcloud run deploy market --image us-docker.pkg.dev/cloudrun/container/hello --region europe-west1 --allow-unauthenticated --ingress internal-and-cloud-load-balancing
gcloud run services update market --region europe-west1 --no-invoker-iam-check
The lab zone is cfg-lab.computingforgeeks.com, and it’s hardcoded in four places: domain in live/root.hcl, the hostname input in the market and docs units, and the mock host in the gxlb unit. Replace it everywhere with a zone you control, and swap the repo URL in both Application manifests for your fork:
grep -rl cfg-lab.computingforgeeks.com live | xargs sed -i 's/cfg-lab\.computingforgeeks\.com/lab.example.net/g'
sed -i 's#github.com/c4geeks/#github.com/your-github-user/#' argocd/apps/food-web.yaml argocd/bootstrap/platform-apps.yaml
Commit and push both changes to your fork. The repo’s .gitignore keeps certs/, the plan directories and .terragrunt-cache/ out of the commit, so the private key stays local. The commands in the rest of this guide show the lab hostnames, so use your own zone wherever cfg-lab.computingforgeeks.com appears, including the openssl subject above, which you should regenerate for the new name.
Write the service-onboarding module
The module is the only path a service team gets, and it has no certificate, target proxy or forwarding rule in it. That absence is the policy. A team can’t attach its own cert through an input because there is no input to attach it to, and the plan gate below catches anyone who adds those resources outside the module. Here is modules/service-onboarding/main.tf as it ran in the lab:
resource "google_dns_record_set" "a" {
project = var.project_id
managed_zone = var.dns_zone_name
name = "${var.hostname}."
type = "A"
ttl = 300
rrdatas = [var.shared_lb_ip]
}
resource "google_compute_region_network_endpoint_group" "cloud_run" {
count = var.backend_type == "cloud_run" ? 1 : 0
project = var.project_id
name = "${var.name}-neg"
region = var.region
network_endpoint_type = "SERVERLESS"
cloud_run {
service = var.backend_ref
}
}
resource "google_compute_global_network_endpoint_group" "internet" {
count = var.backend_type == "internet_neg" ? 1 : 0
project = var.project_id
name = "${var.name}-neg"
network_endpoint_type = "INTERNET_FQDN_PORT"
default_port = 443
}
resource "google_compute_global_network_endpoint" "internet" {
count = var.backend_type == "internet_neg" ? 1 : 0
project = var.project_id
global_network_endpoint_group = google_compute_global_network_endpoint_group.internet[0].name
fqdn = var.backend_ref
port = 443
}
locals {
# one() returns null for the NEG type that was not created; [0] fails the plan
backend_id = coalesce(
one(google_compute_region_network_endpoint_group.cloud_run[*].id),
one(google_compute_global_network_endpoint_group.internet[*].id),
)
}
resource "google_compute_backend_service" "this" {
project = var.project_id
name = "${var.name}-backend"
load_balancing_scheme = "EXTERNAL_MANAGED"
protocol = var.backend_type == "internet_neg" ? "HTTPS" : "HTTP"
description = "managed_by=service-onboarding service=${var.name} env=${var.environment}"
custom_request_headers = var.backend_type == "internet_neg" ? ["Host: ${var.backend_ref}"] : []
backend {
group = local.backend_id
}
}
Notice the module doesn’t touch the URL map, because a URL map owned by every service is a URL map nobody owns. Instead it exports a host rule stub in outputs.tf, and the gxlb unit collects one stub per service:
output "url_map_host_rule" {
value = {
hosts = [var.hostname]
path_matcher = var.name
service_id = google_compute_backend_service.this.id
}
}
Our first version of this module was the one from the earlier edition of this guide, and it failed twice before it planned, once in the google provider’s schema and once in the expression language. Both errors are worth knowing because they show up in other modules too.
Error: An argument named “labels” is not expected here
google_compute_backend_service has no labels argument in provider 8.12, so a module that tags backends with labels fails at plan time:
11:21:56.126 STDERR [market] tofu: │ Error: Unsupported argument
11:21:56.126 STDERR [market] tofu: │
11:21:56.126 STDERR [market] tofu: │ on main.tf line 56, in resource "google_compute_backend_service" "this":
11:21:56.126 STDERR [market] tofu: │ 56: labels = merge(var.labels, {
11:21:56.126 STDERR [market] tofu: │
11:21:56.126 STDERR [market] tofu: │ An argument named "labels" is not expected here.
In the module above, the ownership metadata moved into description, which you still see in gcloud compute backend-services list and in Cloud Asset Inventory searches. Resources that do support labels, such as the forwarding rule, keep them.
Error: Invalid index on an empty tuple
The old module picked the backend with a lookup() over a map that referenced every NEG type with [0]. OpenTofu evaluates the whole map, so the NEG types that have count = 0 break the plan even though they are never selected:
11:22:10.328 STDERR [docs] tofu: │ Error: Invalid index
11:22:10.328 STDERR [docs] tofu: │
11:22:10.328 STDERR [docs] tofu: │ on main.tf line 39, in locals:
11:22:10.328 STDERR [docs] tofu: │ 39: "cloud_run" = google_compute_region_network_endpoint_group.cloud_run[0].id
11:22:10.328 STDERR [docs] tofu: │ ├────────────────
11:22:10.328 STDERR [docs] tofu: │ │ google_compute_region_network_endpoint_group.cloud_run is empty tuple
11:22:10.328 STDERR [docs] tofu: │
11:22:10.328 STDERR [docs] tofu: │ The given key does not identify an element in this collection value: the
11:22:10.328 STDERR [docs] tofu: │ collection has no elements.
one(resource[*].id) returns null for an empty list, and coalesce() takes the first non-null value, so the version above plans for either backend type. We also dropped the backend bucket option the old module carried, because a backend bucket is its own URL map target and can’t sit inside a backend service’s backend block.
Wire the units without a dependency cycle
Dependencies point one way: services read the shared IP and DNS zone, and gxlb reads the services. The earlier edition had each service unit also read url_map_name from gxlb, while gxlb needed every service’s backend, which is a loop. Terragrunt refuses to build a run queue from it:
$ (cd live/lab/. && terragrunt run --all plan)
11:20:51.893 INFO TIP (debugging-docs): For help troubleshooting errors, visit https://docs.terragrunt.com/troubleshooting/debugging
11:20:51.893 ERROR cycle detected during queue construction
[exit=1 elapsed=.089581379s]
Notice the error doesn’t name the units. You get a better hint from terragrunt dag graph, which warns about the cycle, drops the units involved and prints what’s left, so whatever is missing from the graph is in the loop. Here only two units survived, which pointed straight at market and gxlb.
11:21:05.891 WARN Cycle detected in dependency graph, attempting removal of cycles.
digraph {
"docs" ;
"docs" -> "shared-certs";
"shared-certs" ;
}
The fixed live/lab/market/terragrunt.hcl depends on shared-certs only. The mock outputs matter on a fresh stack: without them, the first run --all plan fails with “detected no outputs. Either the target module has not been applied yet” because nothing has been applied for the dependency to read:
include "root" {
path = find_in_parent_folders("root.hcl")
}
terraform {
source = "../../../modules/service-onboarding"
}
dependency "certs" {
config_path = "../shared-certs"
mock_outputs_allowed_terraform_commands = ["validate", "plan"]
mock_outputs = {
dns_zone_name = "cfg-lab"
ip_address = "203.0.113.10"
}
}
inputs = {
name = "market"
hostname = "market.cfg-lab.computingforgeeks.com"
dns_zone_name = dependency.certs.outputs.dns_zone_name
shared_lb_ip = dependency.certs.outputs.ip_address
backend_type = "cloud_run"
backend_ref = "market"
environment = "lab"
}
Your docs unit is identical apart from backend_type = "internet_neg" and an FQDN in backend_ref. The gxlb unit then reads both host rules and passes them to the URL map module as a map, so onboarding a third service means one new unit directory plus one line in this host_rules block:
dependency "market" {
config_path = "../market"
mock_outputs_allowed_terraform_commands = ["validate", "plan"]
mock_outputs = { url_map_host_rule = local.mock_rule }
}
dependency "docs" {
config_path = "../docs"
mock_outputs_allowed_terraform_commands = ["validate", "plan"]
mock_outputs = { url_map_host_rule = local.mock_rule }
}
inputs = {
ip_address = dependency.certs.outputs.ip_address
cert_map_id = dependency.certs.outputs.cert_map_id
default_service_key = "market"
host_rules = {
market = dependency.market.outputs.url_map_host_rule
docs = dependency.docs.outputs.url_map_host_rule
}
}
With the cycle gone, the whole stack plans in about seven seconds. Write the plans as JSON at the same time, because the gate reads those files:
cd live/lab
terragrunt run --all plan --json-out-dir ../../plans
Four units, 15 resources, exit code 0:
11:22:25.045 STDOUT [shared-certs] tofu: Plan: 5 to add, 0 to change, 0 to destroy.
11:22:26.991 STDOUT [market] tofu: Plan: 3 to add, 0 to change, 0 to destroy.
11:22:27.000 STDOUT [docs] tofu: Plan: 4 to add, 0 to change, 0 to destroy.
11:22:30.768 STDOUT [gxlb] tofu: Plan: 3 to add, 0 to change, 0 to destroy.
[exit=0 elapsed=7.052040841s]
--json-out-dir writes one tfplan.json per unit, under a directory named after the unit, which is what lets the gate know which unit proposed each resource.

Market and docs finish 9 ms apart because Terragrunt plans independent units in parallel, while shared-certs leads and gxlb trails because of the dependency graph. The gate in the next step reads the JSON files those runs left behind.
Block per-service certs in CI
The gate rejects any plan that creates a compute SSL certificate anywhere, a Certificate Manager resource outside shared-certs, or a forwarding rule or HTTPS proxy outside gxlb. Those three rules cover the ways to stand up a second TLS frontend on a global external ALB. If your teams also run regional or proxy load balancers, add google_compute_region_ssl_certificate to the cert list and google_compute_region_target_https_proxy, google_compute_forwarding_rule and google_compute_target_ssl_proxy to the frontend list.
Match on the unit, not the resource address. The earlier edition of this guide matched on module. prefixes in a Conftest policy, but every Terragrunt unit is its own root module, so the addresses carry no prefix at all. The plan for the two owner units shows it:
jq -r '.resource_changes[] | .address' ../../plans/shared-certs/tfplan.json ../../plans/gxlb/tfplan.json
An address rule written for a single root module would deny the shared wildcard cert itself and the shared forwarding rule, because both look exactly like the ones a rogue service would add:
google_certificate_manager_certificate.wildcard
google_certificate_manager_certificate_map.shared
google_certificate_manager_certificate_map_entry.wildcard
google_compute_global_address.lb
google_dns_managed_zone.lab
google_compute_global_forwarding_rule.https
google_compute_target_https_proxy.shared
google_compute_url_map.shared
So ci/sprawl-gate.sh takes the unit name from the plan’s directory and applies the rules per unit. It needs only bash and jq, which GitHub-hosted Ubuntu runners include. On a container-based runner, add jq to the job image:
#!/usr/bin/env bash
# Usage: ci/sprawl-gate.sh <json-out-dir> (from: terragrunt run --all plan --json-out-dir <dir>)
set -euo pipefail
plans=${1:?json-out-dir from terragrunt run --all plan}
violations=""
while IFS= read -r f; do
unit=$(basename "$(dirname "$f")")
hits=$(jq -r --arg unit "$unit" '
.resource_changes[]?
| select(.change.actions | index("create"))
| select(
(.type | IN("google_compute_managed_ssl_certificate", "google_compute_ssl_certificate"))
or ((.type | startswith("google_certificate_manager_")) and $unit != "shared-certs")
or ((.type | IN("google_compute_global_forwarding_rule", "google_compute_target_https_proxy")) and $unit != "gxlb")
)
| "DENY \($unit): \(.address) (\(.type)) must go through the shared cert map and gxlb"
' "$f")
[ -n "$hits" ] && violations+="$hits"$'\n'
echo "checked $unit"
done < <(find "$plans" -name tfplan.json | sort)
if [ -n "$violations" ]; then
printf '%s' "$violations"
exit 1
fi
echo "sprawl gate: no per-service certs or frontends in this plan"
Go back to the repo root with cd ../.. and run it against the clean plan. It finishes in 0.05 seconds and passes:
ci/sprawl-gate.sh plans
All four units are checked:
checked docs
checked gxlb
checked market
checked shared-certs
sprawl gate: no per-service certs or frontends in this plan
To prove it bites, we added the classic sprawl pattern to the market unit: a Google-managed cert, its own URL map, a target HTTPS proxy and a forwarding rule. The file is lab/bad-pr-legacy-cert.tf in the repo. Copy it into the unit, plan into a separate directory and run the gate, all from the repo root:
cp lab/bad-pr-legacy-cert.tf live/lab/market/
(cd live/lab && terragrunt run --all plan --json-out-dir ../../plans-bad)
ci/sprawl-gate.sh plans-bad
The market plan grew from 3 to 7 resources, and the gate failed the run with exit code 1:
checked docs
checked gxlb
checked market
checked shared-certs
DENY market: google_compute_global_forwarding_rule.market (google_compute_global_forwarding_rule) must go through the shared cert map and gxlb
DENY market: google_compute_managed_ssl_certificate.market (google_compute_managed_ssl_certificate) must go through the shared cert map and gxlb
DENY market: google_compute_target_https_proxy.market (google_compute_target_https_proxy) must go through the shared cert map and gxlb
You’ll notice the extra URL map isn’t denied on its own. Without a proxy and forwarding rule it can’t serve traffic or hold a cert, so blocking it would just add noise. Delete the copy with rm live/lab/market/bad-pr-legacy-cert.tf before you apply, or the next step creates exactly the sprawl the gate exists to stop. In CI, run terragrunt run --all plan --json-out-dir plans followed by ci/sprawl-gate.sh plans as a required check on every pull request that touches live/, and the merge button stays grey until the PR uses the module.

The bad run exited 1 in under a tenth of a second, so the check adds nothing noticeable to a pipeline that already waits on the plan.
Apply the stack and read the certificate inventory
Apply runs the units in dependency order and took 2 minutes 23 seconds end to end. The slowest single resource was the market backend service at 56 seconds. On the frontend side, the forwarding rule took 23 seconds, the URL map 13 and the proxy 11:
cd live/lab
terragrunt run --all apply
Here are the last lines from each unit, as they finished.
11:33:23.982 STDOUT [shared-certs] tofu: Apply complete! Resources: 5 added, 0 changed, 0 destroyed.
11:33:49.109 STDOUT [docs] tofu: Apply complete! Resources: 4 added, 0 changed, 0 destroyed.
11:34:32.363 STDOUT [market] tofu: google_compute_backend_service.this: Creation complete after 56s
11:34:32.597 STDOUT [market] tofu: Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
11:34:46.920 STDOUT [gxlb] tofu: google_compute_url_map.shared: Creation complete after 13s
11:34:58.424 STDOUT [gxlb] tofu: google_compute_target_https_proxy.shared: Creation complete after 11s
11:35:21.363 STDOUT [gxlb] tofu: google_compute_global_forwarding_rule.https: Creation complete after 23s
11:35:21.594 STDOUT [gxlb] tofu: Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
[exit=0 elapsed=143.541206941s at 2026-11-29T08:35:21Z]
Test both hostnames against the shared IP before touching public DNS. --resolve pins the name to the IP, and openssl s_client shows which cert the load balancer picked from the map:
LB_IP=$(gcloud compute addresses describe cfg-lab-shared-ip --global --format='value(address)')
for h in market docs; do curl -sk -o /dev/null --resolve $h.cfg-lab.computingforgeeks.com:443:$LB_IP -w "$h HTTP %{http_code} cert CN: " https://$h.cfg-lab.computingforgeeks.com/; echo | openssl s_client -connect $LB_IP:443 -servername $h.cfg-lab.computingforgeeks.com 2>/dev/null | openssl x509 -noout -subject -enddate | paste -sd' '; done
Two services, two backend types, one certificate:
market HTTP 200 cert CN: subject=CN=*.cfg-lab.computingforgeeks.com notAfter=Feb 27 08:20:36 2027 GMT
docs HTTP 200 cert CN: subject=CN=*.cfg-lab.computingforgeeks.com notAfter=Feb 27 08:20:36 2027 GMT
Both names return the same subject and the same expiry date, which proves the map entry is matching the hostnames rather than a cert per host:

Your gate only sees Terraform. A cert created by hand in the console never shows up in a plan, so the inventory has to come from GCP itself. To have something to find, we created the kind of cert the gate exists to stop, outside Terraform:
gcloud compute ssl-certificates create legacy-market-cert --domains market.cfg-lab.computingforgeeks.com --global
Then list both certificate APIs side by side. Certificate Manager holds the wildcard, the map and its entry. The classic compute API holds the stray:
gcloud certificate-manager certificates list
gcloud certificate-manager maps list
gcloud certificate-manager maps entries list --map cfg-lab-shared
gcloud compute ssl-certificates list
A healthy consolidated project has one Certificate Manager cert, one map entry in ACTIVE, and an empty compute list. Anything in that last table is sprawl:
NAME LOCATION SUBJECT_ALTERNATIVE_NAMES DESCRIPTION SCOPE EXPIRE_TIME CREATE_TIME UPDATE_TIME
cfg-lab-wildcard global *.cfg-lab.computingforgeeks.com 2027-02-27 08:20:36 +00:00 2026-11-29 08:33:00 +00:00 2026-11-29 08:33:00 +00:00
cfg-lab.computingforgeeks.com
NAME ENDPOINTS DESCRIPTION CREATE_TIME
cfg-lab-shared 203.0.113.10:443 2026-11-29 08:33:00 +00:00
NAME DESCRIPTION HOSTNAME MATCHER CERTIFICATES STATE CREATE_TIME
wildcard *.cfg-lab.computingforgeeks.com cfg-lab-wildcard ACTIVE 2026-11-29 08:33:12 +00:00
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME REGION MANAGED_STATUS
legacy-market-cert MANAGED 2026-11-29T00:44:54.553-08:00 PROVISIONING
market.cfg-lab.computingforgeeks.com: PROVISIONING
The stray stays in PROVISIONING because nothing serves it, and that is exactly how a forgotten per-service cert looks in a real project:

For an organization or folder, Cloud Asset Inventory answers the same question in one call across every project. It uses the cloudasset.googleapis.com API enabled at the start. Search both asset types:
gcloud asset search-all-resources --scope=projects/$GOOGLE_PROJECT --asset-types='certificatemanager.googleapis.com/Certificate,compute.googleapis.com/SslCertificate' --format='table(assetType.basename(),displayName,location,createTime.date(%Y-%m-%dT%H:%M))'
Indexing isn’t instant. Our first search, 18 seconds after the stray cert was created, found only the wildcard. The same search two minutes after creation listed both, so give a scheduled inventory job a few minutes of slack before you trust an empty result:
ASSET_TYPE DISPLAY_NAME LOCATION CREATE_TIME
SslCertificate legacy-market-cert global 2026-11-29T08:44
Certificate cfg-lab-wildcard global 2026-11-29T08:33
Swap projects/ for organizations/<id> in the scope and the same query becomes the org-wide sprawl report that the certificate sprawl audit earlier in the series did by hand.
Detect drift with a detailed exit code
-detailed-exitcode turns a plan into a drift check: exit 0 means no changes, 2 means the live project differs from the code, and 1 is an error. To create real drift, we changed the market record’s TTL from 300 to 60 with gcloud, the way someone in a hurry would:
gcloud dns record-sets update market.cfg-lab.computingforgeeks.com. --zone cfg-lab --type A --ttl 60 --rrdatas $LB_IP
A plan of that unit alone, terragrunt plan -detailed-exitcode run inside live/lab/market, caught it in 2.1 seconds. For a scheduled check you want the whole stack, run from live/lab. Everything after -- goes to OpenTofu unchanged:
terragrunt run --all plan -- -detailed-exitcode
Across the whole stack the scan took 7.4 seconds and pinned the drift to one unit, with exit code 2:
11:47:11.920 STDOUT [shared-certs] tofu: No changes. Your infrastructure matches the configuration.
11:47:14.141 STDOUT [market] tofu: Plan: 0 to add, 1 to change, 0 to destroy.
11:47:14.397 STDOUT [docs] tofu: No changes. Your infrastructure matches the configuration.
11:47:16.813 STDOUT [gxlb] tofu: No changes. Your infrastructure matches the configuration.
[exit=2 elapsed=7.407344126s]
The market plan shows exactly what moved, ~ ttl = 60 -> 300, and terragrunt apply in that unit put it back in 5.7 seconds. At under ten seconds for four units, a scheduled drift job every hour costs almost nothing, so run it from CI on a cron and alert on exit code 2. Treat exit 1 separately, since that usually means expired credentials rather than drift.

Read the exit code, not the log volume: three units reporting no changes and one Plan line still add up to exit 2 for the whole run.
Install Argo CD on GKE Autopilot
Terraform owns the load balancer, certs and DNS. ArgoCD owns what runs inside GKE, so a bad Deployment can’t break the URL map and a bad URL map change can’t roll back a Deployment. We used a fresh Autopilot cluster in the same region:
gcloud container clusters create-auto cfg-gitops --region europe-west1 --network default
gcloud container clusters get-credentials cfg-gitops --region europe-west1
Get the latest release tag from GitHub, then create the namespace. The Argo CD releases page lists the patch lines that are still supported:
ARGOCD_VERSION=$(curl -s https://api.github.com/repos/argoproj/argo-cd/releases/latest | jq -r .tag_name)
echo $ARGOCD_VERSION
kubectl create namespace argocd
Install with server-side apply. The plain kubectl apply that most install guides still show fails on current releases:
kubectl apply -n argocd --server-side --force-conflicts -f https://raw.githubusercontent.com/argoproj/argo-cd/${ARGOCD_VERSION}/manifests/install.yaml
Server-side apply is the method the Argo CD install docs now use, and the same command handles upgrades. Be aware that --force-conflicts overwrites any hand edits you made to fields the manifests define, such as env or probes.
Error: metadata.annotations: Too long: may not be more than 262144 bytes
Our first install used client-side apply. Every other object went in, but the ApplicationSet CRD was refused, buried under the Autopilot warnings, so a script that only greps for failures in the last line can miss it:
The CustomResourceDefinition "applicationsets.argoproj.io" is invalid: metadata.annotations: Too long: may not be more than 262144 bytes
Client-side apply stores the whole object in the last-applied-configuration annotation, and that CRD is now larger than the 256 KiB annotation limit. Server-side apply doesn’t write that annotation. Rerunning the server-side command above over the half-finished install fixed it in 24 seconds, and all three CRDs were present afterwards. Autopilot also printed a warning per Deployment about defaulted CPU requests. Those are harmless, because Autopilot fills in requests the upstream manifests leave out.
Wait for the controller and server before bootstrapping anything. On Autopilot this took 1 minute 29 seconds, most of it node provisioning:
kubectl -n argocd rollout status deploy/argocd-server deploy/argocd-repo-server --timeout=600s
kubectl -n argocd rollout status statefulset/argocd-application-controller --timeout=600s
kubectl -n argocd get pods
Seven pods, all running:
NAME READY STATUS RESTARTS AGE
argocd-application-controller-0 1/1 Running 0 119s
argocd-applicationset-controller-7cd67d655c-sdd2p 1/1 Running 0 2m2s
argocd-dex-server-7c77d84d6c-bk6zg 1/1 Running 0 2m2s
argocd-notifications-controller-64df646d69-b8knk 1/1 Running 0 2m2s
argocd-redis-7d4685fcf9-qhddt 1/1 Running 0 2m2s
argocd-repo-server-58d85877fd-czvs7 1/1 Running 0 2m
argocd-server-7f796d8475-zrr8k 1/1 Running 0 119s
The application controller runs as a StatefulSet, which is why its pod name ends in -0 instead of a hash:

Everything below drives ArgoCD through its CRDs with kubectl. If you’d rather use the argocd binary, the ArgoCD CLI reference covers login and the app commands.
Bootstrap the app-of-apps
One root Application watches argocd/apps/, and each file in that directory is a child Application for one service. After the root is applied once, onboarding a workload is a pull request that adds a file there, so nobody needs cluster-admin to ship a service. Here is the root, argocd/bootstrap/platform-apps.yaml:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: platform-apps
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/c4geeks/gcp-cert-guardrails.git
targetRevision: HEAD
path: argocd/apps
directory:
recurse: true
destination:
server: https://kubernetes.default.svc
namespace: argocd
syncPolicy:
automated:
prune: true
The child, argocd/apps/food-web.yaml, turns on self-heal so ArgoCD reverts manual changes in the cluster. CreateNamespace=true lets the service team skip a separate namespace step:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: food-web
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/c4geeks/gcp-cert-guardrails.git
targetRevision: HEAD
path: apps/food-web
destination:
server: https://kubernetes.default.svc
namespace: cfg-demo
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
Both manifests are shown as they sit in the companion repo. Your clone has your fork’s URL in them after the sed at the start, so apply the root from the repo root of your clone:
kubectl apply -f argocd/bootstrap/platform-apps.yaml
kubectl -n argocd get applications
Within 19 seconds of the root going in, the child Application was created, synced and healthy.
NAME SYNC STATUS HEALTH STATUS
food-web Synced Healthy
platform-apps Synced Healthy
The root has no selfHeal on purpose. Without it, automated sync runs once per new commit, so if someone edits a child Application by hand during an incident, the root leaves that edit alone until the next push to the repo or a manual sync. Turn selfHeal on for the root only if you want hand edits to child Applications reverted within seconds.
Measure self-heal and Git sync times
Self-heal undid a scale-down in seconds, while a Git change waited for the next poll and took over two minutes. We timed both by polling the cluster every half second while breaking things by hand:
| Change | Back in sync after |
|---|---|
kubectl scale --replicas=0, first time | 4.4 s (pods ready at 6.0 s) |
| Same scale-down, three more runs | 3.8 s, 1.0 s, 1.0 s |
kubectl delete service food-web | 32.9 s |
Commit a replicas change to Git (2 to 3; the repo now ships 3, so pick another number) | 134 s |
Why did the deleted Service take 33 seconds? Self-heal backoff. Each repeated self-heal of the same revision waits longer than the last, and the application controller logs show how long is left before the next attempt:
kubectl -n argocd logs statefulset/argocd-application-controller --since=10m | grep food-web | grep "retrying in"
Trimmed to the message field, the waits run from under 2 seconds to 2 minutes 41 seconds:
Skipping auto-sync: already attempted sync to [593d3161edb9826217c25991147e5e538c05f6ba] with timeout 0s (retrying in 1.85577178s)
Skipping auto-sync: already attempted sync to [593d3161edb9826217c25991147e5e538c05f6ba] with timeout 0s (retrying in 5.553828654s)
Skipping auto-sync: already attempted sync to [593d3161edb9826217c25991147e5e538c05f6ba] with timeout 0s (retrying in 52.947528093s)
Skipping auto-sync: already attempted sync to [593d3161edb9826217c25991147e5e538c05f6ba] with timeout 0s (retrying in 32.139576413s)
Skipping auto-sync: already attempted sync to [593d3161edb9826217c25991147e5e538c05f6ba] with timeout 0s (retrying in 2m41.601587325s)
That matches the application controller defaults: a 2 second initial backoff, a factor of 3 and a 300 second cap. If something in the cluster keeps fighting ArgoCD, such as an HPA changing replicas on a Deployment that also sets them, expect repairs to slow to minutes rather than seconds. Leave replicas out of Git for anything an autoscaler owns.
The Git change took 134 seconds with timeout.reconciliation unset in argocd-cm. ArgoCD’s default is a 120 second poll plus up to 60 seconds of jitter, so expect anywhere up to three minutes. If that’s too slow for a rollback, add a GitHub webhook to argocd-server rather than shortening the poll for every repo.
Roll back one service at a time
Rolling back a service touches only that service on both sides. For the infrastructure, destroy the service’s unit or revert the PR that added it: the module owns a DNS record, a NEG and a backend service, so that’s all a destroy can remove. The teardown at the end of this guide shows the order, with services destroyed before the shared cert map is touched. For the workload, revert the commit in Git and auto-sync applies it on the next poll.
Deleting an Application is different, and the earlier edition of this guide had it wrong. Without the resources-finalizer.argocd.argoproj.io finalizer, deleting an Application leaves everything it deployed running. We deleted food-web and listed its namespace straight away:
kubectl -n argocd delete application food-web
kubectl -n cfg-demo get deploy,svc
Both the Deployment and the Service were untouched.
application.argoproj.io "food-web" deleted from argocd namespace
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/food-web 3/3 3 3 8m39s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/food-web ClusterIP 34.118.230.244 <none> 80/TCP 6m7s
The root recreated the child 168.7 seconds later, but only because Git held a commit the root had not synced yet: our replicas change from the previous section. Without selfHeal, automated sync runs once per commit, so with no new commit the child stays deleted until someone syncs the root or pushes to the repo. For a real decommission, delete the child’s file from argocd/apps/ and add the finalizer to the child’s metadata first, so pruning the Application also removes its workload. Leave the finalizer off the root, or deleting the root during maintenance removes every service at once.

The restore only came when the root’s next reconcile picked up the newer commit, so build any recovery runbook around the reconcile interval rather than expecting an instant restore.
Pin provider versions in one place
Each module that other teams consume should carry its own versions.tf, so the module works outside Terragrunt and a tag pins a known provider range. That collides with a Terragrunt root that also generates a required_providers block into every unit, and OpenTofu refuses to plan:
Error: Duplicate required providers configuration
on versions.tf line 3, in terraform:
3: required_providers {
A module may have only one required providers configuration. The required
providers were previously configured at provider.tf:4,3-21.
Keep the version constraints in the modules and let root.hcl generate only the provider "google" block with project and region. That’s how the companion repo is now laid out. Each module’s versions.tf reads:
terraform {
required_version = ">= 1.9"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 8.12"
}
}
}
With that split, run --all plan initialized and planned all four units again on google provider 8.12.0, and the service-onboarding module also passed terraform validate on HashiCorp Terraform 1.17, so teams on either binary can consume it. Consumers then pin a tag in the unit’s source line, for example source = "git::https://github.com/your-org/infra-modules.git//service-onboarding?ref=v1.2.0". Never point it at a branch, because every commit to that branch becomes a production change for every service. If you’re new to either binary, the Terraform and OpenTofu install guide sets up both side by side.
Tear down the lab
Terragrunt destroys in reverse dependency order, so the frontend goes first and the shared cert map last. Run it from live/lab, as with the apply. Our stack of 15 resources was gone in 2 minutes 19 seconds:
terragrunt run --all destroy
Last to go is shared-certs, and the cert map entry has to be deleted before the map and certificate it points at:
11:54:47.549 STDOUT [docs] tofu: Destroy complete! Resources: 4 destroyed.
11:54:57.152 STDOUT [market] tofu: Destroy complete! Resources: 3 destroyed.
11:54:59.980 STDOUT [shared-certs] tofu: Plan: 0 to add, 0 to change, 5 to destroy.
11:55:12.013 STDOUT [shared-certs] tofu: google_certificate_manager_certificate_map_entry.wildcard: Destruction complete after 12s
11:55:22.968 STDOUT [shared-certs] tofu: google_certificate_manager_certificate.wildcard: Destruction complete after 11s
11:55:23.376 STDOUT [shared-certs] tofu: google_certificate_manager_certificate_map.shared: Destruction complete after 11s
11:55:23.522 STDOUT [shared-certs] tofu: Destroy complete! Resources: 5 destroyed.
[exit=0 elapsed=138.612443596s at 2026-11-29T08:55:23Z]
Anything you created outside Terraform needs its own cleanup, namely the stray compute cert, the Cloud Run service, the GKE cluster and the state bucket. Delete them with gcloud.
gcloud compute ssl-certificates delete legacy-market-cert --global --quiet
gcloud run services delete market --region europe-west1 --quiet
gcloud container clusters delete cfg-gitops --location europe-west1 --quiet
gcloud storage rm -r gs://${TG_STATE_BUCKET}
Keep the module, the gate and the app-of-apps in version control, since those are what keep the next service on the shared path. The pattern holds up because it doesn’t depend on reviewers: the module has no certificate inputs, the gate fails any plan that adds certs elsewhere, and Asset Inventory catches the click-ops certs neither of them can see. The zero-incident rotation demo runs a full app on this stack and rotates the wildcard live, and the expiry alerting runbook covers the monitoring side.