Browse the Repo

file-type-icon.circleci
file-type-icon.github
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconattach-eni
file-type-iconbin
file-type-iconREADME.md
file-type-iconinstall.sh
file-type-icondisable-instance-metadata
file-type-iconec2-backup
file-type-iconpersistent-ebs-volume
file-type-iconrequire-instance-metadata-service-version
file-type-iconroute53-helpers
file-type-iconsingle-server
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.github
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconattach-eni
file-type-iconbin
file-type-iconREADME.md
file-type-iconinstall.sh
file-type-icondisable-instance-metadata
file-type-iconec2-backup
file-type-iconpersistent-ebs-volume
file-type-iconrequire-instance-metadata-service-version
file-type-iconroute53-helpers
file-type-iconsingle-server
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

Attach ENI Scripts

This folder contains scripts you can use to attach Elastic Network Interfaces (ENIs) to your EC2 Instances.

  1. attach-eni: This script can be run on an EC2 instance to attach an ENI. You can specify the ENI by ID or by having the script search for the ENI by tag. Normally, you would use Terraform's aws_network_interface_attachment resource to do this, but this resource does not work in cases where you need to attach volumes dynamically, such as with Auto Scaling Groups.

    The script has been tested with Ubuntu 18.04, Ubuntu 20.04, AmazonLinux v1.x, and AmazonLinux v2.x, though it may work on other Linux distributions as well.

An ENI allows you to have IP addresses that remain static, even if the underlying EC2 Instances are changing.

Check out the attach-eni example for how to use these scripts with Terraform.

Installing the attach-eni script

You can install the attach-eni script using the Gruntwork Installer:

gruntwork-install --module-name "attach-eni" --repo "https://github.com/gruntwork-io/terraform-aws-server" --tag "0.1.10"

Using the attach-eni script

The attach-eni script has the following prerequisites:

  1. It must be run as root
  2. It must be run on an EC2 instance
  3. The EC2 instance must have an IAM role with permissions to search ENIs and EC2 tags, as well as attach ENIs (see the attach-eni example)
  4. The EC2 instance must have the AWS CLI and jq installed

Typically, you'll want to run the attach-eni script in the User Data of your EC2 instances so it attaches the ENI at boot time.

Here is an example usage:

attach-eni --eni-id eni-abcd1234

This will attach ENI eni-abcd1234 to the current Instance. Alternatively, you can also run the script as follows:

attach-eni --eni-with-same-tag Name

This tells the script to try find and attach an ENI with the same Name tag as the current 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?