Skip to content

Commit

Permalink
r/role_definition: fixing a crash when expanding permissions block
Browse files Browse the repository at this point in the history
Fixes #9815
  • Loading branch information
tombuildsstuff committed Jan 14, 2021
1 parent 98f66b5 commit 49060b9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ func expandRoleDefinitionPermissions(input []interface{}) []authorization.Permis
}

for _, v := range input {
if v == nil {
continue
}

input := v.(map[string]interface{})
permission := authorization.Permission{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,22 @@ func testAccRoleDefinition_emptyName(t *testing.T) {
})
}

func testAccRoleDefinition_managementGroup(t *testing.T) {
func TestAccRoleDefinition_emptyPermissions(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_definition", "test")
r := RoleDefinitionResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.emptyPermissions(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccRoleDefinition_managementGroup(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_definition", "test")
r := RoleDefinitionResource{}

Expand Down Expand Up @@ -327,6 +342,28 @@ resource "azurerm_role_definition" "test" {
`, data.RandomInteger)
}

func (r RoleDefinitionResource) emptyPermissions(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
data "azurerm_subscription" "primary" {
}
resource "azurerm_resource_group" "test" {
name = "acctestrg-%d"
location = %q
}
resource "azurerm_role_definition" "test" {
name = "acctestrd-%d"
scope = azurerm_resource_group.test.id
assignable_scopes = [azurerm_resource_group.test.id]
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (r RoleDefinitionResource) TestAccRoleDefinition_managementGroup(id string, data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down

0 comments on commit 49060b9

Please sign in to comment.