Skip to content

Commit

Permalink
find pre-existing hosted-zone and use if present; closes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
martinklepsch committed Nov 26, 2016
1 parent c03b8a8 commit f2f93cf
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/confetti/boot_confetti.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[boot.core :as b]))

(def deps '[[camel-snake-kebab "0.3.2"]
[confetti/cloudformation "0.1.3"]
[confetti/cloudformation "0.1.4"]
[confetti/s3-deploy "0.1.1"]
[confetti/confetti "0.1.2-SNAPSHOT"] ; for serialize/report ns
[com.google.guava/guava "18.0"]])
Expand Down Expand Up @@ -59,6 +59,13 @@

;; ==============================================================================

(defn find-hosted-zone [pod creds domain]
(let [drop-dot (fn [n] (subs n 0 (- (count n) 1)))
subdomain-of? (fn [hz]
(let [zone-domain (drop-dot (:name hz))]
(when (and (.endsWith domain zone-domain) (not= domain zone-domain)) hz)))]
(some subdomain-of? (:hosted-zones (pod/with-eval-in pod (amazonica.aws.route53/list-hosted-zones ~creds))))))

(defn fetch-nameservers [pod creds hosted-zone-id]
(let [resp (pod/with-eval-in pod (amazonica.aws.route53/get-hosted-zone ~creds {:id ~hosted-zone-id}))
nss (-> resp :delegation-set :name-servers)]
Expand Down Expand Up @@ -115,7 +122,7 @@
(newline)
(println "The URL of your Cloudfront distribution is" (:cloudfront-url outputs))
(println "You can now use it as CNAME value in your DNS records."))
;; Root domain/Route53 case
;; Root domain using Route53 is required. Show nameservers.
(when (pod/with-call-in cpod (confetti.util/root-domain? ~domain))
(newline)
(u/warn "You're using a root/apex domain. Please note the that your site won't work unless\nyou use Route53's nameservers for your domain.\n"))
Expand Down Expand Up @@ -167,12 +174,16 @@
(assert-exit domain "The :domain option of the create-site task is required!")
(assert-exit access-key "The :access-key option of the create-site task is required!")
(assert-exit secret-key "The :secret-key option of the create-site task is required!")
(let [cpod (prep-pod (confetti-pod))]
(let [cpod (prep-pod (confetti-pod))
creds {:access-key access-key :secret-key secret-key}
hz (find-hosted-zone cpod creds domain)]
(when (pod/with-call-in cpod (confetti.util/root-domain? ~domain))
(assert-exit dns "Root domain setups must enable the :dns option"))
(let [creds {:access-key access-key :secret-key secret-key}
tpl (pod/with-eval-in cpod
(confetti.cloudformation/template {:dns? ~dns}))
(when (:id hz)
(u/warn "An existing Route53 HostedZone has been found.\nInstead of creating a new HostedZone a RecordSet\nwill be added to the existing one (%s).\n\n" (:id hz))
(u/dbug hz))
(let [tpl (pod/with-eval-in cpod
(confetti.cloudformation/template {:dns? ~dns :hosted-zone-id ~(:id hz)}))
stn (string/replace domain #"\." "-")
ran (when-not dry-run
(pod/with-call-in cpod
Expand Down

0 comments on commit f2f93cf

Please sign in to comment.