Welcome to Terraform with Azure learning series. This repository will guide you step by step, helping you understand Terraform concepts while using the Azure provider. I will upload code samples to this repository, and contributions are welcome! Feel free to fork and create pull requests. Let's learn together!
-
Core Components of Terraform:
- Providers: Plugins to interact with various cloud platforms.
- Resources: Infrastructure objects like VMs, VNETs, etc.
- Data Sources: Information about existing resources.
- Variables & Parameters: Input values for configuration.
- Functions, Modules, Local Variables: Advanced features for modular and reusable code.
- Statefile: Tracks the current state of infrastructure.
-
Task: Install Terraform on your system.
-
Understanding the Files:
main.tf
,variable.tf
,terraform.tfvars
,terraform.tfstate
-
Azure Roles:
- Owner, Contributor, Reader
-
Authentication Methods with Azure:
- Azure CLI (
az login
) - Best practice to avoid exposing credentials. - App Registration & Service Principal (Client ID, Client Secret, Tenant ID, Subscription ID).
- Azure CLI (
-
Task: Create an Azure Resource Group and Virtual Network using the code which is in day02.
-
Concepts:
- Deploy new resources.
- Handle conflicts when manual resources are created via the Azure portal.
- Use
terraform import
to bring manually created resources into Terraform's state.
-
Task: Create another subnet manually in Azure, then import it into your Terraform state.
-
Resources to Create:
- Resource Group
- Virtual Network (VNET)
- Subnet
- Public IP
- Network Interface (NIC)
- Windows Virtual Machine (VM)
-
Task: Create the above infrastructure using Terraform. Understand
variable.tf
andterraform.tfvars
files for parameterized configurations.
-
Terraform Plan with Different Variables:
- Use multiple
.tfvars
files to deploy unique VMs.
- Use multiple
-
Command:
terraform plan -var-file="custom.tfvars"
-
Task: Deploy resources with multiple
.tfvars
files.
- Task: Deploy an AKS cluster
-
AKS With it's own network: we will ensure it uses a custom VNET.
-
Task: Modify your AKS configuration to use a custom subnet.
- Task: Deploy identical environments using modules
-
Meta-Arguments:
depends_on
: Set dependencies between resources.count
: Create multiple identical resources.for_each
: Create non-identical resources.lifecycle
: Customize resource management.
-
Task: Deploy 3 resource groups using the
count
argument.
-
ForEach for Non-Identical Resources:
- Useful for deploying non-identical resources like VMs with different configurations.
- Helps reduce code complexity by enabling parameterized resource deployment.
-
Remote Backend with Azure Storage Account:
- Configure remote backend with Azure Storage Account to store Terraform state files securely.
- Enables shared state management for collaborative deployments, supporting backup, CI/CD, and robust infrastructure management.
- Useful in multi-team environments to prevent conflicts in deployment and ensure consistency.
-
Task:
- Deploy multiple non-identical VMs using the
for_each
argument. - Configure a remote backend in Azure for shared state storage.
- Deploy multiple non-identical VMs using the
If you'd like to contribute:
- Fork the repo.
- Create your feature branch (
git checkout -b feature/new-topic
). - Commit your changes (
git commit -am 'Added a new learning day'
). - Push to the branch (
git push origin feature/new-topic
). - Create a new Pull Request.
Note: This repository is designed to assist professionals getting started with Azure and Terraform and also serves as a quick reference for experienced users. If you’re interested in contributing or have any questions, feel free to connect with me at [email protected]. Let's make Terraform learning easier together!