Skip to content

Instantly share code, notes, and snippets.

@corkupine
Forked from jmlrt/tf-import-stack.sh
Created October 31, 2022 18:39
Show Gist options
  • Save corkupine/ac443a3d04cbfdedb2ad21950aaa2055 to your computer and use it in GitHub Desktop.
Save corkupine/ac443a3d04cbfdedb2ad21950aaa2055 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