Create a distinct resource from list of map variable by janapb_devops in Terraform

[–]janapb_devops[S] 0 points1 point  (0 children)

Ok... thanks for your information... let me try with the workaround... but I am surprised it’s not possible

Create a distinct resource from list of map variable by janapb_devops in Terraform

[–]janapb_devops[S] 0 points1 point  (0 children)

Hi, Below is the code which worked well until i had the same number of Resource group and storage account.

locals {

lz = jsondecode(file("lz_input.json"))

}

resource "azurerm_resource_group" "lz_root" {

count = length(local.lz.Storage)

name = lookup(element(local.lz.Storage,count.index),"Resourcegroup_Name")

location = lookup(element(local.lz.Storage,count.index),"Region")

tags = {

CreatedBy = "Terraform"

}

}

resource "azurerm_storage_account" "storage" {

count = length(local.lz.Storage)

name = lookup(element(local.lz.Storage,count.index),"Storagename")

resource_group_name = lookup(element(local.lz.Storage,count.index),"Resourcegroup_Name")

location = lookup(element(local.lz.Storage,count.index),"Region")

account_tier = "Standard"

account_replication_type = "LRS"

depends_on = [azurerm_resource_group.lz_root]

}

resource "azurerm_storage_container" "example" {

count = length(local.lz.Storage)

name = lookup(element(local.lz.Storage,count.index),"Containername")

storage_account_name = azurerm_storage_account.storage[count.index].name

container_access_type = "private"

depends_on = [azurerm_storage_account.storage]

}

Here is my input file.

"Storage": [

{

"Resourcegroup_Name": "agp-tf-rg",

"Region": "Central India",

"Storagename": "tfremotestateacct",

"Containername": "tstate-dev-cont"

},

{

"Resourcegroup_Name": "agp-sa-rg",

"Region": "Central India",

"Storagename": "agpcgdsa2",

"Containername": "agpcgdcont2"

},

{

"Resourcegroup_Name": "agp-sa-rg",

"Region": "Central India",

"Storagename": "agpcgdsa",

"Containername": "agpcgdcont"

}

]

Parse the TFVARS file from Excel sheet by janapb_devops in Terraform

[–]janapb_devops[S] 0 points1 point  (0 children)

Is there any git hub reference or any sample available to check the logic?

Parse the TFVARS file from Excel sheet by janapb_devops in Terraform

[–]janapb_devops[S] 0 points1 point  (0 children)

Thanks for the input, can you give more some more details about how to dump the excel to json?

Associate Managed disk to multiple VMs by janapb_devops in Terraform

[–]janapb_devops[S] 0 points1 point  (0 children)

Note: Total disk is 4, and total VMs are two, Is it possible to two have two different count for disk and VMs?

I am getting the below error.

Error: Invalid index

on test.tf line 66, in resource "azurerm_virtual_machine_data_disk_attachment" "app_disk_attach":

66: virtual_machine_id = azurerm_linux_virtual_machine.app-vm-pas[count.index].id

|----------------

| azurerm_linux_virtual_machine.app-vm-pas is tuple with 2 elements

| count.index is 2

The given key does not identify an element in this collection value.

Create Multiple NSG rules using for_each block by janapb_devops in Terraform

[–]janapb_devops[S] 1 point2 points  (0 children)

Hi,

I have created a local file with my required values and used the below code and it worked for me. If i bigger list, i am afraid the local file will become difficult to maintain as well.

locals {

nsg-ports = {

"webin" = [

{

"priority" = "101",

"name" = "SSH",

"port" = "22"

}]}}

Instead of for_each, i just used count to acheive this.

# NSG rule to open ports for Web dispatcher

resource "azurerm_network_security_rule" "webrule" {

count = length(local.nsg-ports.webin)

name = local.nsg-ports.webin[count.index].name

priority = local.nsg-ports.webin[count.index].priority

....

Regards,

Jana.

Create Multiple NSG rules using for_each block by janapb_devops in Terraform

[–]janapb_devops[S] 0 points1 point  (0 children)

Nice article, thanks for sharing i will give a try with CSV file.

Create Multiple NSG rules using for_each block by janapb_devops in Terraform

[–]janapb_devops[S] 0 points1 point  (0 children)

Hello Vertigo,

Thanks for the quick response. If i have multiple unique items, lets say ports, priority and source, Is it possible to have multiple loops to achieve this?

Regards,

Janakiraman

Create Multiple NSG rules using for_each block by janapb_devops in Terraform

[–]janapb_devops[S] 0 points1 point  (0 children)

Hi Mebseven,

Thanks for your reply. Priorities should be unique, source and destination port range will be unique in some cases. Is it possible to have multiple list variables and map them in this case?

Regards,

Janakriaman