使用terraform输出CSV文件



我正在尝试使用地形变量数据(CSV文件(来创建资源组,资源组的名称将添加到CSV文件中。

我当前遇到以下错误。

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: 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.
╵

更新错误消息

╷
│ 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.

您的代码应该是(假设这次您发布了正确的代码(:

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

由于没有显示./test.csv,因此很难推测其内容和在代码中的使用。

假设您的CSV文件具有如下标题姓名、地点、ABC、XXY、CDF、您的

那么你也可以在这里使用for_each

locals {
resource_groupname = csvdecode(file("./test.csv"))
}
resource "azurerm_resource_group" "Main" {
for_each = { for inst in locals.resource_groupname) : inst.location=> inst 
}

name = each.value.name
location =  each.value.location
} 

相关内容

  • 没有找到相关文章

最新更新