- Welcome my DevOps blog./
- 🔰Posts/
- 🗂️My Trainings/
- Terraform Trainings and Certifications/
- Terraform on AWS with SRE & IaC DevOps/
- Terraform: Settings, Providers and Resources/
Terraform: Settings, Providers and Resources
Table of Contents
Terraform Blocks #
Terraform Block #
- Special block used to configure some behaviors
- Required Terraform Version
- List Required Providers
- Terraform Backend

Provider Block #
- Heart of the Terraform
- Terraform is relying on providers to interact with remote systems
- Declare providers for Terraform to install and use them
- Provider configurations belong to Root Module
📄File: c1-versions.tf
# INFO: Terraform Block
terraform {
required_version = "~> 1.13.0" # NOTE: Greater than 1.13.2. Only the most upright version number (.0) can change.
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0" # NOTE: Greater than 6.0. Only the most upright version number (.0) can change.
}
}
}
# INFO: Provider Block
provider "aws" {
region = "eu-west-2"
}
required_version = "~> 1.13.2" means that valid versions will be: 1.13.2-9required_version = "~> 1.13" means that valid versions will be: 1.13-99
# INFO: Provider Block
provider "aws" {
region = "eu-west-2"
# profile = "dev-account"
profile = "terraform-user"
}
~/.aws/credentials settings. Those profiles can then be referenced in the Provider block and used to connect to your Provider.Resource Block #
- Each Resource Block describes one or more Infrastructure Objects
- Resource Syntax: How to declare Resources?
- Resource Behavior: How Terraform handles resource declarations?
- Provisioners: We can configure Resource post-creation actions
📄File: c2-ec2instance.tf
# Resource: EC2 Instance
resource "aws_instance" "myec2vm" {
ami = "ami-0742b4e673072066f"
instance_type = "t3.micro"
user_data = file("${path.module}/app1-install.sh")
tags = {
"Name" = "EC2 Demo"
}
}

Resource Behavior #
| Terraform Resource | |
|---|---|
| Create Resource | Create resources that exist in the configuration but are not associated with a real infrastructure object in the state. |
| Destroy Resource | Destroy resources that exist in the state but no longer exist in the configuration. |
| Update in-place Resources | Update in-place resources whose arguments have changed. |
| Destroy and re-create | Destroy and re-create resources whose arguments have changed but cannot be updated in-place due to remote API limitations. |
Terraform State #
The primary purpose of Terraform State is to store bindings between objects on a remote system and resource instances declared in your configuration.
- Terraform State file
terraform.tfstate
terraform.tfstate file is being created / updated every time terraform plan command is being executed.
Important! #
The terraform state file is the only way Terraform can track which resources it is managing. It often contains sensitive information so must be stored securely and access must be restricted.
Terraform Registry #
ℹ️ https://registry.terraform.io
Terraform Registry is a selection of Providers and Modules used by Terraform.
Provider Badges:
- Official - Owned and maintained by HashiCorp
- Verified - Owned and maintained by third-party technology partners. HashiCorp has verified the authenticity of the Provider’s publisher
- Community - Community providers are published to the Terraform Registry by individual maintainers, groups of maintainers or other members of the Terraform community
- Archived - Official or Verified Providers that are no longer maintained.
» Sources « #
- More about Resources
- Create EC2 Instance Resource
- More about File Function
- More about Resources - Argument Reference
- More about Resources - Attribute Reference
» References « #
» Disclaimer « #
This series draws heavily from Kalyan Reddy Daida’s Terraform on AWS with SRE & IaC DevOps course on Udemy.
His content was a game-changer in helping me understand Terraform.
| About the instructor | |
|---|---|
| 🌐 Website | 📺 YouTube |
| 🗃️ GitHub |