-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
arm_role_assignment
: add principal_type
and skip_service_principal_aad_check
properties
#4168
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
855ee7e
Expose Principal Type attribute
WodansSon 84029ed
Update azurerm/resource_arm_role_assignment_test.go
WodansSon 19e6594
Update azurerm/resource_arm_role_assignment_test.go
WodansSon c988716
Updates per PR comments
WodansSon b10b749
Merge branch 'e_principal-type' of https://github.com/terraform-provi…
WodansSon 18bdc0f
Missed a comma
WodansSon 808509e
Revert name change
WodansSon 9daeb7a
Update per PR review
WodansSon 13173f9
Change of direction
WodansSon fc6eecb
Removing unused resource
WodansSon 7b3452d
added set to read CRUD
WodansSon 934b93c
Update read
WodansSon 1d42907
gofmt
WodansSon 1e3a823
Changes per PR comments
WodansSon 865796d
Added principal_type as a computed attribute
WodansSon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,8 +24,9 @@ func TestAccAzureRMRoleAssignment(t *testing.T) { | |||||
"requiresImport": testAccAzureRMRoleAssignment_requiresImport, | ||||||
}, | ||||||
"assignment": { | ||||||
"sp": testAccAzureRMActiveDirectoryServicePrincipal_servicePrincipal, | ||||||
"group": testAccAzureRMActiveDirectoryServicePrincipal_group, | ||||||
"sp": testAccAzureRMActiveDirectoryServicePrincipal_servicePrincipal, | ||||||
"spType": testAccAzureRMActiveDirectoryServicePrincipal_servicePrincipalWithType, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this might be better as:
Suggested change
|
||||||
"group": testAccAzureRMActiveDirectoryServicePrincipal_group, | ||||||
}, | ||||||
"management": { | ||||||
"assign": testAccAzureRMRoleAssignment_managementGroup, | ||||||
|
@@ -219,6 +220,25 @@ func testAccAzureRMActiveDirectoryServicePrincipal_servicePrincipal(t *testing.T | |||||
}) | ||||||
} | ||||||
|
||||||
func testAccAzureRMActiveDirectoryServicePrincipal_servicePrincipalWithType(t *testing.T) { | ||||||
ri := tf.AccRandTimeInt() | ||||||
id := uuid.New().String() | ||||||
|
||||||
resource.ParallelTest(t, resource.TestCase{ | ||||||
PreCheck: func() { testAccPreCheck(t) }, | ||||||
Providers: testAccProviders, | ||||||
CheckDestroy: testCheckAzureRMRoleAssignmentDestroy, | ||||||
Steps: []resource.TestStep{ | ||||||
{ | ||||||
Config: testAccAzureRMRoleAssignment_servicePrincipalWithType(ri, id), | ||||||
Check: resource.ComposeTestCheckFunc( | ||||||
testCheckAzureRMRoleAssignmentExists("azurerm_role_assignment.test"), | ||||||
), | ||||||
}, | ||||||
}, | ||||||
}) | ||||||
} | ||||||
|
||||||
func testAccAzureRMActiveDirectoryServicePrincipal_group(t *testing.T) { | ||||||
ri := tf.AccRandTimeInt() | ||||||
id := uuid.New().String() | ||||||
|
@@ -440,6 +460,28 @@ resource "azurerm_role_assignment" "test" { | |||||
`, rInt, roleAssignmentID) | ||||||
} | ||||||
|
||||||
func testAccAzureRMRoleAssignment_servicePrincipalWithType(rInt int, roleAssignmentID string) string { | ||||||
return fmt.Sprintf(` | ||||||
data "azurerm_subscription" "current" {} | ||||||
|
||||||
resource "azuread_application" "test" { | ||||||
name = "acctestspa-%d" | ||||||
} | ||||||
|
||||||
resource "azuread_service_principal" "test" { | ||||||
application_id = "${azuread_application.test.application_id}" | ||||||
} | ||||||
|
||||||
resource "azurerm_role_assignment" "test" { | ||||||
name = "%s" | ||||||
scope = "${data.azurerm_subscription.current.id}" | ||||||
role_definition_name = "Reader" | ||||||
principal_id = "${azuread_service_principal.test.id}" | ||||||
skip_service_principal_aad_check = true | ||||||
} | ||||||
`, rInt, roleAssignmentID) | ||||||
} | ||||||
|
||||||
func testAccAzureRMRoleAssignment_group(rInt int, roleAssignmentID string) string { | ||||||
return fmt.Sprintf(` | ||||||
data "azurerm_subscription" "current" {} | ||||||
|
@@ -464,17 +506,17 @@ data "azurerm_subscription" "primary" {} | |||||
data "azurerm_client_config" "test" {} | ||||||
|
||||||
data "azurerm_role_definition" "test" { | ||||||
name = "Monitoring Reader" | ||||||
name = "Monitoring Reader" | ||||||
} | ||||||
|
||||||
resource "azurerm_management_group" "test" { | ||||||
group_id = "%s" | ||||||
group_id = "%s" | ||||||
} | ||||||
|
||||||
resource "azurerm_role_assignment" "test" { | ||||||
scope = "${azurerm_management_group.test.id}" | ||||||
role_definition_id = "${data.azurerm_role_definition.test.id}" | ||||||
principal_id = "${data.azurerm_client_config.test.service_principal_object_id}" | ||||||
scope = "${azurerm_management_group.test.id}" | ||||||
role_definition_id = "${data.azurerm_role_definition.test.id}" | ||||||
principal_id = "${data.azurerm_client_config.test.service_principal_object_id}" | ||||||
} | ||||||
`, groupId) | ||||||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking about this, I'm fine with this approach, but is there any way that we could look this information up so that users don't need to specify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this is all a hack around broken AAD replication, and that there might be other reasons to set the type property (or at the least consume it) i'm more inclined to just expose the SDK/API type field and users can set it as desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the service team:
The only valid values that are publicly exposed by our APIs are: User, Group, and ServicePrincipal.
This property is more relevant on the read path than write. For writes, the only relevant scenario is for ServicePrincipal. I see no value add in specifying
PrincipalType
as User or Group. The service anyways checks against AAD and fails the call if the principal is not found or the principal type in AAD doesn’t match what the request specified. Only forServicePrincipal
, if AAD returns principal not found, then role assignment create still proceeds in the new api-version.Don’t set this parameter unless explicitly dealing with newly created service principal.
As stated above this attribute makes more sense in the read scenario, the API will return User, Group, ServicePrincipal based on the type of the principal in AAD.