-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource -
azurerm_role_assignment_marketplace
(#22398)
* add code * add code * format * fix build * fix test * fix lint * fix lint * resolve comments * rename `azurerm_role_assignment_marketplace` to `azurerm_marketplace_role_assignment` * fix gen check
- Loading branch information
1 parent
fa2efb0
commit 49bf0dc
Showing
44 changed files
with
3,273 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
internal/services/authorization/parse/id_scopedroleassignment.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/authorization/2022-04-01/roleassignments" | ||
) | ||
|
||
type ScopedRoleAssignmentId struct { | ||
ScopedId roleassignments.ScopedRoleAssignmentId | ||
TenantId string | ||
} | ||
|
||
func NewScopedRoleAssignmentID(scope string, roleAssignmentName string, tenantId string) ScopedRoleAssignmentId { | ||
return ScopedRoleAssignmentId{ | ||
ScopedId: roleassignments.NewScopedRoleAssignmentID(scope, roleAssignmentName), | ||
TenantId: tenantId, | ||
} | ||
} | ||
|
||
func ScopedRoleAssignmentID(input string) (*ScopedRoleAssignmentId, error) { | ||
azureResourceId, tenantId := DestructRoleAssignmentId(input) | ||
scopedId, err := roleassignments.ParseScopedRoleAssignmentID(azureResourceId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ScopedRoleAssignmentId{ScopedId: *scopedId, TenantId: tenantId}, nil | ||
} | ||
|
||
func ValidateScopedRoleAssignmentID(input interface{}, key string) (warnings []string, errors []error) { | ||
v, ok := input.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected %q to be a string", key)) | ||
return | ||
} | ||
|
||
if _, err := ScopedRoleAssignmentID(v); err != nil { | ||
errors = append(errors, err) | ||
} | ||
|
||
return | ||
} | ||
|
||
func (id ScopedRoleAssignmentId) ID() string { | ||
return ConstructRoleAssignmentId(id.ScopedId.ID(), id.TenantId) | ||
} | ||
|
||
func (id ScopedRoleAssignmentId) String() string { | ||
components := []string{ | ||
id.ScopedId.String(), | ||
} | ||
|
||
if id.TenantId != "" { | ||
components = append(components, fmt.Sprintf("Tenant ID: %s", id.TenantId)) | ||
} | ||
|
||
return fmt.Sprintf("Scoped Role Assignment (%s)", strings.Join(components, "\n")) | ||
} |
124 changes: 124 additions & 0 deletions
124
internal/services/authorization/parse/id_scopedroleassignment_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/authorization/2022-04-01/roleassignments" | ||
) | ||
|
||
func TestScopedRoleAssignmentID(t *testing.T) { | ||
testData := []struct { | ||
Input string | ||
Error bool | ||
Expected *ScopedRoleAssignmentId | ||
}{ | ||
{ | ||
Input: "", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
Input: "/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
Input: "/providers/Microsoft.Marketplace/providers/Microsoft.Authorization/roleAssignments/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
Input: "/providers/Microsoft.Subscription/providers/Microsoft.Authorization/roleAssignments/23456781-2349-8764-5631-234567890121", | ||
Expected: &ScopedRoleAssignmentId{ | ||
ScopedId: roleassignments.NewScopedRoleAssignmentID("/providers/Microsoft.Subscription", "23456781-2349-8764-5631-234567890121"), | ||
}, | ||
}, | ||
|
||
{ | ||
Input: "/providers/Microsoft.Marketplace/providers/Microsoft.Authorization/roleAssignments/23456781-2349-8764-5631-234567890121", | ||
Expected: &ScopedRoleAssignmentId{ | ||
ScopedId: roleassignments.NewScopedRoleAssignmentID("/providers/Microsoft.Marketplace", "23456781-2349-8764-5631-234567890121"), | ||
}, | ||
}, | ||
|
||
{ | ||
Input: "/providers/Microsoft.Marketplace/providers/Microsoft.Authorization/roleAssignments/23456781-2349-8764-5631-234567890121|12345678-1234-5678-1234-567890123456", | ||
Expected: &ScopedRoleAssignmentId{ | ||
ScopedId: roleassignments.NewScopedRoleAssignmentID("/providers/Microsoft.Marketplace", "23456781-2349-8764-5631-234567890121"), | ||
TenantId: "12345678-1234-5678-1234-567890123456", | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Input) | ||
|
||
actual, err := ScopedRoleAssignmentID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
continue | ||
} | ||
|
||
t.Fatalf("expected a value but got an error: %+v", err) | ||
} | ||
|
||
if v.Error { | ||
t.Fatal("Expect an error but didn't get one") | ||
} | ||
|
||
if actual.ScopedId.RoleAssignmentName != v.Expected.ScopedId.RoleAssignmentName { | ||
t.Fatalf("Expected %q but got %q for Role Assignment Name", v.Expected.ScopedId.RoleAssignmentName, actual.ScopedId.RoleAssignmentName) | ||
} | ||
|
||
if actual.TenantId != v.Expected.TenantId { | ||
t.Fatalf("Expected %q but got %q for Tenant ID", v.Expected.TenantId, actual.TenantId) | ||
} | ||
} | ||
} | ||
|
||
func TestValidateScopedRoleAssignmentID(t *testing.T) { | ||
cases := []struct { | ||
Input string | ||
Valid bool | ||
}{ | ||
|
||
{ | ||
Input: "", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "/providers/Microsoft.Marketplace/providers/Microsoft.Authorization/roleAssignments/", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "/providers/Microsoft.Subscription/providers/Microsoft.Authorization/roleAssignments/23456781-2349-8764-5631-234567890121", | ||
Valid: true, | ||
}, | ||
|
||
{ | ||
Input: "/providers/Microsoft.Marketplace/providers/Microsoft.Authorization/roleAssignments/23456781-2349-8764-5631-234567890121", | ||
Valid: true, | ||
}, | ||
|
||
{ | ||
Input: "/providers/Microsoft.Marketplace/providers/Microsoft.Authorization/roleAssignments/23456781-2349-8764-5631-234567890121|12345678-1234-5678-1234-567890123456", | ||
Valid: true, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Logf("[DEBUG] Testing Value %s", tc.Input) | ||
_, errors := ValidateScopedRoleAssignmentID(tc.Input, "test") | ||
valid := len(errors) == 0 | ||
|
||
if tc.Valid != valid { | ||
t.Fatalf("Expected %t but got %t", tc.Valid, valid) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
internal/services/authorization/role_assignment_marketplace_resource.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package authorization | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/authorization/parse" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
const ( | ||
MarketplaceScope = "/providers/Microsoft.Marketplace" | ||
) | ||
|
||
var _ sdk.Resource = RoleAssignmentMarketplaceResource{} | ||
|
||
type RoleAssignmentMarketplaceResource struct { | ||
base roleAssignmentBaseResource | ||
} | ||
|
||
func (r RoleAssignmentMarketplaceResource) Arguments() map[string]*pluginsdk.Schema { | ||
return r.base.arguments() | ||
} | ||
|
||
func (r RoleAssignmentMarketplaceResource) Attributes() map[string]*pluginsdk.Schema { | ||
return r.base.attributes() | ||
} | ||
|
||
func (r RoleAssignmentMarketplaceResource) Create() sdk.ResourceFunc { | ||
return r.base.createFunc(r.ResourceType(), MarketplaceScope) | ||
} | ||
|
||
func (r RoleAssignmentMarketplaceResource) Delete() sdk.ResourceFunc { | ||
return r.base.deleteFunc() | ||
} | ||
|
||
func (r RoleAssignmentMarketplaceResource) Read() sdk.ResourceFunc { | ||
return r.base.readFunc(MarketplaceScope, true) | ||
} | ||
|
||
func (r RoleAssignmentMarketplaceResource) ResourceType() string { | ||
return "azurerm_marketplace_role_assignment" | ||
} | ||
|
||
func (r RoleAssignmentMarketplaceResource) ModelObject() interface{} { | ||
return nil | ||
} | ||
|
||
func (r RoleAssignmentMarketplaceResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return parse.ValidateScopedRoleAssignmentID | ||
} |
Oops, something went wrong.