Open
Description
Problem
Coder workspaces on AWS currently lack persistent state across workspace stop/start cycles beyond basic EC2 stop functionality. Users need the ability to snapshot their workspace state and resume from selected snapshots.
Proposed Solution
Create a Terraform module that enables AMI-based snapshots of EC2 instances when workspaces are stopped, with user-specified labels and selection options for workspace start.
Implementation Steps
-
Create AMI snapshots on workspace stop
- Use
aws_ami_from_instance
resource triggered bycoder_workspace.me.transition == "stop"
- Tag AMIs with workspace owner, name, label, and creation timestamp
- Use
-
Add user parameters for snapshot control
- Implement
coder_parameter
resources for:- Enable/disable snapshot functionality
- Custom snapshot labels
- Option to start from previous snapshots
- Implement
-
Retrieve available snapshots
- Use
aws_ami
data source with filters on Coder-specific tags - Format snapshot metadata for selection dropdown
- Use
-
Modify instance creation
- Create a
local.ami_id
variable that selects user snapshot or default AMI - Update
aws_instance
resource to use this dynamic AMI ID - Add
lifecycle { ignore_changes = [ami] }
to prevent Terraform conflicts
- Create a
-
Implement optional cleanup
- Consider
aws_dlm_lifecycle_policy
for snapshot retention management - Add configuration options for retention periods and counts
- Consider
Key Considerations
- Users need IAM permissions for AMI creation/management
- AMI creation takes time; handle workspace stop gracefully
- Implement cost control through snapshot cleanup policies
- Ensure proper tagging for snapshot organization
Metadata
Metadata
Assignees
Labels
No labels