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_role_definition crashes when all permissions are empty #9815

Closed
iscanteck opened this issue Dec 10, 2020 · 2 comments · Fixed by #9850
Closed

azurerm_role_definition crashes when all permissions are empty #9815

iscanteck opened this issue Dec 10, 2020 · 2 comments · Fixed by #9850

Comments

@iscanteck
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Terraform v0.13.3

  • provider registry.terraform.io/hashicorp/azuread v1.0.0
  • provider registry.terraform.io/hashicorp/azurerm v2.40.0
  • provider registry.terraform.io/hashicorp/random v3.0.0

Affected Resource(s)

  • azurerm_role_definition

Terraform Configuration Files

resource "azurerm_role_definition" "AppServiceNothing" {
  scope             = data.azurerm_management_group.default.id
  name              = "AppServiceNothing"
  assignable_scopes = [data.azurerm_management_group.default.id]
  permissions {
    actions = []
    not_actions = []
    data_actions = []
    not_data_actions = []
  }
}

Debug Output

Panic Output

panic: interface conversion: interface {} is nil, not map[string]interface {}
2020-12-10T21:42:10.698Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 
2020-12-10T21:42:10.698Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: goroutine 30 [running]:
2020-12-10T21:42:10.698Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/authorization.expandRoleDefinitionPermissions(0xc000b72d20, 0xc000fa3b00, 0xb, 0x45dafe0)
2020-12-10T21:42:10.698Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/authorization/role_definition_resource.go:255 +0xb47
2020-12-10T21:42:10.698Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/authorization.resourceArmRoleDefinitionCreateUpdate(0xc000b72d20, 0x46f2220, 0xc001277b00, 0x0, 0x0)
2020-12-10T21:42:10.698Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/authorization/role_definition_resource.go:147 +0x268
2020-12-10T21:42:10.698Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc0001ffb00, 0xc0007a5360, 0xc000fa2c60, 0x46f2220, 0xc001277b00, 0x471ba01, 0xc000f15b08, 0xc000fb1830)
2020-12-10T21:42:10.698Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:310 +0x365
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc000812300, 0xc000f87a10, 0xc0007a5360, 0xc000fa2c60, 0xc000fa9ca8, 0xc00000e9e8, 0x471dcc0)
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider.go:294 +0x99
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000808108, 0x5712e20, 0xc000f9fec0, 0xc000b727e0, 0xc000808108, 0xc000f9fec0, 0xc000ddab78)
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin/grpc_provider.go:885 +0x8b4
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x4b418a0, 0xc000808108, 0x5712e20, 0xc000f9fec0, 0xc0005f4900, 0x0, 0x5712e20, 0xc000f9fec0, 0xc0000edc00, 0x3a3)
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5/tfplugin5.pb.go:3305 +0x217
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: google.golang.org/grpc.(*Server).processUnaryRPC(0xc0006c2900, 0x575d9c0, 0xc0006c3380, 0xc0011be400, 0xc000610de0, 0x8a56980, 0x0, 0x0, 0x0)
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1024 +0x501
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: google.golang.org/grpc.(*Server).handleStream(0xc0006c2900, 0x575d9c0, 0xc0006c3380, 0xc0011be400, 0x0)
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1313 +0xd3d
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc000c8ef10, 0xc0006c2900, 0x575d9c0, 0xc0006c3380, 0xc0011be400)
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:722 +0xa1
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: created by google.golang.org/grpc.(*Server).serveStreams.func1
2020-12-10T21:42:10.699Z [DEBUG] plugin.terraform-provider-azurerm_v2.40.0_x5: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:720 +0xa1

Expected Behaviour

Should show valid error message.

Actual Behaviour

Terraform crashes

Steps to Reproduce

  1. terraform apply

Important Factoids

References

jackofallops added a commit that referenced this issue Mar 25, 2021
…permissions optional (#9850)

* r/role_definition: making the `permissions` block optional

The API returns an empty list if an empty permissions block is sent
but also allows sending an empty list - so it appears that this isn't
required.

* r/role_definition: fixing a crash when expanding permissions block

Fixes #9815

* r/role_definition: documenting that the `permissions` block is now optional

* r/role_definition: splitting out the Update and polling until it's settled down

Turns out the Update call is eventually consistent - where a new Role Definition
gets created and then reconciled on the backend. This new Role Definition has a
new CreatedOn and UpdatedOn, so it's possible to determine when this has been
updated - however in testing it can take ~5m for this to settle down.

Whilst it's unfortunate this takes a little longer to settle down, this should
improve the reliability of resources which depend on this.

Unfortunately the Azure SDK doesn't expose these fields in the response, so for
now we're using a wrapped to access them and confirm this has been updated.

* r/role_definition: fixes #3732

* r/role_definition: tests to private so these are run in sequence

* update custompoller for time comparison

* missed some test renames

* add error handling to time parse

* increase timeout and confirmations for consistency checking

* go mod vendor

Co-authored-by: jackofallops <[email protected]>
@ghost
Copy link

ghost commented Mar 26, 2021

This has been released in version 2.53.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.53.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Apr 25, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.