From 8496c9de14ed432bbc781541b7d7a6c8c5fa5dc5 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 26 Sep 2025 09:36:07 +0000 Subject: [PATCH] Phase1 --- .github/workflows/terraform.yml | 27 +++++++++++++++++++++++++++ .gitignore | 5 ++++- README.md | 20 ++++++++++++++++++++ environments/dev/backend.tf | 8 ++++++++ environments/dev/main.tf | 12 ++++++++++++ modules/network/outputs.tf | 8 +++++++- modules/network/variables.tf | 20 +++++++++++++++++++- 7 files changed, 97 insertions(+), 3 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index e69de29..56d339f 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -0,0 +1,27 @@ +name: Terraform + +on: + pull_request: + branches: [ "main" ] + push: + branches: [ "main" ] + +jobs: + terraform: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + + - name: Terraform Init + run: terraform -chdir=environments/dev init + + - name: Terraform Validate + run: terraform -chdir=environments/dev validate + + - name: Terraform Plan + run: terraform -chdir=environments/dev plan diff --git a/.gitignore b/.gitignore index c3b7960..842d58d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ +# Terraform .terraform/ *.tfstate *.tfstate.backup .terraform.lock.hcl + +# Local configs terraform.tfvars -*.override.tf +*.override.tf \ No newline at end of file diff --git a/README.md b/README.md index 74a4737..aa6ee38 100644 --- a/README.md +++ b/README.md @@ -1 +1,21 @@ # Terraform Azure Bootcamp + +This repo contains hands-on Terraform projects on Azure, following a structured learning path: +1. Foundations (VM, Virtual Network) +2. Modules +3. Remote State & Environments +4. Scaling & Advanced Patterns +5. Security & Testing +6. Production-Ready 3-Tier Architecture + +## 📂 Structure +- `modules/` → reusable Terraform modules (network, compute, database, etc.) +- `environments/` → environment-specific configs (`dev`, `prod`) +- `.github/workflows/terraform.yml` → CI/CD with GitHub Actions + +## 🚀 Usage +```bash +cd environments/dev +terraform init +terraform plan +terraform apply \ No newline at end of file diff --git a/environments/dev/backend.tf b/environments/dev/backend.tf index e69de29..0117784 100644 --- a/environments/dev/backend.tf +++ b/environments/dev/backend.tf @@ -0,0 +1,8 @@ +terraform { + backend "azurerm" { + resource_group_name = "terraform" + storage_account_name = "tfstoracccom" + container_name = "tfstate" + key = "dev.terraform.tfstate" + } +} diff --git a/environments/dev/main.tf b/environments/dev/main.tf index e69de29..91b3812 100644 --- a/environments/dev/main.tf +++ b/environments/dev/main.tf @@ -0,0 +1,12 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "4.46.0" + } + } +} + +provider "azurerm" { + # Configuration options +} \ No newline at end of file diff --git a/modules/network/outputs.tf b/modules/network/outputs.tf index 94ca2bd..1399cf6 100644 --- a/modules/network/outputs.tf +++ b/modules/network/outputs.tf @@ -1 +1,7 @@ -output "vnet_id" { value = "" } +output "vnet_id" { + value = azurerm_virtual_network.main.id +} + +output "subnet_ids" { + value = { for s in azurerm_subnet.subnets : s.name => s.id } +} \ No newline at end of file diff --git a/modules/network/variables.tf b/modules/network/variables.tf index 088bd1a..67bd549 100644 --- a/modules/network/variables.tf +++ b/modules/network/variables.tf @@ -1 +1,19 @@ -variable "resource_group_name" { type = string } +variable "resource_group_name" { + description = "Name of the resource group" + type = string +} + +variable "location" { + description = "Azure region" + type = string +} + +variable "address_space" { + description = "CIDR for the Virtual Network" + type = list(string) +} + +variable "subnets" { + description = "Map of subnet names and CIDRs" + type = map(string) +} \ No newline at end of file