Skip to content

Commit

Permalink
fix role_definition_id for data.azurerm_role_definition
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyeqf committed Dec 25, 2023
1 parent 46a95c1 commit e0f8119
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ func (a RoleDefinitionDataSource) Read() sdk.ResourceFunc {
}

state := RoleDefinitionDataSourceModel{
Scope: config.Scope,
RoleDefinitionId: pointer.From(role.ID),
Scope: config.Scope,
// Though the property is called "Name", it's UUID in fact.
RoleDefinitionId: pointer.From(role.Name),
}

state.Name = pointer.From(role.RoleName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestAccRoleDefinitionDataSource_basic(t *testing.T) {
Config: RoleDefinitionDataSource{}.basic(id, data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists(),
check.That(data.ResourceName).Key("role_definition_id").IsUUID(),
check.That(data.ResourceName).Key("description").Exists(),
check.That(data.ResourceName).Key("type").Exists(),
check.That(data.ResourceName).Key("permissions.#").HasValue("1"),
Expand All @@ -46,6 +47,7 @@ func TestAccRoleDefinitionDataSource_basicByName(t *testing.T) {
Config: RoleDefinitionDataSource{}.byName(id, data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists(),
check.That(data.ResourceName).Key("role_definition_id").IsUUID(),
check.That(data.ResourceName).Key("description").Exists(),
check.That(data.ResourceName).Key("type").Exists(),
check.That(data.ResourceName).Key("permissions.#").HasValue("1"),
Expand All @@ -68,6 +70,7 @@ func TestAccRoleDefinitionDataSource_builtIn_contributor(t *testing.T) {
Config: RoleDefinitionDataSource{}.builtIn("Contributor"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("id").HasValue("/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"),
check.That(data.ResourceName).Key("role_definition_id").IsUUID(),
check.That(data.ResourceName).Key("description").Exists(),
check.That(data.ResourceName).Key("type").Exists(),
check.That(data.ResourceName).Key("permissions.#").HasValue("1"),
Expand Down Expand Up @@ -95,6 +98,8 @@ func TestAccRoleDefinitionDataSource_builtIn_owner(t *testing.T) {
Config: RoleDefinitionDataSource{}.builtIn("Owner"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("id").HasValue("/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"),
check.That(data.ResourceName).Key("role_definition_id").IsUUID(),
check.That(data.ResourceName).Key("role_definition_id").IsUUID(),
check.That(data.ResourceName).Key("description").Exists(),
check.That(data.ResourceName).Key("type").Exists(),
check.That(data.ResourceName).Key("permissions.#").HasValue("1"),
Expand All @@ -114,6 +119,7 @@ func TestAccRoleDefinitionDataSource_builtIn_reader(t *testing.T) {
Config: RoleDefinitionDataSource{}.builtIn("Reader"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("id").HasValue("/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7"),
check.That(data.ResourceName).Key("role_definition_id").IsUUID(),
check.That(data.ResourceName).Key("description").Exists(),
check.That(data.ResourceName).Key("type").Exists(),
check.That(data.ResourceName).Key("permissions.#").HasValue("1"),
Expand All @@ -133,6 +139,7 @@ func TestAccRoleDefinitionDataSource_builtIn_virtualMachineContributor(t *testin
Config: RoleDefinitionDataSource{}.builtIn("Virtual Machine Contributor"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("id").HasValue("/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"),
check.That(data.ResourceName).Key("role_definition_id").IsUUID(),
check.That(data.ResourceName).Key("description").Exists(),
check.That(data.ResourceName).Key("type").Exists(),
check.That(data.ResourceName).Key("permissions.#").HasValue("1"),
Expand Down

0 comments on commit e0f8119

Please sign in to comment.