Skip to content

Instantly share code, notes, and snippets.

@ledakis
Created July 7, 2020 17:38
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 ledakis/3a4fea05b96bb9e50348c4267601fa46 to your computer and use it in GitHub Desktop.
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
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}"
}
#!/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}'
@ledakis
Copy link
Author

ledakis commented Jul 7, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment