Intermediate Level
Advanced concepts in Infrastructure as Code including state management, testing, and best practices.
Intermediate Level
This section covers advanced concepts in Infrastructure as Code, including state management, testing strategies, and best practices.
Terraform Questions
What is the difference between Terraform local
and remote
state?
Terraform state can be stored locally (on disk) or remotely (in S3, Consul, etc.).
Storage | Pros | Cons |
---|---|---|
Local State (terraform.tfstate ) | Fast, simple | Not suitable for teams |
Remote State (S3, etc.) | Shared, secure | Slightly slower |
Example remote state (S3 backend):
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
}
}
How do you handle secrets in Terraform?
Avoid hardcoding secrets in .tf
files:
✅ Use environment variables
✅ Use Terraform Vault Provider
✅ Store secrets in AWS Secrets Manager
What is Terraform Locking, and why is it important?
Terraform uses state locking to prevent simultaneous updates by multiple users.
Example (DynamoDB locking):
backend "s3" {
bucket = "my-terraform-bucket"
dynamodb_table = "terraform-lock"
}
What is Terraform Workspaces?
Terraform Workspaces allow managing multiple environments within a single configuration.
terraform workspace new dev
terraform workspace select dev
How do you create reusable Terraform modules?
Modules help organize and reuse code.
Example (modules/network/main.tf
):
variable "vpc_cidr" {}
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
}
Ansible Questions
How do you use Ansible variables?
Variables can be defined in:
✅ Playbooks (vars:
)
✅ Inventory (host_vars
, group_vars
)
✅ Command-line (-e
flag)
Example:
- hosts: web
vars:
app_port: 8080
tasks:
- debug: msg="App runs on port {{ app_port }}"
What are Ansible Facts?
Facts are system information collected automatically.
Example:
ansible all -m setup
What is the purpose of Ansible Handlers?
Handlers run only when notified.
Example:
- name: Install Nginx
apt:
name: nginx
notify: Restart Nginx
handlers:
- name: Restart Nginx
service:
name: nginx
state: restarted
CloudFormation Questions
What are the main components of AWS CloudFormation?
Component | Description |
---|---|
Templates | Defines resources in YAML/JSON |
Stacks | Collection of AWS resources |
StackSets | Deploy stacks across multiple accounts |
How do you update a CloudFormation stack?
Use:
aws cloudformation update-stack --stack-name my-stack --template-body file://template.yml
What is the difference between DependsOn
and CreationPolicy
in CloudFormation?
Feature | Purpose |
---|---|
DependsOn | Ensures a resource is created before another |
CreationPolicy | Waits for a signal before marking as successful |
📢 Contribute & Stay Updated
💡 Want to contribute?
We welcome contributions! If you have insights, new tools, or improvements, feel free to submit a pull request.
📌 How to Contribute?
- Read the CONTRIBUTING.md guide.
- Fix errors, add missing topics, or suggest improvements.
- Submit a pull request with your updates.
🌍 Community & Support
🔗 GitHub: @NotHarshhaa
📝 Blog: ProDevOpsGuy
💬 Telegram Community: Join Here