Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconattach-eni
file-type-iconbastion-host
file-type-iconec2-backup
file-type-iconpersistent-ebs-volume
file-type-iconroute53-helpers
file-type-iconpacker
file-type-iconuser-data
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconmodules
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.adoc
file-type-iconcore-concepts.md
file-type-iconterraform-cloud-enterprise-private-module-...

Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconattach-eni
file-type-iconbastion-host
file-type-iconec2-backup
file-type-iconpersistent-ebs-volume
file-type-iconroute53-helpers
file-type-iconpacker
file-type-iconuser-data
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconmodules
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.adoc
file-type-iconcore-concepts.md
file-type-iconterraform-cloud-enterprise-private-module-...
Single EC2 Instance

Single EC2 Instance

Run a single EC2 instance for stateless or stateful apps. Supports IAM roles, EBS volumes, ENIs, and EIPs.

Code Preview

Preview the Code

mobile file icon

README.md

down

Route 53 Helpers Example

This folder contains an example of how to create an EC2 Instance that runs the add-dns-a-record script on boot to add a DNS A record pointing to the Instance's IP address.

How do you run this example?

To run this example, you need to do the following:

  1. Build an AMI using Packer
  2. Deploy the AMI using Terraform

These steps are described in detail next.

Build an AMI using Packer

The code that runs the EC2 instance in this example is an Amazon Machine Image (AMI) that has been defined in a Packer template under packer/build.json. To build an AMI from this template:

  1. Install Packer.
  2. Set up your AWS credentials as environment variables.
  3. Run packer build build.json to create the AMI in your AWS account. Note down the ID of this new AMI.

Deploy the AMI using Terraform

Now that you have an AMI, use Terraform to deploy it:

  1. Install Terraform.
  2. Open up vars.tf and set secrets at the top of the file as environment variables and fill in any other variables in the file that don't have defaults. This includes the ami variable which you should fill in with the ID of the AMI you just built with Packer.
  3. terraform get.
  4. terraform plan.
  5. If the plan looks good, run terraform apply.

When the templates are applied, Terraform will output the IP address of the EC2 instance. If you SSH to the instance, it should have a /data folder. This is the EBS volume. It should persist whatever data you put into it in between restarts of this EC2 instance.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?