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

Can't use PIM Assignment - Resource Group with for_each #1

Closed
MohnJadden opened this issue Jun 7, 2022 · 2 comments · Fixed by #3
Closed

Can't use PIM Assignment - Resource Group with for_each #1

MohnJadden opened this issue Jun 7, 2022 · 2 comments · Fixed by #3

Comments

@MohnJadden
Copy link

I am trying to use the PIM Assignment - Resource Group module with for_each and lookups in TF. The use case is so that we can set a security group as a variable, then have that security group be granted RBAC roles, and in this case, the PIM assignment as well.

The main.tf portion is as follows:

module "pim_assignment_2" {

  source               = "./PIM Assignment - Resource Group"
  for_each             = var.team_name
  resource_group_name  = azurerm_resource_group.test-vdi-rg.name
  principal_id         = lookup(var.SecurityGroup, each.key)
  role_definition_name = "Virtual Machine Administrator Login"
}

When I run terraform plan, I get the following error:

│ Error: Module module.pim_assignment_2 contains provider configuration
│
│ Providers cannot be configured within modules using count, for_each or depends_on.

How should we utilize the module to create one PIM assignment in a for_each situation?

@mariussm
Copy link
Contributor

Hi @MohnJadden , could you try out the branch linked to this issue, to see if removing the provider configuration helps for this? I know there is a limitation here somewhere in Terraform when using for_each and count, though, but try it out.

@MohnJadden
Copy link
Author

That seems to have resolved the issue - I did have to tweak main.tf to use [each.key] instead of .name since I'm using arrays, but the original issue was resolved with this build. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants