terraformterraform-provider-azureterraform0.12+terraform-template-fileterraform-provider-openstack

Output CSV file using terraform


I'm trying to use terraform variable data (CSV file) to create a resource group and the name of the resource group are added into the CSV file.

I'm currently experiencing the below error.

provider "azurerm" {
    features{}
}

locals {
      resource_groupname = csvdecode(file("./test.csv"))
    }

    resource "azurerm_resource_group" "Main" {
      count    = length(locals.resource_groupname)
      name     =  locals.resource_groupname[count.index].groupname   
      location = "North europe"
    } 

Error Message

 Error: Reference to undeclared resource
│
│   on testvariable.tf line 10, in resource "azurerm_resource_group" "Customer11":
│   10:   count    = length(locals.groupname)
│
│ A managed resource "locals" "groupname" has not been declared in the root module.
╵
╷
│ Error: Reference to undeclared resource
│
│   on testvariable.tf line 11, in resource "azurerm_resource_group" "Customer11":
│   11:   name     = data.locals.groupname[count.index].groupname
│
│ A data resource "locals" "groupname" has not been declared in the root module.
╵

Updated Error Messgae

╷
│ Error: Reference to undeclared resource
│
│   on testtf.tf line 10, in resource "azurerm_resource_group" "Main":
│   10:       count    = length(locals.resource_groupname)
│
│ A managed resource "locals" "resource_groupname" has not been declared in the root module.
╵
╷
│ Error: Reference to undeclared resource
│
│   on testtf.tf line 11, in resource "azurerm_resource_group" "Main":
│   11:       name     =  locals.resource_groupname[count.index].groupname
│
│ A managed resource "locals" "resource_groupname" has not been declared in the root module.

Solution

  • Your code should be (assuming this time you posted correct code):

        resource "azurerm_resource_group" "Main" {
          count    = length(local.resource_groupname)
          name     =  local.resource_groupname[count.index].groupname   
          location = "North europe"
        }
    

    Since ./test.csv is not shown its difficult to speculate on its content and the use in your code.