General Principles of Intellectual Property: Concepts of Intellectual Proper...
Terraform
1. Getting started with Terraform
• Terraform is an infrastructure as code software by HashiCorp.
• Terraform is used to create, manage, and update infrastructure resources
such as physical machines, VMs, network ,storage, containers, and more.
Almost any infrastructure type can be represented as a resource in Terraform
• It is developed in Go Language
• The syntax of Terraform configurations is called HashiCorp Configuration
Language (HCL) . It is meant to strike a balance between human readable
and editable as well as being machine-friendly
• Managing anything with an API
2. Terraform is a
• Open source
• Declarative language : where you write code that specifies your desired end state
• Immutable infrastructure : is all about immutable components which are recreated and
replaced instead of updating after infrastructure creation.
3. Terraform vs Other Software
• Chef, Puppet, Ansible etc. : Configuration management tools install and manage software on
a machine that already exists.
• Cloud Formation : is developed and maintained by AWS, it is very tightly integrated and only
supports AWS.
• cloud-agnostic : it goes further by being both cloud-agnostic and enabling multiple providers
and services to be combined and composed.
• Terraform is a client-only architecture.
6. Steps to install Terraform
For Mac/Linux :
• Navigate to https://www.terraform.io/downloads.html select appropriate installer based
on your operating system.
• Once you install you can verify the version of terraform
• Make sure that the terraform binary is available on the PATH.
• For Mac/Linux. On the shell/terminal, go to the folder where terraform binary is extracted
• echo $"export PATH=$PATH:$(pwd)" >> ~/.bash_profile
• source ~/.bash_profile
7. For windows :
• In Search, search for and then select: System (Control Panel)
• Click the System and Security link.
• Click the System link.
• Click the Advanced system settings link.
• Click Environment Variables. In the section System Variables, find the PATH environment
variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
• In the Edit System Variable (or New System Variable) window, append at the end of
the PATH environment variable the value of terraform path ex.”c:terraform;”. Click OK. Close
all remaining windows by clicking OK.
• Reopen Command prompt window, and run terraform.
14. You can clean up all resources you created with Terraform
Just use the terraform destroy command
15. But how did Terraform know what to destroy???
• Terraform records state of everything it has done
once you execute Terraform Apply ,it creates below files
• terraform.tfstate
• terraform.tfstate.backup
• By default, state is stored locally in .tfstate files
18. outputs
• Is a way to organize data to be easily queried and shown back to the Terraform user.
• Outputs are a way to tell Terraform what data is important. This data is outputted when apply is
called, and can be queried using the terraform output command.
• an output to show us the public IP address of the elastic IP address that we create. Add this
to any of your *.tf files :
19. Backends
• Backends are responsible for storing state
• A "backend" in Terraform determines how state is loaded and how an operation such as apply
is executed
• By default, Terraform uses the "local" backend, which is the normal behavior of Terraform
you're used to
• Here are some of the benefits of backends:
• Working in a team:
• Backends can store their state remotely and protect that state with locks to prevent
corruption. Some backends such as Terraform Enterprise even automatically store a
history of all state revisions.
• Keeping sensitive information off disk:
• State is retrieved from backends on demand and only stored in memory. If you're using
a backend such as Amazon S3, the only location the state ever is persisted is in S3.
20. Terraform Modules
• That you can reuse, configure, and version control
• A module is just a folder with Terraform templates
• Example using module
21. Module Sources
• The module installer supports installation from a number of different source types, as listed below
• Local paths
• GitHub
• Bit bucket
• S3 buckets
• Terraform Registry
22. Best practices
• Plan before apply
• Stage before prod
• Isolated environments