Skip to content

Commit

Permalink
swap to typed sdk
Browse files Browse the repository at this point in the history
Signed-off-by: ziyeqf <[email protected]>
  • Loading branch information
ziyeqf committed Nov 1, 2023
1 parent 2f0b375 commit 01c8e59
Show file tree
Hide file tree
Showing 4 changed files with 565 additions and 494 deletions.
27 changes: 27 additions & 0 deletions internal/services/authorization/parse/role_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package parse
import (
"fmt"
"strings"

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

type RoleDefinitionID struct {
Expand All @@ -14,6 +16,31 @@ type RoleDefinitionID struct {
RoleID string
}

var _ resourceids.ResourceId = RoleDefinitionID{}

func (r RoleDefinitionID) ID() string {
return fmt.Sprintf("%s|%s", r.ResourceID, r.Scope)
}

func (r RoleDefinitionID) String() string {
components := []string{
fmt.Sprintf("Resource ID: %q", r.ResourceID),
fmt.Sprintf("Scope: %q", r.Scope),
fmt.Sprintf("Role Definition: %q", r.RoleID),
}
return fmt.Sprintf("Role Definition (%s)", strings.Join(components, "\n"))
}

func (r RoleDefinitionID) Segments() []resourceids.Segment {
return []resourceids.Segment{
resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"),
resourceids.StaticSegment("staticProviders", "providers", "providers"),
resourceids.ResourceProviderSegment("staticMicrosoftAuthorization", "Microsoft.Authorization", "Microsoft.Authorization"),
resourceids.StaticSegment("staticRoleDefinitions", "roleDefinitions", "roleDefinitions"),
resourceids.UserSpecifiedSegment("roleDefinitionId", "roleDefinitionIdValue"),
}
}

// RoleDefinitionId is a pseudo ID for storing Scope parameter as this it not retrievable from API
// It is formed of the Azure Resource ID for the Role and the Scope it is created against
func RoleDefinitionId(input string) (*RoleDefinitionID, error) {
Expand Down
9 changes: 5 additions & 4 deletions internal/services/authorization/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,29 @@ func (r Registration) WebsiteCategories() []string {
// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource {
return map[string]*pluginsdk.Resource{
"azurerm_client_config": dataSourceArmClientConfig(),
"azurerm_role_definition": dataSourceArmRoleDefinition(),
"azurerm_client_config": dataSourceArmClientConfig(),
}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {
return map[string]*pluginsdk.Resource{
"azurerm_role_assignment": resourceArmRoleAssignment(),
"azurerm_role_definition": resourceArmRoleDefinition(),
}
}

func (r Registration) DataSources() []sdk.DataSource {
return []sdk.DataSource{}
return []sdk.DataSource{
ArmRoleDefinitionDataSource{},
}
}

func (r Registration) Resources() []sdk.Resource {
resources := []sdk.Resource{
PimActiveRoleAssignmentResource{},
PimEligibleRoleAssignmentResource{},
RoleAssignmentMarketplaceResource{},
ArmRoleDefinitionResource{},
}
return resources
}
Loading

0 comments on commit 01c8e59

Please sign in to comment.