This document summarizes a talk on using Jsonnet, Terraform, and Packer together for infrastructure as code and application configuration management. Jsonnet is introduced as a configuration language that is designed like a programming language, allowing powerful abstractions while maintaining hermetic configurations. The methodology demonstrated generates infrastructure and application components from a single Jsonnet configuration, outputting files for Packer to build machine images and Terraform configuration to deploy the infrastructure. This allows building and updating a cloud application from a single make command for synchronized infrastructure and application configuration.
5. Jsonnet https://google.github.io/jsonnet/doc/
Addresses the config
language problem:
Write
application
Simple
config file
+ Comments + vars
+ String arith
+ conditionals+ repetition
+ int arith
Turing
completeness!!1
+ templates
+ closures
+ user def.
functions
Typical config
language
6. Hazards of ad-hoc language design:
Jsonnet https://google.github.io/jsonnet/doc/
Complex / surprising
behaviorNo specification:
difficult to develop
tools
Feature creep
(overlapping
features)
Ugly implementation
Hard to improve /
replace
implementation with
same semantics
Hard to port
implementation (e.g.
to Javascript)
7. Use existing general purpose
scripting language?
Write
application
Simple
config file
Python / Go /
Ruby / Lua /
etc.
Jsonnet https://google.github.io/jsonnet/doc/
Not hermetic: Can yield
different config in
different environment
Designed for
specifying
behavior, not
data
Code cannot be
substituted with data
(side effects)
Heavyweight
implementations
8. Jsonnet https://google.github.io/jsonnet/doc/
// Trivial Example
{
person1: {
name: "Alice",
welcome: "Hello " + self.name + "!",
},
person2: self.person1 { name: "Bob" },
}
{
"person1": {
"name": "Alice",
"welcome": "Hello Alice!"
},
"person2": {
"name": "Bob",
"welcome": "Hello Bob!"
}
}
➡
A configuration language designed like a programming language
● Simple: Just 9 features, (3 are from JSON)
○ Literals, arrays, objects, variables, conditionals, arithmetic, closures, mixins, errors
● Powerful: Multi-paradigm (supports OO and functional)
● Hermetic: Repeatable evaluation, code/data interchangeable
● Familiar: All syntax and semantics compatible with JSON / Python
● Concise: Code / data interleaving, prototype inheritance
● Formal: Complete operational semantics
9. Application Server
Application Server
Application Server
Application Server
Application ServerTile Generation
Service
Cassandra
Cassandra
Cassandra
HTTP
HTTP
Cassandra protocol
Live version
Fractal Application Architecture
10. Jsonnet
configuration
Jsonnet
configuration
Jsonnet
configuration
One logical configuration,
perhaps broken into several files
by import constructs.
appserv.packer.json
cassandra.packer.json
tilegen.packer.json
{
"appserv.packer.json": ...,
"cassandra.packer.json": ...,
"tilegen.packer.json": ...,
"terraform.tf": ...
}
Multiple output mode:
Configuration defines
several files
terraform.tf
Jsonnet evaluation
Centralize ALL configuration
Use a makefile: Invoke Jsonnet, run Packer and Terraform on JSON output:
● Build multiple images in parallel, only if config changed
● Just run make -j to build images and deploy / update cloud application
infrastructure, system, daemons, databases, builds, ...
11. ● Abstraction - say less
○ Build template libraries, factor out repetitive code
■ Both tilegen and appserv use Nginx + uWSGI + Flask
○ Override bits of default Nginx / uWSGI / Cassandra configs as needed
○ Higher level templates allow listing of apt packages, repos, keys, etc
● Synchronize details
○ Backend endpoints / credentials feature in
■ frontend / backend application config (packer configs)
■ infrastructure (metadata, firewalls, health checks, load balancer...)
Advantages of this methodology