-
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.
azurerm_role_management_policy
- Support for resource scope (#27205)
* Update role_management_policy_resource.go * Update role_management_policy_data_source.go * Update role_management_policy_data_source.go * Update role_management_policy_resource.go * Update role_management_policy_data_source.go * unified validation with other role assignments * updated docs with correct input scopes * updated docs with correct input scopes --------- Co-authored-by: Grand Lord Kevin <[email protected]>
- Loading branch information
1 parent
f697f04
commit 590483c
Showing
6 changed files
with
204 additions
and
4 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
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 |
---|---|---|
|
@@ -125,6 +125,36 @@ func TestAccRoleManagementPolicy_subscription(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccRoleManagementPolicy_resource(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_role_management_policy", "test") | ||
r := RoleManagementPolicyResource{} | ||
|
||
// Ignore the dangling resource post-test as the policy remains while the resource exists, or is in a pending deletion state | ||
data.ResourceTestSkipCheckDestroyed(t, []acceptance.TestStep{ | ||
{ | ||
Config: r.resource(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
check.That(data.ResourceName).Key("active_assignment_rules.0.expire_after").HasValue("P30D"), | ||
check.That(data.ResourceName).Key("eligible_assignment_rules.0.expiration_required").HasValue("false"), | ||
check.That(data.ResourceName).Key("notification_rules.0.eligible_assignments.0.approver_notifications.0.notification_level").HasValue("All"), | ||
), | ||
}, | ||
data.ImportStep(), | ||
{ | ||
Config: r.resourceUpdate(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
check.That(data.ResourceName).Key("active_assignment_rules.0.expire_after").HasValue("P15D"), | ||
check.That(data.ResourceName).Key("eligible_assignment_rules.0.expiration_required").HasValue("true"), | ||
check.That(data.ResourceName).Key("activation_rules.0.approval_stage.0.primary_approver.0.type").HasValue("Group"), | ||
check.That(data.ResourceName).Key("notification_rules.0.eligible_assignments.0.approver_notifications.0.notification_level").HasValue("Critical"), | ||
), | ||
}, | ||
data.ImportStep(), | ||
}) | ||
} | ||
|
||
func (RoleManagementPolicyResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) { | ||
client := clients.Authorization.RoleManagementPoliciesClient | ||
|
||
|
@@ -451,3 +481,111 @@ resource "azurerm_role_management_policy" "test" { | |
} | ||
`, r.resourceGroupTemplate(data), data.RandomString, requireApproval) | ||
} | ||
|
||
func (RoleManagementPolicyResource) resourceTemplate(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
provider "azurerm" {} | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%[1]s" | ||
location = "%[2]s" | ||
} | ||
resource "azurerm_storage_account" "test" { | ||
name = "accteststg%[1]s" | ||
resource_group_name = azurerm_resource_group.test.name | ||
location = azurerm_resource_group.test.location | ||
account_tier = "Standard" | ||
account_replication_type = "LRS" | ||
} | ||
data "azurerm_role_definition" "contributor" { | ||
name = "Contributor" | ||
scope = azurerm_storage_account.test.id | ||
} | ||
`, data.RandomString, data.Locations.Primary) | ||
} | ||
|
||
func (r RoleManagementPolicyResource) resource(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "azurerm_role_management_policy" "test" { | ||
scope = azurerm_storage_account.test.id | ||
role_definition_id = data.azurerm_role_definition.contributor.id | ||
active_assignment_rules { | ||
expire_after = "P30D" | ||
} | ||
eligible_assignment_rules { | ||
expiration_required = false | ||
} | ||
notification_rules { | ||
eligible_assignments { | ||
approver_notifications { | ||
notification_level = "All" | ||
default_recipients = false | ||
additional_recipients = ["[email protected]"] | ||
} | ||
} | ||
} | ||
} | ||
`, r.resourceTemplate(data), data.RandomString) | ||
} | ||
|
||
func (r RoleManagementPolicyResource) resourceUpdate(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
provider "azuread" {} | ||
resource "azuread_group" "approver" { | ||
display_name = "PIM Approver Test %[2]s" | ||
mail_enabled = false | ||
security_enabled = true | ||
} | ||
resource "azurerm_role_management_policy" "test" { | ||
scope = azurerm_storage_account.test.id | ||
role_definition_id = data.azurerm_role_definition.contributor.id | ||
active_assignment_rules { | ||
expire_after = "P15D" | ||
} | ||
eligible_assignment_rules { | ||
expiration_required = true | ||
} | ||
activation_rules { | ||
maximum_duration = "PT1H" | ||
require_approval = true | ||
approval_stage { | ||
primary_approver { | ||
object_id = azuread_group.approver.object_id | ||
type = "Group" | ||
} | ||
} | ||
} | ||
notification_rules { | ||
eligible_assignments { | ||
approver_notifications { | ||
notification_level = "Critical" | ||
default_recipients = false | ||
additional_recipients = ["[email protected]"] | ||
} | ||
} | ||
eligible_activations { | ||
assignee_notifications { | ||
notification_level = "All" | ||
default_recipients = true | ||
additional_recipients = ["[email protected]"] | ||
} | ||
} | ||
} | ||
} | ||
`, r.resourceTemplate(data), data.RandomString) | ||
} |
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