Skip to content

Instantly share code, notes, and snippets.

@therve
Created September 7, 2020 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therve/d588869b89f0939a3ee051e91dce72f3 to your computer and use it in GitHub Desktop.
Save therve/d588869b89f0939a3ee051e91dce72f3 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Import an existing Datadog dashboard into a terraform file
# Usage:
#
# $ get-dashboard.sh $dashboard_name $dashboard_id $output_file
#
# Where:
# dashboard_name is the local Terraform name of your dashboard resource
# dashboard_id is the short dashboard ID in Datadog
# output_file is the terraform file which will contain the imported resource
NAME=$1
DASHBOARD_ID=$2
OUTPUT=$3
if [ -f $OUTPUT ]; then
echo "Output file already exists."
exit 1
fi
cat <<EOF > $OUTPUT
resource "datadog_dashboard" $NAME {
}
EOF
terraform import datadog_dashboard.$NAME $DASHBOARD_ID
terraform show -no-color > $OUTPUT
sed -i "" "s/~EOT/EOT/" $OUTPUT
sed -i "" '/^ *id *=./d' $OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment