13 ms·
It's a configuration file parser and task dependency engine that tries to guarantee idempotent updates by keeping a record of the current state of your deployme
by nonameiguess 3y ago
It's a configuration file parser and task dependency engine that tries to guarantee idempotent updates by keeping a record of the current state of your deployment and only running update tasks if your configuration doesn't match the deployed state. The dependency engine also does some topological sorting to automatically run tasks in dependency order, in parallel where possible, without you having to imperatively specify any kind of ordering.
The configuration files themselves are intended to be written in HCL or the Hashicorp Configuration Language, which was created for Terraform and offers some built-in functions and types, but it will also accept json, which is intended more for when you programmatically generate your configuration. They recently began supporting writing your configuration as Python or TypeScript as well, addressing complaints that HCL is close enough to a real programming language that you often wish you had a real programming language.
The state is tracked either in a local file or a remote file, and the file is json. If remote, you can add authorization and locking depending on the remote storage provider.
The meat of the work is not really done by Terraform itself, but by providers, which are plugins either written by Hashicorp, by infrastructure vendors, or by the user community. The configuration files define resources that consist of variables that end up getting passed to these plugins that then construct API calls to request the real infrastructure providers do the provisioning. You also get "data" resources that just query the infrastructure provider rather than asking it to provision anything.
As for why you want Infrastructure as Code, effectively the same reason you want anything as code. Why write software when you can get a computer to do just about anything with shell commands? Because you can reuse, share, make far better reliability and consistency guarantees, and the code itself provides somewhat of an audit trail or record that should reflect the behavior of your resources. As long as your administrators actually use it, you have a clear, readable record of how everything you own was deployed. It can be put to code review before changing anything. You can use your regular peer review/pull request process to implement separation of duties.
Terraform is somewhat of an industry leader. Hashicorp is the company that started out with Vagrant and also makes Packer, Vault, Consul, Nomad, and some other things, but all of their products are pretty widely used and have a lot of developer mindshare. They're not the only game in town, but as far as Infrastructure as Code tools that aren't locked to a single cloud provider, there's really only Terraform and Pulumi that I'm aware of and have seen actually used in the wild.