Skip to content

Commit

Permalink
feat: alzlib 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-FFFFFF committed Aug 3, 2023
1 parent 8fb95f8 commit 4c0b58e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Azure/terraform-provider-alz
go 1.20

require (
github.com/Azure/alzlib v0.4.2
github.com/Azure/alzlib v0.5.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Azure/alzlib v0.4.2 h1:l7Jfau2GQomzvWM0qfOssK57b4ka2QoYV+jvSQ6Kruo=
github.com/Azure/alzlib v0.4.2/go.mod h1:3tok1J/Qu0SoNO1Bm6bolpMrF1dIruuKj7HaukdeGJE=
github.com/Azure/alzlib v0.5.0 h1:bQfP09WFkT4KuLlzhrIUUVl5wTk0Y5IiSuk+0Yh2tDU=
github.com/Azure/alzlib v0.5.0/go.mod h1:3tok1J/Qu0SoNO1Bm6bolpMrF1dIruuKj7HaukdeGJE=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 h1:8q4SaHjFsClSvuVne0ID/5Ka8u3fcIHyqkLjcFpNRHQ=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=
Expand Down
18 changes: 9 additions & 9 deletions internal/provider/archetype_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type mapTypes interface {
armpolicy.SetDefinition |
armauthorization.RoleAssignment |
armauthorization.RoleDefinition |
alzlib.PolicyAssignmentAdditionalRoleAssignments
alzlib.PolicyRoleAssignments
}

// checkExistsInAlzLib is a helper struct to check if an item exists in the AlzLib.
Expand Down Expand Up @@ -82,11 +82,11 @@ type ArchetypeDataSourceModel struct {
SubscriptionIds types.Set `tfsdk:"subscription_ids"` // set of string
}

// AlzPolicyRoleAssignmentType is a representation of the additional policy assignments
// AlzPolicyRoleAssignmentType is a representation of the policy assignments
// that must be created when assigning a given policy.
type AlzPolicyRoleAssignmentType struct {
RoleDefinitionIds types.Set `tfsdk:"role_definition_ids"`
AdditionalScopes types.Set `tfsdk:"additional_scopes"`
Scopes types.Set `tfsdk:"scopes"`
}

// ArchetypeDataSourceModelDefaults describes the defaults used in the alz data processing.
Expand Down Expand Up @@ -396,8 +396,8 @@ func (d *ArchetypeDataSource) Schema(ctx context.Context, req datasource.SchemaR
Computed: true,
},

"additional_scopes": schema.SetAttribute{
MarkdownDescription: "A set of additional scopes to assign with the policy assignment.",
"scopes": schema.SetAttribute{
MarkdownDescription: "A set of scopes to assign with the policy assignment.",
ElementType: types.StringType,
Computed: true,
},
Expand Down Expand Up @@ -625,7 +625,7 @@ func (d *ArchetypeDataSource) Read(ctx context.Context, req datasource.ReadReque
data.AlzRoleDefinitions = m

tflog.Debug(ctx, "Converting additional role assignments")
policyras, diags := convertAlzPolicyRoleAssignments(ctx, mg.GetAdditionalRoleAssignmentsByPolicyAssignmentMap())
policyras, diags := convertAlzPolicyRoleAssignments(ctx, mg.GetPolicyRoleAssignmentsMap())
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
Expand All @@ -637,17 +637,17 @@ func (d *ArchetypeDataSource) Read(ctx context.Context, req datasource.ReadReque
}

// convertAlzPolicyRoleAssignments converts a map[string]alzlib.PolicyAssignmentAdditionalRoleAssignments to a map[string]AlzPolicyRoleAssignmentType.
func convertAlzPolicyRoleAssignments(ctx context.Context, m map[string]alzlib.PolicyAssignmentAdditionalRoleAssignments) (map[string]AlzPolicyRoleAssignmentType, diag.Diagnostics) {
func convertAlzPolicyRoleAssignments(ctx context.Context, m map[string]alzlib.PolicyRoleAssignments) (map[string]AlzPolicyRoleAssignmentType, diag.Diagnostics) {
res := make(map[string]AlzPolicyRoleAssignmentType, len(m))
diags := make(diag.Diagnostics, 0)
for k, v := range m {
raset, d := types.SetValueFrom(ctx, types.StringType, v.RoleDefinitionIds)
diags.Append(d...)
adscopeset, d := types.SetValueFrom(ctx, types.StringType, v.AdditionalScopes)
scopeset, d := types.SetValueFrom(ctx, types.StringType, v.Scopes)
diags.Append(d...)
res[k] = AlzPolicyRoleAssignmentType{
RoleDefinitionIds: raset,
AdditionalScopes: adscopeset,
Scopes: scopeset,
}
}
return res, diags
Expand Down
14 changes: 7 additions & 7 deletions internal/provider/archetype_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,16 @@ func TestConvertAlzPolicyRoleAssignments(t *testing.T) {
assert.Empty(t, diags)

// Test with empty input
res, diags = convertAlzPolicyRoleAssignments(context.Background(), make(map[string]alzlib.PolicyAssignmentAdditionalRoleAssignments))
res, diags = convertAlzPolicyRoleAssignments(context.Background(), make(map[string]alzlib.PolicyRoleAssignments))
assert.NotNil(t, res)
assert.Empty(t, res)
assert.Empty(t, diags)

// Test with non-empty input
src := map[string]alzlib.PolicyAssignmentAdditionalRoleAssignments{
src := map[string]alzlib.PolicyRoleAssignments{
"assignment1": {
RoleDefinitionIds: []string{"role1", "role2"},
AdditionalScopes: []string{"scope1", "scope2"},
Scopes: []string{"scope1", "scope2"},
},
}
res, diags = convertAlzPolicyRoleAssignments(context.Background(), src)
Expand All @@ -298,14 +298,14 @@ func TestConvertAlzPolicyRoleAssignments(t *testing.T) {
for k, v := range src {
assert.Contains(t, res, k)
assert.Len(t, res[k].RoleDefinitionIds.Elements(), len(v.RoleDefinitionIds))
assert.Len(t, res[k].AdditionalScopes.Elements(), len(v.AdditionalScopes))
assert.Len(t, res[k].Scopes.Elements(), len(v.Scopes))
for i, rd := range v.RoleDefinitionIds {
assert.Contains(t, res[k].RoleDefinitionIds.Elements(), types.StringValue(rd))
assert.Equal(t, rd, res[k].RoleDefinitionIds.Elements()[i].(basetypes.StringValue).ValueString()) //nolint:forcetypeassert
}
for i, as := range v.AdditionalScopes {
assert.Contains(t, res[k].AdditionalScopes.Elements(), types.StringValue(as))
assert.Equal(t, as, res[k].AdditionalScopes.Elements()[i].(basetypes.StringValue).ValueString()) //nolint:forcetypeassert
for i, as := range v.Scopes {
assert.Contains(t, res[k].Scopes.Elements(), types.StringValue(as))
assert.Equal(t, as, res[k].Scopes.Elements()[i].(basetypes.StringValue).ValueString()) //nolint:forcetypeassert
}
}
}
Expand Down

0 comments on commit 4c0b58e

Please sign in to comment.