Skip to main content
Latest Documentation
This is the latest documentation for the Cloud Posse Reference Architecture. To determine which version you're currently using, please see Version Identification.

Module: ec2-ami-snapshot

Terraform module to easily generate AMI snapshots to create replica instances

Usage​

Create an AWS instance​

resource "aws_instance" "default" {
ami = "ami-408c7f28"
instance_type = "t1.micro"

tags = {
Name = "test1"
}
}

Create AMI from an AWS instance. Instance ID is required"​

module "tf_ami_from_instance" {
source = "git::https://github.com/cloudposse/tf_ami_from_instance.git?ref=master"
source_instance_id = "${aws_instance.web.id}"
stage = "${var.stage}"
namespace = "${var.namespace}"
name = "${var.name}"
attributes = "${var.attributes}"
tags = "${var.tags}"
}

Caveats​

  • Terraform will only keep the latest AMI snapshot (terraform will delete the previously generated AMI) See our Lamda based solution which avoids this pitfall: https://github.com/cloudposse/tf_lambda_ami_backup
  • This is is not compatible with autoscaling groups

Variables​

Required Variables​

source_instance_id (any) required

Optional Variables​

snapshot_without_reboot (string) optional


Default value: "true"

Context Variables​

The following variables are defined in the context.tf file of this module and part of the terraform-null-label pattern.

attributes (list(string)) optional

Additional attributes (e.g. policy or role)
Required: No

Default value: [ ]

delimiter (string) optional

Delimiter to be used between name, namespace, stage, etc.
Required: No

Default value: "-"

name (string) optional

The Name of the application or solution (e.g. bastion or portal)
Required: No

Default value: ""

namespace (string) optional

Namespace (e.g. cp or cloudposse)
Required: No

Default value: ""

stage (string) optional

Stage (e.g. prod, dev, staging)
Required: No

Default value: ""

tags (map(string)) optional

Additional tags (e.g. map('BusinessUnit','XYZ'))
Required: No

Default value: { }

Outputs​

ami_id

AMI ID depends on the instance type and region in which you're launching your stack. And IDs can change regularly, such as when an AMI is updated with software updates.

Dependencies​

Providers​

  • aws

Modules​

NameVersionSourceDescription
label0.2.0git::https://github.com/cloudposse/tf_label.gitn/a

Resources​

The following resources are used by this module:

Data Sources​

The following data sources are used by this module: