Skip to content

[K9VULN-12163] feat(agentless-gcp): introduce agentless setup metadata#146

Merged
mohamed-challal merged 10 commits into
mainfrom
mohamed.challal/introduce-agentless-setup-metadata
Mar 5, 2026
Merged

[K9VULN-12163] feat(agentless-gcp): introduce agentless setup metadata#146
mohamed-challal merged 10 commits into
mainfrom
mohamed.challal/introduce-agentless-setup-metadata

Conversation

@mohamed-challal
Copy link
Copy Markdown
Contributor

@mohamed-challal mohamed-challal commented Mar 5, 2026

Summary

This PR reworks the GCP Agentless Scanning Cloud Shell setup script to better support additive deployments, users can run the script multiple times to add new scanner regions or projects to scan without destroying existing infrastructure.

Previously, re-running the script with a different region would cause Terraform to lose track of the previous region's provider, resulting in Error: Provider configuration not present errors and requiring a full destroy/redeploy cycle.

Changes

Deployment metadata (metadata.py — new)

  • Introduces a config.json metadata file stored in the GCS state bucket alongside the Terraform state.
  • Tracks: scanner project, all deployed regions, all projects to scan, created_at / modified_at timestamps.
  • On each deploy, reads existing metadata and merges current inputs with previously deployed state (union of regions and projects).
  • Uses GCS object generation preconditions (compare-and-swap) for safe concurrent writes.
  • Metadata is written only after a successful terraform apply.

Deploy flow (main.py)

  • Reads existing metadata before generating Terraform config.
  • Merges current run inputs with existing deployment state via Config.with_merged().
  • Generates Terraform config covering all regions and projects (existing + new).
  • Prints a clear diff showing which regions/projects are new vs. existing.
  • If Terraform state exists but metadata does not (old deployment), exits with an explicit message asking the user to destroy first.

Destroy flow (destroy.py)

  • Reads metadata from GCS to discover all deployed regions and projects (no longer requires SCANNER_REGIONS / PROJECTS_TO_SCAN env vars when metadata exists).
  • Falls back to environment variables if metadata is absent.
  • Deletes metadata file after successful terraform destroy.

Region validation (preflight.py)

  • Validates region IDs against the actual GCP Compute API (gcloud compute regions describe).
  • Runs validation concurrently using ThreadPoolExecutor for all regions in parallel.

Resource naming (terraform.py)

  • Abbreviates long region names in VPC names to stay within GCP's 63-character resource name limit (e.g., northamerica-northeast1na-ne1 in vpc_name).
  • Renamed Terraform module prefix from datadog_agentless_scanner_ to datadog_agentless_.
  • Renamed GCS backend prefix from agentless-scanner to datadog-agentless.
  • Updated unit tests.

How it works

Run 1 Run 2
Input regions us-east1 europe-west1
Input projects to cover project-a project-a, project-b
Merged regions us-east1 us-east1, europe-west1
Merged projects to cover project-a project-a, project-b
What Terraform does Creates scanner infra in us-east1, IAM for project-a Adds europe-west1 infra + project-b IAM bindings (us-east1 untouched)
Metadata after regions: [us-east1], projects: [project-a] regions: [europe-west1, us-east1], projects: [project-a, project-b]
{
  "version": 1,
  "scanner_project": "project-a",
  "regions": [
    "europe-west1",
    "us-east1"
  ],
  "projects_to_scan": [
    "project-a",
    "project-b"
  ],
  "created_at": "2026-03-05T17:13:47.909771+00:00",
  "modified_at": "2026-03-05T17:22:25.225663+00:00"
}

@mohamed-challal mohamed-challal self-assigned this Mar 5, 2026
@mohamed-challal mohamed-challal requested a review from a team as a code owner March 5, 2026 11:18
@mohamed-challal mohamed-challal merged commit 5315016 into main Mar 5, 2026
1 check passed
@mohamed-challal mohamed-challal deleted the mohamed.challal/introduce-agentless-setup-metadata branch March 5, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants