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 - swap to typed sdk #23679

Merged
merged 6 commits into from
Dec 6, 2023
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
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
18 changes: 10 additions & 8 deletions internal/services/authorization/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

type Registration struct {
}
type Registration struct{}

var _ sdk.TypedServiceRegistrationWithAGitHubLabel = Registration{}
var _ sdk.UntypedServiceRegistrationWithAGitHubLabel = Registration{}
var (
_ sdk.TypedServiceRegistrationWithAGitHubLabel = Registration{}
_ sdk.UntypedServiceRegistrationWithAGitHubLabel = Registration{}
)

func (r Registration) AssociatedGitHubLabel() string {
return "service/authorization"
Expand All @@ -33,28 +34,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{
RoleDefinitionDataSource{},
}
}

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