summaryrefslogtreecommitdiff
path: root/split-spec.scm
diff options
context:
space:
mode:
Diffstat (limited to 'split-spec.scm')
-rw-r--r--split-spec.scm63
1 files changed, 63 insertions, 0 deletions
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)