Skip to content

Instantly share code, notes, and snippets.

@jmlrt
Created March 9, 2018 09:40
Show Gist options
  • Save jmlrt/308e0811c52ff80d2ab9db1969154837 to your computer and use it in GitHub Desktop.
Save jmlrt/308e0811c52ff80d2ab9db1969154837 to your computer and use it in GitHub Desktop.
import terraform stack resources helper
#!/usr/bin/env bash
# List terraform resources in the current directory and ask their arn to import them into terraform state
RESOURCES_LIST=$(awk -F\" '/^resource "/ {print $2"."$4}' *.tf)
for resource in ${RESOURCES_LIST}
do
read -p "Enter ARN for resource ${resource} (type none to not import it): " arn
if [[ ${arn} != "none" ]]
then
terraform import ${resource} ${arn}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment