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 - enture role_definition_id is correctly set if left empty after after create #3913

Merged
merged 2 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions azurerm/resource_arm_role_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ func resourceArmRoleDefinitionRead(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error loading Role Definition %q: %+v", d.Id(), err)
}

if id := resp.ID; id != nil {
roleDefinitionId, err := parseRoleDefinitionId(*id)
if err != nil {
return fmt.Errorf("Error parsing Role Definition ID: %+v", err)
}
if roleDefinitionId != nil {
d.Set("role_definition_id", roleDefinitionId.roleDefinitionId)
}
}

if props := resp.RoleDefinitionProperties; props != nil {
d.Set("name", props.RoleName)
d.Set("description", props.Description)
Expand Down
54 changes: 54 additions & 0 deletions azurerm/resource_arm_role_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,40 @@ func TestAccAzureRMRoleDefinition_update(t *testing.T) {
})
}

func TestAccAzureRMRoleDefinition_updateEmptyId(t *testing.T) {
resourceName := "azurerm_role_definition.test"
ri := tf.AccRandTimeInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMRoleDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMRoleDefinition_emptyId(ri),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRoleDefinitionExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "permissions.#", "1"),
resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.#", "1"),
resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.0", "*"),
resource.TestCheckResourceAttr(resourceName, "permissions.0.not_actions.#", "0"),
),
},
{
Config: testAccAzureRMRoleDefinition_updateEmptyId(ri),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRoleDefinitionExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "permissions.#", "1"),
resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.#", "1"),
resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.0", "*"),
resource.TestCheckResourceAttr(resourceName, "permissions.0.not_actions.#", "1"),
resource.TestCheckResourceAttr(resourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/read"),
),
},
},
})
}

func TestAccAzureRMRoleDefinition_emptyName(t *testing.T) {
resourceName := "azurerm_role_definition.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -303,3 +337,23 @@ resource "azurerm_role_definition" "test" {
}
`, rInt)
}

func testAccAzureRMRoleDefinition_updateEmptyId(rInt int) string {
return fmt.Sprintf(`
data "azurerm_subscription" "primary" {}

resource "azurerm_role_definition" "test" {
name = "acctestrd-%d"
scope = "${data.azurerm_subscription.primary.id}"

permissions {
actions = ["*"]
not_actions = ["Microsoft.Authorization/*/read"]
}

assignable_scopes = [
"${data.azurerm_subscription.primary.id}",
]
}
`, rInt)
}