Created
July 7, 2020 17:38
-
-
Save ledakis/3a4fea05b96bb9e50348c4267601fa46 to your computer and use it in GitHub Desktop.
Check if a certificate validation record in Route 53 already exists before plan
This file contains 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
variable "zoneid" { | |
type = string | |
default = "YOURZONEID" | |
} | |
variable "certificate_url" { | |
type = string | |
default = "fqdn.example.com." | |
} | |
data "external" "record_checker" { | |
program = ["bash", "script.sh"] | |
query = { | |
zoneid = var.zoneid | |
certurl = var.certificate_url | |
} | |
} | |
output "is_there_one_already" { | |
description = "Is there a record already?" | |
value = "${data.external.record_checker.result.number > 0}" | |
} | |
This file contains 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
#!/usr/bin/env bash | |
set -e | |
eval "$(jq -r '@sh "ZONEID=\(.zoneid) CERTURL=\(.certurl)"')" | |
NUMRECORDS=$(aws route53 list-resource-record-sets --hosted-zone-id $ZONEID --query "length(ResourceRecordSets[?ends_with(Name, '$CERTURL') && Type == 'CNAME' && ends_with(ResourceRecords[0].Value, 'acm-validations.aws.')])") | |
jq -n --arg number "$NUMRECORDS" '{"number":$number}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script format I found in https://www.terraform.io/docs/providers/external/data_source.html