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_management_policy - notification_rules are no longer Optional/Computed and removing the block will reset them back to the default values provided by Azure #28877

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
270 changes: 162 additions & 108 deletions internal/services/authorization/role_management_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,24 @@ func buildRoleManagementPolicyForUpdate(metadata *sdk.ResourceMetaData, rolePoli
if metadata.ResourceData.HasChange("notification_rules.0.eligible_assignments.0.admin_notifications") {
if notificationAdminAdminEligibilityBase, ok := existingRules["Notification_Admin_Admin_Eligibility"]; ok {
if notificationAdminAdminEligibility, ok := notificationAdminAdminEligibilityBase.(rolemanagementpolicies.RoleManagementPolicyNotificationRule); ok {
if len(model.NotificationRules) == 1 {
if len(model.NotificationRules[0].EligibleAssignments) == 1 {
if len(model.NotificationRules[0].EligibleAssignments[0].AdminNotifications) == 1 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationAdminAdminEligibility,
model.NotificationRules[0].EligibleAssignments[0].AdminNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_assignments.0.admin_notifications.0.additional_recipients"),
),
)
}
}
if len(model.NotificationRules) != 0 && len(model.NotificationRules[0].EligibleAssignments) != 0 && len(model.NotificationRules[0].EligibleAssignments[0].AdminNotifications) != 0 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationAdminAdminEligibility,
model.NotificationRules[0].EligibleAssignments[0].AdminNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_assignments.0.admin_notifications.0.additional_recipients"),
),
)
} else {
updatedRules = append(updatedRules, expandNotificationSettings(
notificationAdminAdminEligibility,
RoleManagementPolicyNotificationSettings{
NotificationLevel: "All",
DefaultRecipients: true,
AdditionalRecipients: []string{},
},
true,
))
}
}
}
Expand All @@ -258,18 +264,24 @@ func buildRoleManagementPolicyForUpdate(metadata *sdk.ResourceMetaData, rolePoli
if metadata.ResourceData.HasChange("notification_rules.0.active_assignments.0.admin_notifications") {
if notificationAdminAdminAssignmentBase, ok := existingRules["Notification_Admin_Admin_Assignment"]; ok {
if notificationAdminAdminAssignment, ok := notificationAdminAdminAssignmentBase.(rolemanagementpolicies.RoleManagementPolicyNotificationRule); ok {
if len(model.NotificationRules) == 1 {
if len(model.NotificationRules[0].ActiveAssignments) == 1 {
if len(model.NotificationRules[0].ActiveAssignments[0].AdminNotifications) == 1 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationAdminAdminAssignment,
model.NotificationRules[0].ActiveAssignments[0].AdminNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.active_assignments.0.admin_notifications.0.additional_recipients"),
),
)
}
}
if len(model.NotificationRules) != 0 && len(model.NotificationRules[0].ActiveAssignments) != 0 && len(model.NotificationRules[0].ActiveAssignments[0].AdminNotifications) != 0 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationAdminAdminAssignment,
model.NotificationRules[0].ActiveAssignments[0].AdminNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.active_assignments.0.admin_notifications.0.additional_recipients"),
),
)
} else {
updatedRules = append(updatedRules, expandNotificationSettings(
notificationAdminAdminAssignment,
RoleManagementPolicyNotificationSettings{
NotificationLevel: "All",
DefaultRecipients: true,
AdditionalRecipients: []string{},
},
true,
))
}
}
}
Expand All @@ -278,18 +290,24 @@ func buildRoleManagementPolicyForUpdate(metadata *sdk.ResourceMetaData, rolePoli
if metadata.ResourceData.HasChange("notification_rules.0.eligible_activations.0.admin_notifications") {
if notificationAdminEndUserAssignmentBase, ok := existingRules["Notification_Admin_EndUser_Assignment"]; ok {
if notificationAdminEndUserAssignment, ok := notificationAdminEndUserAssignmentBase.(rolemanagementpolicies.RoleManagementPolicyNotificationRule); ok {
if len(model.NotificationRules) == 1 {
if len(model.NotificationRules[0].EligibleActivations) == 1 {
if len(model.NotificationRules[0].EligibleActivations[0].AdminNotifications) == 1 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationAdminEndUserAssignment,
model.NotificationRules[0].EligibleActivations[0].AdminNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_activations.0.admin_notifications.0.additional_recipients"),
),
)
}
}
if len(model.NotificationRules) != 0 && len(model.NotificationRules[0].EligibleActivations) != 0 && len(model.NotificationRules[0].EligibleActivations[0].AdminNotifications) != 0 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationAdminEndUserAssignment,
model.NotificationRules[0].EligibleActivations[0].AdminNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_activations.0.admin_notifications.0.additional_recipients"),
),
)
} else {
updatedRules = append(updatedRules, expandNotificationSettings(
notificationAdminEndUserAssignment,
RoleManagementPolicyNotificationSettings{
NotificationLevel: "All",
DefaultRecipients: true,
AdditionalRecipients: []string{},
},
true,
))
}
}
}
Expand All @@ -298,18 +316,24 @@ func buildRoleManagementPolicyForUpdate(metadata *sdk.ResourceMetaData, rolePoli
if metadata.ResourceData.HasChange("notification_rules.0.eligible_assignments.0.approver_notifications") {
if notificationApproverAdminEligibilityBase, ok := existingRules["Notification_Approver_Admin_Eligibility"]; ok {
if notificationApproverAdminEligibility, ok := notificationApproverAdminEligibilityBase.(rolemanagementpolicies.RoleManagementPolicyNotificationRule); ok {
if len(model.NotificationRules) == 1 {
if len(model.NotificationRules[0].EligibleAssignments) == 1 {
if len(model.NotificationRules[0].EligibleAssignments[0].ApproverNotifications) == 1 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationApproverAdminEligibility,
model.NotificationRules[0].EligibleAssignments[0].ApproverNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_assignments.0.approver_notifications.0.additional_recipients"),
),
)
}
}
if len(model.NotificationRules) != 0 && len(model.NotificationRules[0].EligibleAssignments) != 0 && len(model.NotificationRules[0].EligibleAssignments[0].ApproverNotifications) != 0 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationApproverAdminEligibility,
model.NotificationRules[0].EligibleAssignments[0].ApproverNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_assignments.0.approver_notifications.0.additional_recipients"),
),
)
} else {
updatedRules = append(updatedRules, expandNotificationSettings(
notificationApproverAdminEligibility,
RoleManagementPolicyNotificationSettings{
NotificationLevel: "All",
DefaultRecipients: true,
AdditionalRecipients: []string{},
},
true,
))
}
}
}
Expand All @@ -318,18 +342,24 @@ func buildRoleManagementPolicyForUpdate(metadata *sdk.ResourceMetaData, rolePoli
if metadata.ResourceData.HasChange("notification_rules.0.active_assignments.0.approver_notifications") {
if notificationApproverAdminAssignmentBase, ok := existingRules["Notification_Approver_Admin_Assignment"]; ok {
if notificationApproverAdminAssignment, ok := notificationApproverAdminAssignmentBase.(rolemanagementpolicies.RoleManagementPolicyNotificationRule); ok {
if len(model.NotificationRules) == 1 {
if len(model.NotificationRules[0].ActiveAssignments) == 1 {
if len(model.NotificationRules[0].ActiveAssignments[0].ApproverNotifications) == 1 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationApproverAdminAssignment,
model.NotificationRules[0].ActiveAssignments[0].ApproverNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.active_assignments.0.approver_notifications.0.additional_recipients"),
),
)
}
}
if len(model.NotificationRules) != 0 && len(model.NotificationRules[0].ActiveAssignments) != 0 && len(model.NotificationRules[0].ActiveAssignments[0].ApproverNotifications) != 0 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationApproverAdminAssignment,
model.NotificationRules[0].ActiveAssignments[0].ApproverNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.active_assignments.0.approver_notifications.0.additional_recipients"),
),
)
} else {
updatedRules = append(updatedRules, expandNotificationSettings(
notificationApproverAdminAssignment,
RoleManagementPolicyNotificationSettings{
NotificationLevel: "All",
DefaultRecipients: true,
AdditionalRecipients: []string{},
},
true,
))
}
}
}
Expand All @@ -338,18 +368,24 @@ func buildRoleManagementPolicyForUpdate(metadata *sdk.ResourceMetaData, rolePoli
if metadata.ResourceData.HasChange("notification_rules.0.eligible_activations.0.approver_notifications") {
if notificationApproverEndUserAssignmentBase, ok := existingRules["Notification_Approver_EndUser_Assignment"]; ok {
if notificationApproverEndUserAssignment, ok := notificationApproverEndUserAssignmentBase.(rolemanagementpolicies.RoleManagementPolicyNotificationRule); ok {
if len(model.NotificationRules) == 1 {
if len(model.NotificationRules[0].EligibleActivations) == 1 {
if len(model.NotificationRules[0].EligibleActivations[0].ApproverNotifications) == 1 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationApproverEndUserAssignment,
model.NotificationRules[0].EligibleActivations[0].ApproverNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_activations.0.approver_notifications.0.additional_recipients"),
),
)
}
}
if len(model.NotificationRules) != 0 && len(model.NotificationRules[0].EligibleActivations) != 0 && len(model.NotificationRules[0].EligibleActivations[0].ApproverNotifications) != 0 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationApproverEndUserAssignment,
model.NotificationRules[0].EligibleActivations[0].ApproverNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_activations.0.approver_notifications.0.additional_recipients"),
),
)
} else {
updatedRules = append(updatedRules, expandNotificationSettings(
notificationApproverEndUserAssignment,
RoleManagementPolicyNotificationSettings{
NotificationLevel: "All",
DefaultRecipients: true,
AdditionalRecipients: []string{},
},
true,
))
}
}
}
Expand All @@ -358,18 +394,24 @@ func buildRoleManagementPolicyForUpdate(metadata *sdk.ResourceMetaData, rolePoli
if metadata.ResourceData.HasChange("notification_rules.0.eligible_assignments.0.assignee_notifications") {
if notificationRequestorAdminEligibilityBase, ok := existingRules["Notification_Requestor_Admin_Eligibility"]; ok {
if notificationRequestorAdminEligibility, ok := notificationRequestorAdminEligibilityBase.(rolemanagementpolicies.RoleManagementPolicyNotificationRule); ok {
if len(model.NotificationRules) == 1 {
if len(model.NotificationRules[0].EligibleAssignments) == 1 {
if len(model.NotificationRules[0].EligibleAssignments[0].AssigneeNotifications) == 1 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationRequestorAdminEligibility,
model.NotificationRules[0].EligibleAssignments[0].AssigneeNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_assignments.0.assignee_notifications.0.additional_recipients"),
),
)
}
}
if len(model.NotificationRules) != 0 && len(model.NotificationRules[0].EligibleAssignments) != 0 && len(model.NotificationRules[0].EligibleAssignments[0].AssigneeNotifications) != 0 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationRequestorAdminEligibility,
model.NotificationRules[0].EligibleAssignments[0].AssigneeNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_assignments.0.assignee_notifications.0.additional_recipients"),
),
)
} else {
updatedRules = append(updatedRules, expandNotificationSettings(
notificationRequestorAdminEligibility,
RoleManagementPolicyNotificationSettings{
NotificationLevel: "All",
DefaultRecipients: true,
AdditionalRecipients: []string{},
},
true,
))
}
}
}
Expand All @@ -378,18 +420,24 @@ func buildRoleManagementPolicyForUpdate(metadata *sdk.ResourceMetaData, rolePoli
if metadata.ResourceData.HasChange("notification_rules.0.active_assignments.0.assignee_notifications") {
if notificationRequestorAdminAssignmentBase, ok := existingRules["Notification_Requestor_Admin_Assignment"]; ok {
if notificationRequestorAdminAssignment, ok := notificationRequestorAdminAssignmentBase.(rolemanagementpolicies.RoleManagementPolicyNotificationRule); ok {
if len(model.NotificationRules) == 1 {
if len(model.NotificationRules[0].ActiveAssignments) == 1 {
if len(model.NotificationRules[0].ActiveAssignments[0].AssigneeNotifications) == 1 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationRequestorAdminAssignment,
model.NotificationRules[0].ActiveAssignments[0].AssigneeNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.active_assignments.0.assignee_notifications.0.additional_recipients"),
),
)
}
}
if len(model.NotificationRules) != 0 && len(model.NotificationRules[0].ActiveAssignments) != 0 && len(model.NotificationRules[0].ActiveAssignments[0].AssigneeNotifications) != 0 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationRequestorAdminAssignment,
model.NotificationRules[0].ActiveAssignments[0].AssigneeNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.active_assignments.0.assignee_notifications.0.additional_recipients"),
),
)
} else {
updatedRules = append(updatedRules, expandNotificationSettings(
notificationRequestorAdminAssignment,
RoleManagementPolicyNotificationSettings{
NotificationLevel: "All",
DefaultRecipients: true,
AdditionalRecipients: []string{},
},
true,
))
}
}
}
Expand All @@ -398,18 +446,24 @@ func buildRoleManagementPolicyForUpdate(metadata *sdk.ResourceMetaData, rolePoli
if metadata.ResourceData.HasChange("notification_rules.0.eligible_activations.0.assignee_notifications") {
if notificationRequestorEndUserAssignmentBase, ok := existingRules["Notification_Requestor_EndUser_Assignment"]; ok {
if notificationRequestorEndUserAssignment, ok := notificationRequestorEndUserAssignmentBase.(rolemanagementpolicies.RoleManagementPolicyNotificationRule); ok {
if len(model.NotificationRules) == 1 {
if len(model.NotificationRules[0].EligibleActivations) == 1 {
if len(model.NotificationRules[0].EligibleActivations[0].AssigneeNotifications) == 1 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationRequestorEndUserAssignment,
model.NotificationRules[0].EligibleActivations[0].AssigneeNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_activations.0.assignee_notifications.0.additional_recipients"),
),
)
}
}
if len(model.NotificationRules) != 0 && len(model.NotificationRules[0].EligibleActivations) != 0 && len(model.NotificationRules[0].EligibleActivations[0].AssigneeNotifications) != 0 {
updatedRules = append(updatedRules,
expandNotificationSettings(
notificationRequestorEndUserAssignment,
model.NotificationRules[0].EligibleActivations[0].AssigneeNotifications[0],
metadata.ResourceData.HasChange("notification_rules.0.eligible_activations.0.assignee_notifications.0.additional_recipients"),
),
)
} else {
updatedRules = append(updatedRules, expandNotificationSettings(
notificationRequestorEndUserAssignment,
RoleManagementPolicyNotificationSettings{
NotificationLevel: "All",
DefaultRecipients: true,
AdditionalRecipients: []string{},
},
true,
))
}
}
}
Expand Down
Loading
Loading