Skip to content

Commit 2bbff32

Browse files
feat: opt-in non-authoritative project metadata
Add use_authoritative_project_metadata variable (default: true) to let users switch from google_compute_project_metadata (authoritative) to per-key google_compute_project_metadata_item resources. Existing deployments see no change on upgrade. Users who share the GCP project with other metadata sources can opt in by setting the variable to false and running the documented state migration. Co-authored-by: Ona <no-reply@ona.com>
1 parent ac3a34e commit 2bbff32

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,47 @@ for setup instructions, configuration options, and troubleshooting.
2626
The [`runner-with-networking`](./examples/runner-with-networking/) example
2727
provides a full infrastructure setup including VPC, DNS, and certificates.
2828

29+
## Project Metadata Mode
30+
31+
By default this module uses `google_compute_project_metadata` (authoritative),
32+
which manages **all** project-level metadata. Any metadata keys not declared in
33+
this module will be removed on `terraform apply`.
34+
35+
If other systems or Terraform modules manage project metadata in the same GCP
36+
project, set `use_authoritative_project_metadata = false` to switch to per-key
37+
`google_compute_project_metadata_item` resources. This only manages the keys
38+
the module needs (`enable-oslogin`, `gitpod-runner-id`) and leaves everything
39+
else untouched.
40+
41+
```hcl
42+
module "runner" {
43+
source = "gitpod-io/ona-runner/google"
44+
# ...
45+
use_authoritative_project_metadata = false
46+
}
47+
```
48+
49+
### Migrating an existing deployment to per-key metadata
50+
51+
Switching an existing deployment from authoritative to per-key requires a state
52+
migration. Without it, Terraform will try to destroy the old resource and create
53+
the new ones, which can fail or cause a brief metadata gap.
54+
55+
```bash
56+
# 1. Remove the old authoritative resource from state
57+
terraform state rm 'module.runner.google_compute_project_metadata.runner_metadata'
58+
59+
# 2. Import the individual keys into the new resources
60+
terraform import 'module.runner.google_compute_project_metadata_item.enable_oslogin[0]' 'projects/<PROJECT_ID>/enable-oslogin'
61+
terraform import 'module.runner.google_compute_project_metadata_item.runner_id[0]' 'projects/<PROJECT_ID>/gitpod-runner-id'
62+
63+
# 3. Apply — should show no changes
64+
terraform apply
65+
```
66+
67+
Replace `<PROJECT_ID>` with your GCP project ID and adjust the module path if
68+
your module block uses a different name.
69+
2970
## Releases
3071

3172
New stable releases are published roughly once a week. To get notified when a

runner-vm.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,29 @@ resource "google_compute_health_check" "runner" {
358358
}
359359

360360

361-
# Resource tagging for lifecycle management
361+
# Project metadata: authoritative (default) or per-key items.
362+
# Authoritative manages ALL project metadata — keys not in this block are removed.
363+
# Per-key items only touch the keys this module needs, leaving other metadata intact.
362364
resource "google_compute_project_metadata" "runner_metadata" {
365+
count = var.use_authoritative_project_metadata ? 1 : 0
363366
project = var.project_id
364367

365368
metadata = {
366369
"enable-oslogin" = "TRUE"
367370
"gitpod-runner-id" = var.runner_id
368371
}
369372
}
373+
374+
resource "google_compute_project_metadata_item" "enable_oslogin" {
375+
count = var.use_authoritative_project_metadata ? 0 : 1
376+
project = var.project_id
377+
key = "enable-oslogin"
378+
value = "TRUE"
379+
}
380+
381+
resource "google_compute_project_metadata_item" "runner_id" {
382+
count = var.use_authoritative_project_metadata ? 0 : 1
383+
project = var.project_id
384+
key = "gitpod-runner-id"
385+
value = var.runner_id
386+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,10 @@ variable "enable_agents" {
337337
default = true
338338
}
339339

340+
variable "use_authoritative_project_metadata" {
341+
description = "Use authoritative google_compute_project_metadata (true) or per-key google_compute_project_metadata_item (false). The authoritative resource manages ALL project metadata — keys not listed in this module will be removed. Set to false if other systems or Terraform modules manage project metadata in the same project. Switching from true to false on an existing deployment requires state migration (see README)."
342+
type = bool
343+
default = true
344+
}
345+
340346

0 commit comments

Comments
 (0)