Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Terraform testing variable map object values without resource configuration part 2

This is second part of earlier written article Terraform testing local variables and output csv file without resource Part 1. Idea is use same method technique to learn and verify how to assign map of object works. Below is the example of variable map object and its output.

I used this map object practically in earlier article Hashicorp Terraform map and object inside module and variable example

# Declare the "resource_info_value" variable with a default value
variable "resource_info_value" {
  type = map(object({
    rg_name = string
    tags = object({
      environment = string
      Owner       = string
    })
    storage_accounts = optional(map(object({
      name                     = string
      account_tier             = string
      account_replication_type = string
    })))
  }))
  default = {
    rg1 = {
      rg_name = "demo_RG1" # Add the rg_name attribute with a default value
      tags = {
        environment = "DemoRG1"
        Owner       = "http://vcloud-lab.com"
      }
      storage_accounts = {
        sa1 = {
          name                     = "longnameofsa0001"
          account_tier             = "Standard"
          account_replication_type = "LRS"
        }
      }
    }
    rg2 = {
      rg_name = "demo_RG2" # Add the rg_name attribute with a default value
      tags = {
        environment = "DemoRG2"
        Owner       = "http://vcloud-lab.com"
      }
      storage_accounts = {
        sa2 = {
          name                     = "longnameofsa0002"
          account_tier             = "Standard"
          account_replication_type = "LRS"
        }
      }
    }
  }
}

# Output block to display the value of the "resource_info_value" variable
output "example_output" {
  value = var.resource_info_value
}

This is the implementation of terraform configuration plan testing.

terraform plan apply azure cloud microsoft sotrage account account replication type account_tier tags owner environment resource group name testing information variable set list object map configuration.png

Useful Articles
Terraform error retrieving storage account failure responding to request StatusCode 404 StorageAccountNotFound The storage account was not found
Terraform clone virtual machine template in VMware vSphere vCenter from CSV file
Terraform A reference to a resource type must be followed by at least one attribute access, specifying the resource name
Terraform one module deploy null or multiple resources based on input
Hashicorp Terraform map and object inside module and variable example
Terraform module clone VMware vSphere Linux and Windows virtual machine
Terraform VMware vSphere Virtual Machine customization clone failed on Windows
Terraform VMware vSphere Virtual Machine cloning Operating system not found
How to Install Minikube on Ubuntu - Step by Step
MINIKUBE Unable to start VM - This computer doesn't have VT-X AMD-v enabled
Install and Setup your own Kubernetes Cluster with K3s
Rancher k3s.yaml permission denied when using kubectl - Kubernetes

Go Back

Comment

Blog Search

Page Views

11390921

Follow me on Blogarama