DevOps Classroom notes 29/Sep/2024

For each Block

variable "subnets" {
    type = map(object({
      cidr_block = string
      az = string
    }))

    default = {
      "web" = {
        cidr_block = "10.0.0.0/24"
        az = "ap-south-1a"
      },
      "app" = {
        cidr_block = "10.0.1.0/24"
        az = "ap-south-1b"
      }

    }

}

resource "aws_vpc" "base" {
    cidr_block = "10.0.0.0/16"
    tags = {
        Name = "base"
    }
}


resource "aws_subnet" "subnets" {
    for_each = var.subnets
    cidr_block = each.value.cidr_block
    availability_zone = each.value.az
    tags = {
      Name = each.key
    }
    vpc_id = aws_vpc.base.id

}

Dynamic Block

variable "subnets" {
    type = map(string)
    default = {
      "web" = "10.0.0.0/24"
      "app" = "10.0.1.0/24"
      "db" = "10.0.2.0/24"
    }

}

terraform {
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "4.3.0"
    }
  }
}

provider "azurerm" {
  # Configuration options
  features {

  }
}

resource "azurerm_resource_group" "rg" {
  name     = "rg-terraform"
  location = "eastus"
}

resource "azurerm_virtual_network" "vnet" {
  name                = "vnet-terraform"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  dynamic "subnet" {
    for_each = var.subnets
    content {
      name = subnet.key
      address_prefixes = [subnet.value]
    }
  }
}

Creating Golden Images using Packer


Complete CI/CD Pipeline

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Plugin for Social Media by Acurax Wordpress Design Studio
Exit mobile version
%%footer%%