Skip to content

clowdhaus/terraform-aws-ebs-snapshot-builder

Repository files navigation

AWS EBS Snapshot Builder Terraform module

Terraform module to provision an EBS snapshot builder state machine on AWS.

Usage

See examples directory for working examples to reference:

module "ebs_snapshot_builder" {
  source = "clowdhaus/ebs-snapshot-builder/aws"

  name = "example"
  
  # Images to cache
  public_images = [
    "nvcr.io/nvidia/k8s-device-plugin:v0.16.2", # 120 MB compressed / 351 MB decompressed
    "nvcr.io/nvidia/pytorch:24.08-py3",         # 9.5 GB compressed / 20.4 GB decompressed
  ]

  # AZs where EBS fast snapshot restore will be enabled
  fsr_availability_zone_names = ["us-east-1a", "us-east-1b", "us-east-1c"]

  vpc_id    = "vpc-1234556abcdef"
  subnet_id = "subnet-abcde012"

  tags = {
    Terraform   = "true"
    Environment = "dev"
  }
}

Examples

Examples codified under the examples are intended to give users references for how to use the module(s) as well as testing/validating changes to the source code of the module. If contributing to the project, please be sure to make any appropriate updates to the relevant examples to allow maintainers to test your changes and to keep the examples up to date for users. Thank you!

Requirements

Name Version
terraform >= 1.3
aws >= 5.68

Providers

Name Version
aws >= 5.68

Modules

Name Source Version
security_group terraform-aws-modules/security-group/aws ~> 5.0
state_machine terraform-aws-modules/step-functions/aws ~> 4.2

Resources

Name Type
aws_iam_instance_profile.ec2 resource
aws_iam_role.ec2 resource
aws_iam_role_policy_attachment.ec2_role resource
aws_ssm_parameter.snapshot_id resource
aws_iam_policy_document.ec2_assume_role data source
aws_iam_policy_document.state_machine data source
aws_partition.current data source
aws_region.current data source
aws_ssm_parameter.eks_ami data source

Inputs

Name Description Type Default Required
cpu_architecture The CPU architecture of the instance. Either amd64 or arm64 string "amd64" no
create Controls if resources should be created (affects nearly all resources) bool true no
default_values A map of default values to use for the state machine
object({
enable_fast_snapshot_restore = optional(bool, true)
snapshot_name = optional(string, "ml-container-cache")
snapshot_description = optional(string, "ML container image cache")
})
{} no
ebs_volume_settings A map of EBS volume settings that will be used on the volumes (root + additional) attached to the instance created
object({
iops = optional(number, 6000),
throughput = optional(number, 500),
volume_size = optional(number, 64),
})
{} no
ecr_images A list of ECR images to pull list(string) [] no
eks_version The EKS version for the respective EKS AMI that will be used to create the EC2 instance string "1.31" no
fsr_availability_zone_names A list of availability zone names where EBS Fast Snapshot Restore will be enabled list(string) [] no
instance_type The instance type to launch string "c6in.16xlarge" no
name The name of the state machine string "" no
public_images A list of images to pull from public registries list(string) [] no
security_group_egress_rules A list of egress rules to add to the security group any
[
{
"cidr_blocks": "0.0.0.0/0",
"from_port": 0,
"protocol": "-1",
"to_port": 0
}
]
no
ssm_parameter_name The name of the SSM parameter to create for storing the created snapshot ID string null no
state_machine_tags A map of addititional tags to add to the state machine map(string) {} no
subnet_id The subnet ID where the EC2 instance will be launched string "" no
tags A map of tags to add to all resources map(string) {} no
vpc_id The VPC ID where the intance and security group will be created string "" no

Outputs

Name Description
ssm_parameter_arn The ARN of the SSM parameter storing the snapshot name
ssm_parameter_name The name of the SSM parameter storing the snapshot name
start_execution_command Example awscli command to start the state machine execution

License

Apache-2.0 Licensed. See LICENSE.