# GCP One-to-One Image Builder

This recipe launches a single GCP VM, creates a reusable GCP disk image from it, and tears the VM down when work is complete.

## Recipes

### provision-gcp-vm-via-script

Starts one VM from the selected image or the optional exact custom image. Choose
the operating system, machine type, boot disk size, and approved source network
before launch. A cleanup job is scheduled for 12 hours later.

### destroy-gcp-vm-via-script

Destroys the current VM and Terraform-managed cloud resources for the page and
scope. Running this manually cancels the pending 12-hour cleanup job.

### create-image-from-instance

Creates a reusable GCP disk image from the current host. The image step may briefly stop the VM if GCP requires the boot disk to be detached for imaging, then it starts the VM again. The output ends with a clear `SUCCESS` or `ERROR` message.

Write down the image name after a successful create. To launch it later, use
`provision-gcp-vm-via-script` and supply that exact name as `CUSTOM_IMAGE`.

### list-created-images

Lists images already created by this user. The lookup is filtered by the `lemc_username` image label, and results are printed to the recipe terminal and written to `image-list.txt`.

## Network Access

Set `SOURCE_CIDR` to the smallest approved network prefix that can reach the
VM. Prefer the operator's single public IPv4 address with `/32`. If the value
is missing, the image uses `127.0.0.1/32`, which permits no useful remote
ingress. Do not use `0.0.0.0/0` for a maintained deployment.

## Resource Tags

Set `RESOURCE_TAGS` to a comma-separated list to add searchable labels/tags to VMs and created images:

```text
purpose=demo, sample
```

`key=value` entries become GCP labels. Plain entries become labels like
`tag_sample=true`. VMs also receive matching network tags plus a dynamic
`lemc-user-<username>` network tag.

## Image Naming

Use a name that is easy to trace:

```text
sample-{workload-name}-YYYYMMDD-v1
```

Example:

```text
sample-data-processing-20260128-v1
```

## Useful Outputs

After launch:

- `private-ssh-key`
- `dotenv`

After image creation:

- `image-info.txt`: short success summary and image name
- `image-details.json`: full GCP image details
- `image-error.txt`: short failure summary when image creation fails
- `image-list.txt`: images found by `list-created-images`

## Cleanup

Provision schedules a destroy step 12 hours later so build hosts do not
linger. Image creation does not cancel that cleanup timer. Use
`destroy-gcp-vm-via-script` when finished early.
