… kind of.
Declarative has its advantages which are hyped all over the internet so I’ll skip that part. The painful downside of declarative approach is often the expressivity. Sample proofs:
Now you can have Python embedded in your CloudFormation file. That is part of the CloudFormation Macros which were introduced on 2018-09-06.
Happy coding, everyone!
I bet you’ve seen a lot of scripts with seemingly innocent
if [ -e blah ];then ...; else ...; fi or something similar . What’s the problem?
if has at most two branches while
[[ have three different exit codes. Oops.
If you make a syntax error (or any other error occurs) in the
[[ expression, it will return the exit code 2 (or above, according to
if will take the
else branch. If you are lucky, you will notice the error message from the
[[ commands. If not, the
else branch will always be executed.
I don’t want to use bash. The pitfall above is one of the many reasons. Unfortunately, I do use bash because it’s still best tool for some tasks. I’m working on alternative to bash. It’s called NGS, the Next Generation Shell. In NGS, the situation above is solved as one would expect from a modern programming language: exit codes 2 and above throw exception.
If you also think that there should be a viable alternative to bash, you are welcome to help me working on it.
Happy coding! Hope it’s not in bash 🙂
I’ve got “protection” feature by default (and I didn’t notice I even had it up until now) from my internet provider, Bezeq International. In the last few days I was experiencing selective reachability. Some IPs were just blocked by the “protection”.
More than 20 minutes with support that wanted to install their binaries on my laptop (I couldn’t do it for many reasons) and then about 5 minutes with some more senior guy that after hearing the symptoms just turned that thing off. Everything works fine now.
Hope this helps other people so they could recognize the situation and immediately know what’s happening.
- One of GitHub web IPs was blocked.
- Broken FaceBook
;; ANSWER SECTION:
static.xx.fbcdn.net. 3599 IN CNAME scontent.xx.fbcdn.net.
scontent.xx.fbcdn.net. 59 IN A 188.8.131.52
- Broken AWS. Manifested in timeouts talking to various services endpoints.
Following are just screenshots of http://ec2-reachability.amazonaws.com/ :
I was hoping that smart guys vs bad situation will have another outcome but Terraform language for version 0.12 looks bad… as languages of Puppet and Ansible.
I’m not saying that people that made Puppet and Ansible are not smart. It’s that we could learn from the mistakes they made… unless we don’t consider those being mistakes.
Puppet and Ansible went through very similar difficult situation. They have limited themselves to a declarative format and then they tried to accommodate the real life. Terraform has this situation right now.
The situation is:
- Declarative format being used
- People need something more powerful, like a programming language because … real life where conditionals, loops and data transformations make much more sense than working around declarative languages limitations.
Interestingly enough, they all did not switch to a proper programming language. Maybe because that would be at least partially admitting that the product should have been a library in the first place?
Terraform is actually in very crappy situation because even if they decide to expose everything as a library as the main interface, I don’t see people start using Go for “infrastructure as code”. Not as smooth as Ruby or Python anyway.
Happy coding, everyone!
On a bit more positive note, the new splat operator looks like an improvement.
Terraform looks even more like a “normal” language with Conditional Operator Improvements and
null value. The conditional operator fixes previous oddities that it had.
Terraform got type system. Looks powerful. Just need to see that Terraform does not evolve to Scala 🙂
New template syntax brings more raw power. Looks good.
- HCL to JSON one-to-one mapping. When I read “having a clean 1:1 mapping between HCL and JSON, and ensuring every feature of HCL is supported in JSON” I immediately thought that there must be converting tools then… and was not disappointed 🙂 “In future versions of Terraform, we will also support native tooling to convert HCL to JSON and JSON to HCL cleanly (including comments)”
- “Comments in JSON” – nice!
Declarative languages failure
Approach that in my eyes failed, again and again, is to start with your own declarative language and then with time grow the language. (SQL being among notable exceptions)
Puppet is the best example. map and each, added in Puppet 4.0.0 are, in my opinion, just two in a sea of evidence that the envisioned simple format has failed to handle the needs of the real world.
Ansible’s loop looks bad as the whole idea of making top levels of programs in YAML based syntax (and the rest in Python).
In my opinion, it makes more sense to create a language first and then libraries for it, not a library and then a language around it.
My hope for Terraform
I think Terraform guys are smart. Among other things, it manifests in implementing data sources. Data sources make Terraform much more flexible. I think it’s very clever.
Terraform, which started declarative, are now inventing their own programming language. They are going the way of Puppet and Ansible. I hope they can do better, in this awkward situation: there are quite a lot of constraints on the programming language because of the existing syntax and semantics.
Happy coding, everyone!
I am considering making a JSON parsing and generating command line tool. Started with looking around a bit. Below is a list of existing JSON command line tools. Numbers are [GitHub stars] at the time of writing this post. (… contributed by …) means that this post was updated with the item.
- jq  – filter, extract, modify and output JSON or text using DSL
- jid  – “You can drill down JSON interactively by using filtering queries like jq.” (item contributed by /u/Tacticus)
- gron  – convert JSON or JSON lines (from file/stdin/url) to text (path=value) which can be processed with grep/sed/diff; the tool also supports converting back to JSON after such processing
- jo  – generate JSON based on command line arguments and stdin; can read data from files and place it as base64 encoded values
- JSON.sh  – written in shell/gawk; “traverses the JSON objects and prints out the path to the current object (as a JSON array) and then the object, without whitespace”
- jsawk  – focused primarily on filtering and transforming a list (or an object). Update 2019-09-30: as @joeytwiddle suggested in comment, the project appears to be unmaintained and doesn’t work with recent Node.js versions. Latest commit and latest closed issue are from 2015.
- json (by trentm)  – “massaging JSON on your Unix command line”; JS-like syntax for extracting values; in-place file editing
- rq  – awk/sed-like tool for structured data; supports several formats, including JSON
- TickTick  – use JSON syntax directly in bash; “This is just a fun hack”
- jshon  – very CLI-ish way to extract, manipulate and output the data
- jl  – “a tiny functional language for querying and manipulating JSON”; visually reminds Haskell
- jsonpp  – JSON pretty printer (item contributed by /u/ferbass)
- fx  – conveniently run your JS code to manipulate JSON.
- RecordStream  – create, manipulate and output records; supports JSON; Perl-based so grep expressions for example are in Perl.
- JSON.awk  – JSON.sh fork in awk; after fork the projects added different features.
- jp  – “command line interface to JMESPath” (link contributed by Evgeny Zislis)
- json-command  – conveniently manipulate JSON using JS.
- jsonv.sh  – convert JSON to CSV; specify paths in JSON to
- jgrep (aka “JSON-grep”)  – “Command line tool and API for parsing JSON documents” in Ruby (item contributed by /u/tophlammiepie)
- jsed  – manipulate and extract data; somewhat similar to jsawk in mindset
- jayin  “Piping with js at terminal”. Added on 2019-09-30 following comment from @joeytwiddle.
- jsongrep  (by dsc) – extract data at given path using shell globs and output one per line
- jsongrep  (by terrycojones) – easily extract data at given path
I’ve added related post in which I argue that jq functionality belongs to a shell.
If you feel that some project is missing from the list, please let me know in comments below.
About to remove an empty directory? Use
rmdir will not remove the directory if it’s not empty. Make it a habit. Thank me once every 2 to 20 years when you don’t remove your stuff by accident.