# 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.

This fork adds an optional Linux SSH port field for saved images that no longer listen on port 22.

## Buttons

### launch-single-host

Starts a fresh Debian build host. Choose the machine type and boot disk size before launch. A cleanup job is scheduled for 12 hours later.

### launch-from-machine-image

Starts a host from a previously saved GCP image. Paste the exact image name from the create-image success message or `image-info.txt`. Choose the operating system, machine type, and boot disk size. A cleanup job is scheduled for 12 hours later.

For Linux images, leave `SSH_PORT` blank to use port 22. Set `SSH_PORT` to a custom high port, such as `10022`, when launching an image whose `sshd` has been moved off the default port. Custom values must be from 10000 through 65535.

The launch output and `dotenv` file include the effective SSH port.

### destroy-single-host

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-host

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. You need that exact value for `launch-from-machine-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`.

## 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`

Example SSH command with a custom port:

```bash
ssh -i private-ssh-key -p 10022 user@VM_IP
```

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

Launch recipes schedule a destroy step 12 hours later so build hosts do not linger. The image creation page does not cancel that cleanup timer. Use `destroy-single-host` when finished early.
