Skip to content

Instantly share code, notes, and snippets.

@joshlove
Created February 6, 2017 00:58
Show Gist options
  • Select an option

  • Save joshlove/d7e9abb0881971e815651c95d52bf4f3 to your computer and use it in GitHub Desktop.

Select an option

Save joshlove/d7e9abb0881971e815651c95d52bf4f3 to your computer and use it in GitHub Desktop.
Import EC2 instances into terraform
#!/usr/bin/env bash
IFS=$'\n'
for each in $(aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value | [0]]' --output text);
do
instance=$(echo $each | cut -d$'\t' -f1)
name=$(echo $each | cut -d$'\t' -f2)
terraform import aws_instance.${name} ${instance}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment