我需要将PowerShell脚本上传到创建的第一个存储帐户上的容器中。我在www.example.com上有var.tf:
locals {
sta_ctn = {
"exploitation" = { sta = azurerm_storage_account.terra_sta[0].name, access_type = "private" }
}
如果有一天我需要创建另一个容器,我使用了foreach。我在storage_account.tf中有这个:
resource "azurerm_storage_container" "terra_sta_ctn" {
for_each = local.sta_ctn
name = each.key
storage_account_name = each.value.sta
container_access_type = each.value.access_type
}
resource "azurerm_storage_blob" "terra_sta_ctn_ansible" {
name = "ConfigureRemotingForAnsible.ps1"
storage_account_name = azurerm_storage_account.terra_sta[0].name
storage_container_name = azurerm_storage_container.terra_sta_ctn[0].name
type = "Block"
source = "${path.root}/_scripts/ansible/ConfigureRemotingForAnsible.ps1"
}
错误是:
│ Error: Invalid index
│
│ on storage_account.tf line 26, in resource "azurerm_storage_blob" "terra_sta_ctn_ansible":
│ 26: storage_container_name = azurerm_storage_container.terra_sta_ctn[0].name
│ ├────────────────
│ │ azurerm_storage_container.terra_sta_ctn is object with 1 attribute "exploitation"
│
│ The given key does not identify an element in this collection value. An object only supports looking up attributes by name, not by numeric index.
“0”在这一行“26:storage_container_name = azurerm_storage_container.terra_sta_ctn[0].name”带下划线。但“exploitation”是我的容器的名称。需要的正是这个名称。
我还需要做什么?
1条答案
按热度按时间ozxc1zmp1#
由于您在
terra_sta_ctn
中使用for_each
,因此您也应该在terra_sta_ctn_ansible
中使用for_each
:附言
你还没有展示
terra_sta
是什么,所以不可能推测azurerm_storage_account.terra_sta[0].name
是否正确。