From 68e13e0aec50a12b343aec8c2009162e4dbc08de Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 28 Nov 2018 12:44:54 -0500 Subject: First working version. --- split-spec.scm | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 split-spec.scm (limited to 'split-spec.scm') diff --git a/split-spec.scm b/split-spec.scm new file mode 100644 index 0000000..6111b17 --- /dev/null +++ b/split-spec.scm @@ -0,0 +1,63 @@ +(use-modules (aws cloudformation utils) + (aws cloudformation utils json) + (ice-9 match) + (srfi srfi-1)) + +(define spec + (call-with-input-file "cloudformation-spec.json" read-json)) +(define spec-version (json-assoc-ref spec "ResourceSpecificationVersion")) +(define properties-by-service (make-hash-table)) +(define resources-by-service (make-hash-table)) + +(define (parse-service-name name) + (match (delete "" (string-split name #\:)) + (("Tag") "Universal") + ((_ service . _) service))) + +(define (add-to-group table type-spec) + (match type-spec + ((name . details) + (let* ((service (parse-service-name name)) + (existing-stuff (or (hash-ref table service) '()))) + (hash-set! table + service + (cons type-spec existing-stuff)))))) + +(for-each (lambda (property) + (add-to-group properties-by-service property)) + (json-assoc-ref spec "PropertyTypes")) +(for-each (lambda (property) + (add-to-group resources-by-service property)) + (json-assoc-ref spec "ResourceTypes")) + +(define (hash-table-keys table) + (hash-fold (lambda (k v memo) (cons k memo)) '() table)) + +(define services + (sort (lset-union string=? + (hash-table-keys properties-by-service) + (hash-table-keys resources-by-service)) + string<)) + +(for-each (lambda (service) + (let* ((module-suffix (symbol->string (aws-string->symbol service))) + (file-name (string-append "aws/cloudformation/" + module-suffix ".cfn"))) + (display "create ") + (display file-name) + (newline) + (call-with-output-file file-name + (lambda (port) + (let ((properties (or (hash-ref properties-by-service service) + '())) + (resources (or (hash-ref resources-by-service service) + '()))) + (write `(("ModuleSuffix" . ,module-suffix) + ,@(if (string=? service "Universal") + `(("ResourceSpecificationVersion" . + ,spec-version)) + '()) + ("PropertyTypes" . ,properties) + ("ResourceTypes" . ,resources)) + port)))))) + services) -- cgit v1.2.3