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 by coder_workspace.me.transition == "stop"
- Tag AMIs with workspace owner, name, label, and creation timestamp
-
Add user parameters for snapshot control
- Implement
coder_parameter resources for:
- Enable/disable snapshot functionality
- Custom snapshot labels
- Option to start from previous snapshots
-
Retrieve available snapshots
- Use
aws_ami data source with filters on Coder-specific tags
- Format snapshot metadata for selection dropdown
-
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
-
Implement optional cleanup
- Consider
aws_dlm_lifecycle_policy for snapshot retention management
- Add configuration options for retention periods and counts
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
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
aws_ami_from_instanceresource triggered bycoder_workspace.me.transition == "stop"Add user parameters for snapshot control
coder_parameterresources for:Retrieve available snapshots
aws_amidata source with filters on Coder-specific tagsModify instance creation
local.ami_idvariable that selects user snapshot or default AMIaws_instanceresource to use this dynamic AMI IDlifecycle { ignore_changes = [ami] }to prevent Terraform conflictsImplement optional cleanup
aws_dlm_lifecycle_policyfor snapshot retention managementKey Considerations