Created
September 7, 2020 15:47
-
-
Save therve/d588869b89f0939a3ee051e91dce72f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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