known software best practices: • Code versioning • Code reuse (modularization/abstraction) • Code sharing In order to achieve: • Repeatability • Speed • Reliability 5
and versioning infrastructure safely and efficiently. • Declarative approach ◦ Infrastructure is described using a high-level configuration syntax • Incremental changes ◦ Automatically discover the steps required from current to desired infrastructure state • Execution plan ◦ See what Terraform will do when you apply configuration • Dependency graph ◦ automatically decide the order in which action are executed • Automation 8
still need Puppet, Chef, Ansible to manage software on VM • Cloud abstraction layer ◦ Doesn’t expose any API, just a CLI mean to be used by humans ◦ Doesn’t hide the inner characteristics of each cloud provider via abstraction • A solution to your lack of cloud knowledge 9
to arrange resources inside a terraform project: • All .tf files in the current folder are automatically sources and merged together in memory $ ls -la total 108 drwxr-xr-x 4 gionn dev 4096 mar 8 15:47 . drwxr-xr-x 3 gionn dev 4096 mar 7 18:03 .. drwxr-xr-x 7 gionn dev 4096 mar 8 15:47 .git drwxr-xr-x 3 gionn dev 4096 mar 7 18:22 .terraform -rw-r--r-- 1 gionn dev 2333 mar 7 18:18 account.json -rw-r--r-- 1 gionn dev 175 mar 7 18:19 auth.tf -rw-r--r-- 1 gionn dev 406 mar 8 15:46 vm.tf 19
to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. --------------------------------------------- An execution plan has been generated and is shown below. 21
to destroy. ------------------------------------------------- - Note: You didn't specify an "-out" parameter to save this plan, so Terraform can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run. 23
generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: + google_compute_instance.default 24
confirmation Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: ___ 25
Map managed resources to terraform resources • Persist additional metadata • Cache, useful for large infrastructures JSON structure that can be modified (bugs happens) or inspected (custom integrations). State should be persistent and shared among developers. 28
just commit to GIT. For bigger teams, tfstate locking is required. Multiple backends supported: • Google cloud storage • S3 • Consul • Etcd • Terraform enterprise 29
machine_type (and configure allow_stopping_for_update) Now, when terraform apply is run, terraform discover that the machine_type of the existing resource doesn’t correspond to the desiderata. 33
resource ◦ Set a default • Define unique resource names to avoid conflicts ◦ Leverage count.index variable • Reference a difference disk for each instance ◦ Use count.index variable as disk reference • Override variable value via environment variable ◦ TF_VAR_my_counter