Get ready for your next interview with our comprehensive question library
Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp that allows you to define and provision infrastructure using declarative configuration files. Unlike imperative tools that require you to specify step-by-step instructions, Terraform uses a declarative approach where you describe the desired end state.
Key differences from other IaC tools:
The Terraform workflow consists of four main steps:
terraform init to download providers and modulesterraform plan to preview changes before applyingterraform apply to create/modify/destroy infrastructureterraform init
terraform plan
terraform apply
terraform destroy # when cleanup is needed
Providers are plugins that enable Terraform to interact with cloud platforms, SaaS providers, and APIs. They define resource types and data sources available for use.
Example AWS provider configuration:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-west-2"
}
Resources are infrastructure components that Terraform creates, manages, and destroys. They represent the desired state of infrastructure.
Data sources allow Terraform to fetch information about existing infrastructure or external systems without managing them.
# Resource - creates new EC2 instance
resource "aws_instance" "web" {
ami = "ami-12345678"
instance_type = "t2.micro"
}
# Data source - fetches existing VPC info
data "aws_vpc" "default" {
default = true
}
Upgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumAccess all premium content - interview questions, and other learning resources
We regularly update our features and content, to ensure you get the most relevant and updated premium content.
1000 monthly credits
Cancel anytime