Skip to content

Commit

Permalink
Create azurerm_role_management_policy resource
Browse files Browse the repository at this point in the history
  • Loading branch information
oWretch committed May 8, 2024
1 parent e5e3de2 commit 502a588
Show file tree
Hide file tree
Showing 3 changed files with 1,139 additions and 0 deletions.
45 changes: 45 additions & 0 deletions internal/services/authorization/parse/role_management_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package parse

import (
"fmt"
"strings"

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

type RoleManagementPolicyId struct {
Scope string
Name string
}

var _ resourceids.Id = RoleManagementPolicyId{}

func NewRoleManagementPolicyID(scope, name string) *RoleManagementPolicyId {
return &RoleManagementPolicyId{
Scope: scope,
Name: name,
}
}

func RoleManagementPolicyID(id string) (*RoleManagementPolicyId, error) {
parts := strings.Split(id, "/providers/Microsoft.Authorization/roleManagementPolicies/")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid role management policy ID: %s", id)
}

return NewRoleManagementPolicyID(parts[0], parts[1]), nil
}

func (id RoleManagementPolicyId) ID() string {
fmtString := "%s/providers/Microsoft.Authorization/roleManagementPolicies/%s"
return fmt.Sprintf(fmtString, id.Scope, id.Name)
}

func (id RoleManagementPolicyId) String() string {
segments := []string{
fmt.Sprintf("Scope %q", id.Scope),
fmt.Sprintf("Policy Name %q", id.Name),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Role Management Policy ID", segmentsStr)
}
1 change: 1 addition & 0 deletions internal/services/authorization/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (r Registration) Resources() []sdk.Resource {
PimEligibleRoleAssignmentResource{},
RoleAssignmentMarketplaceResource{},
RoleDefinitionResource{},
RoleManagementPolicyResource{},
}
return resources
}

0 comments on commit 502a588

Please sign in to comment.