Hedronite · Dev Lesson · Polyglot-Dev / Go · Mon 2026-09-14

Go Cloud Storage bucket — import-candidate census

List names Terraform can import. Do not invent HCL from the SDK.

Lesson Class: DevOps-Go (quatro fourth)
Paired Ops: GCS import + moved module refactor
Paired Dev: Python plan JSON census
Paired Cert: Associate import/moved/GCS IDs
Grounding: Lab 03 brownfield premise · cloud.google.com/go/storage
List
Buckets in the project.
ID
Name is the import candidate.
Bound
No Update/create/delete from this binary.
Print the names. Leave the import block to HCL review.

<!-- hal:authoritative:yaml -->

List names Terraform can import. Do not invent HCL from the SDK.

§I — Frame

Ops needs a real bucket name for an import block ID. Yesterday's Go inventory walked lifecycle and retention. Today print project buckets as import candidates: name, location, storage class, versioning. Leave Terraform authorship to humans.

§II — Sketch

ctx := context.Background()
client, err := storage.NewClient(ctx)
if err != nil {
    return err
}
defer client.Close()

it := client.Buckets(ctx, projectID)
for {
    battrs, err := it.Next()
    if err == iterator.Done {
        break
    }
    if err != nil {
        return err
    }
    // candidate import id == battrs.Name
    // also print battrs.Location, battrs.StorageClass, battrs.VersioningEnabled
}

Use iterator.Done correctly. Treat permission errors as WARN rows for best-effort scans.

Optional: accept a path to terraform state list output and mark buckets whose name already appears under a google_storage_bucket address as tracked, others as candidate. Do not call Terraform APIs from this binary; read a file the pipeline already produced.

§III — Boundaries

  1. No Bucket.Update and no bucket create/delete from the census binary.
  2. Project ID is required context.
  3. Align WARN strings with Ops/Dev so Maghrib can fold Go items into the Dev quiz (no Go quiz.html).
  4. Distinct from 09-13: do not emphasize lifecycle rule dumping; emphasize import ID readiness.

§IV — Closing

Print bucket names Terraform can put in import.id. Pair with Ops Lab 03/11 path. Leave module extraction and moved blocks to HCL review.

Related