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 authored and jackofallops committed Mar 24, 2021
1 parent 47bd5c3 commit e20ab99
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
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 @@ -16,7 +16,7 @@ import (

type RoleDefinitionResource struct{}

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

Expand All @@ -31,7 +31,7 @@ func TestAccAzureRMRoleDefinition_basic(t *testing.T) {
})
}

func TestAccAzureRMRoleDefinition_requiresImport(t *testing.T) {
func TestAccRoleDefinition_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_definition", "test")
id := uuid.New().String()

Expand All @@ -50,7 +50,7 @@ func TestAccAzureRMRoleDefinition_requiresImport(t *testing.T) {
})
}

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

Expand All @@ -65,7 +65,7 @@ func TestAccAzureRMRoleDefinition_complete(t *testing.T) {
})
}

func TestAccAzureRMRoleDefinition_update(t *testing.T) {
func TestAccRoleDefinition_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_definition", "test")
r := RoleDefinitionResource{}
id := uuid.New().String()
Expand All @@ -88,7 +88,7 @@ func TestAccAzureRMRoleDefinition_update(t *testing.T) {
})
}

func TestAccAzureRMRoleDefinition_updateEmptyId(t *testing.T) {
func TestAccRoleDefinition_updateEmptyId(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_definition", "test")

r := RoleDefinitionResource{}
Expand All @@ -111,7 +111,7 @@ func TestAccAzureRMRoleDefinition_updateEmptyId(t *testing.T) {
})
}

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

Expand All @@ -126,7 +126,22 @@ func TestAccAzureRMRoleDefinition_emptyName(t *testing.T) {
})
}

func TestAccAzureRMRoleDefinition_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 All @@ -141,7 +156,7 @@ func TestAccAzureRMRoleDefinition_managementGroup(t *testing.T) {
})
}

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

Expand All @@ -156,7 +171,7 @@ func TestAccAzureRMRoleDefinition_assignToSmallerScope(t *testing.T) {
})
}

func TestAccAzureRMRoleDefinition_noAssignableScope(t *testing.T) {
func TestAccRoleDefinition_noAssignableScope(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_definition", "test")

r := RoleDefinitionResource{}
Expand Down Expand Up @@ -341,6 +356,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 (RoleDefinitionResource) managementGroup(id string, data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down

0 comments on commit e20ab99

Please sign in to comment.