Skip to content

Commit

Permalink
Update based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
oWretch committed Jun 4, 2024
1 parent 8a81eda commit be4c521
Show file tree
Hide file tree
Showing 4 changed files with 574 additions and 214 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package parse

import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

// Resource Manager Role Definition ID
type RoleDefinitionResourceId struct {
RoleDefinitionId string
Scope string
}

var _ resourceids.Id = RoleDefinitionResourceId{}

func NewRoleDefinitionResourceId(roleDefinitionId, scope string) RoleDefinitionResourceId {
return RoleDefinitionResourceId{
RoleDefinitionId: roleDefinitionId,
Scope: scope,
}
}

// ParseSubscriptionID parses 'input' into a RoleDefinitionResourceID
func ParseRoleDefinitionResourceId(input string) (*RoleDefinitionResourceId, error) {
segments := strings.Split(input, "/providers/Microsoft.Authorization/roleDefinitions/")
switch {
case strings.HasPrefix(input, "/subscriptions/"):
return &RoleDefinitionResourceId{
Scope: segments[0],
RoleDefinitionId: segments[1],
}, nil
case strings.HasPrefix(input, "/providers/"):
return &RoleDefinitionResourceId{
RoleDefinitionId: segments[0],
}, nil
default:
return nil, fmt.Errorf("could not parse Role Definition ID, invalid format %q", input)
}
}

func (id RoleDefinitionResourceId) ID() string {
return fmt.Sprintf("%s/providers/Microsoft.Authorization/roleDefinitions/%s", id.Scope, id.RoleDefinitionId)
}

func (id RoleDefinitionResourceId) String() string {
components := []string{
fmt.Sprintf("Role Definition ID: %q", id.RoleDefinitionId),
}
if id.Scope != "" {
components = append(components, fmt.Sprintf("Scope: %q", id.Scope))
}
return fmt.Sprintf("Role Definition (%s)", strings.Join(components, "\n"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ func TestRoleManagementPolicyDataSource_resourceGroup(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_role_management_policy", "test")
r := RoleManagementPolicyDataSource{}

// Ignore the dangling resource post-test as the policy remains while the group is in a pending deletion state
data.ResourceTestSkipCheckDestroyed(t, []acceptance.TestStep{
data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.resourceGroup(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -38,8 +37,7 @@ func TestRoleManagementPolicyDataSource_managementGroup(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_role_management_policy", "test")
r := RoleManagementPolicyDataSource{}

// Ignore the dangling resource post-test as the policy remains while the group is in a pending deletion state
data.ResourceTestSkipCheckDestroyed(t, []acceptance.TestStep{
data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.managementGroup(data),
Check: acceptance.ComposeTestCheckFunc(
Expand Down
Loading

0 comments on commit be4c521

Please sign in to comment.