Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_storage_share_file issue with for_each loops #15895

Closed
benkelly89 opened this issue Mar 20, 2022 · 4 comments · Fixed by #16460
Closed

azurerm_storage_share_file issue with for_each loops #15895

benkelly89 opened this issue Mar 20, 2022 · 4 comments · Fixed by #16460
Labels
bug crash sdk/requires-upgrade This is dependent upon upgrading an SDK

Comments

@benkelly89
Copy link

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

@magodo
Copy link
Collaborator

magodo commented Mar 21, 2022

@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?

@benkelly89
Copy link
Author

benkelly89 commented Mar 21, 2022

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.

@magodo
Copy link
Collaborator

magodo commented Mar 22, 2022

@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()

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug crash sdk/requires-upgrade This is dependent upon upgrading an SDK
Projects
None yet
2 participants