Terraform is an example of a declarative approach to deploying Infrastructure as Code. other core concepts are:
- consistency: Each time you do something, the results should be the same
- idempotent: If you haven’t changed anything about your code, nothing will change in the environment
- Push or Pull: Terraform is a push-type model, the configuration that terraform has is getting pushed to the target environment.
Terraform Object Types
- Provider: blocks define information about a provider you want to use
- Resources: things you want to create in a target environment
- Data sources: a way to query information from a provider
Block Syntax
HashiCorp configuration language uses block syntax for everything in the file. It’s a simplified version of JSON that is easier to read and it supports inline comments.
Each block is going to start with the block type keyword that describes what type of object is being described in the block.
block_type "lable" "name_label" {
key = "value"
}
// define object type, type of resource, and name label
resource "aws_instance" "web_server" {
name = "web-server"
// we could use a nested block to specify an ebs_volume
ebs_volume {
size = 40
}
}
Terraform Object Reference
<resource_type>.<name_label>.<attribute>
aws_instance.web_server.name