Closed benkelly89 closed 2 years ago
@benkelly89 I've locally tested with below config, it works fine for me:
locals {
files = toset(["a.txt", "b.txt"])
}
#...
resource "azurerm_storage_share_file" "example" {
for_each = local.files
name = "mycontent-${each.key}"
storage_share_id = azurerm_storage_share.example.id
source = each.key
}
Could you please share the TF config which can reproduce this issue?
Hi
This is the code,
locals {
content_file_list = { for entry in flatten([for key in keys(local.vm_list) : [for file in fileset("${path.module}/palo/content","*") : {instance = key,file = file}]]) : "${entry.instance}_${replace(entry.file,".","-")}" => entry }
}
resource "azurerm_storage_share_file" "pa_content" {
for_each = local.content_file_list
name = each.value.file
path = azurerm_storage_share_directory.content[each.value.instance].name
storage_share_id = azurerm_storage_share.pa-bootstrap.id
source = "${path.module}/palo/content/${each.value.file}"
}
This will generate a sample map as obviously the above references locals that aren't apparent { for entry in flatten([for key in keys({pa-1="byol",pa-2="payg"}) : [for file in fileset("/","*") : {instance = key,file = file}]]) : "${entry.instance}_${replace(entry.file,".","-")}" => entry }
Basically we are bootstrapping Palo Alto's, we have to create a bootstrap package per Palo, as part fo that we want to include any necessary content updates. The point of this is that it will take each file that is in the content folder and upload it to each Palo's bootstrap package.
The plan is fine, it works out exactly what it needs to, but hit that error on apply.
@benkelly89 Thanks! The issue is not due to the usage of for_each
, but a bug in the SDK, which is triggered once any file's size is bigger than 16MB * runtime.NumCPU()
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Having an issue were whenever I try to use for_each with azurerm_storage_share_file. I get the below error. I've tried on both version 2.93 and 2.99 of the provider, also on terraform version 1.1.4 and 1.1.7.
The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
Stack trace from the terraform-provider-azurerm_v2.99.0_x5 plugin:
panic: sync: negative WaitGroup counter
goroutine 145 [running]: sync.(WaitGroup).Add(0x675e8a0, 0xc001066080) /opt/goenv/versions/1.17.5/src/sync/waitgroup.go:74 +0x105 sync.(WaitGroup).Done(...) /opt/goenv/versions/1.17.5/src/sync/waitgroup.go:99 github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files.Client.PutFile.func1(0xb) /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files/range_put_file.go:56 +0x2c5 created by github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files.Client.PutFile /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files/range_put_file.go:40 +0x23e
Error: The terraform-provider-azurerm_v2.99.0_x5 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely helpful if you could report the crash with the plugin's maintainers so that it can be fixed. The output above should help diagnose the issue.
[error]Bash exited with code '1'.
Finishing: Terraform Apply