diff --git a/tools/terraform.sh b/tools/terraform.sh index 9b4a56e..7cd6e45 100644 --- a/tools/terraform.sh +++ b/tools/terraform.sh @@ -28,7 +28,6 @@ complete -C "$(command -v terraform)" terraform alias tf_destroy='terraform destroy' alias tf_init='terraform init' -alias tf_import='terraform import' alias tf_output='terraform output' alias tf_providers='terraform providers' @@ -66,6 +65,18 @@ function tf_apply { terraform fmt } +function tf_import { + local resource=$1 + local aws_address=$2 + + if terraform import "${resource}" "${aws_address}"; then + gum spin \ + --show-output \ + --title "Loading imported '${resource}' ..." \ + terraform state show "${resource}" | tee >(to_clipboard) + fi +} + function tf_pin_provider_versions { local versions="versions.tf" diff --git a/tools/utils.sh b/tools/utils.sh index 51e6ccd..8fd8a11 100644 --- a/tools/utils.sh +++ b/tools/utils.sh @@ -2,3 +2,13 @@ __lazy_install pre-commit __lazy_install shellcheck + +function to_clipboard { + if [[ ${platform} == "darwin" ]]; then + echo "ℹ️ copied to clipboard" + pbcopy < /dev/stdin + else + echo "⚠️ no implemented ... copy urself" + cat + fi +}