Created
November 11, 2020 15:15
-
-
Save mvasilenko/d8441c69e27be5f7c7c3bbbe39f4d070 to your computer and use it in GitHub Desktop.
import Cloudflare DNS record into terraform state
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
# set your CloudFlare key & email | |
export auth_email=$CLOUDFLARE_EMAIL | |
export auth_key=$CLOUDFLARE_TOKEN | |
# list your DNS zones hosted at CloudFlare | |
curl -s -X GET "https://api.cloudflare.com/client/v4/zones/?per_page=100" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json"| jq -r '.result[] | "\(.id) \(.name)"' | |
# expected output: | |
# a3c9c7d3861e52cf23c835102c258d63 example1.com | |
# f47d1debb65621ca89039b9fbfeb726a example2.com | |
# get records for example1.com | |
curl -X GET "https://api.cloudflare.com/client/v4/zones/a3c9c7d3861e52cf23c835102c258d63/dns_records?per_page=100" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json"| jq -r '.result[] | "\(.id) \(.name)"' | |
# expected output: | |
# 9b2542913adbe8c0e50fc6d755cd4c9c www.example1.com | |
# 3389b2877b4ab4562a6b72f861bbeaef test.example1.com | |
# import DNS records | |
terraform import cloudflare_record.www_example_com example1.com/9b2542913adbe8c0e50fc6d755cd4c9c | |
# whoa, DNS record was imported | |
# verify import | |
terraform plan | |
# expected output: no changes in DNS records |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment