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_assignment] Add support for Management Groups #4063

Merged
merged 10 commits into from
Aug 13, 2019
2 changes: 1 addition & 1 deletion azurerm/data_source_builtin_role_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package azurerm
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_role_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package azurerm
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"

"github.com/hashicorp/terraform/helper/schema"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/authorization/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package authorization

import (
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_role_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"

"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand Down
51 changes: 47 additions & 4 deletions azurerm/resource_arm_role_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func TestAccAzureRMRoleAssignment(t *testing.T) {
"sp": testAccAzureRMActiveDirectoryServicePrincipal_servicePrincipal,
"group": testAccAzureRMActiveDirectoryServicePrincipal_group,
},
"management": {
"assign": testAccAzureRMRoleAssignment_managementGroup,
},
}

for group, m := range testCases {
Expand Down Expand Up @@ -207,7 +210,7 @@ func testAccAzureRMActiveDirectoryServicePrincipal_servicePrincipal(t *testing.T
CheckDestroy: testCheckAzureRMRoleAssignmentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMRoleAssingment_servicePrincipal(ri, id),
Config: testAccAzureRMRoleAssignment_servicePrincipal(ri, id),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRoleAssignmentExists("azurerm_role_assignment.test"),
),
Expand All @@ -226,7 +229,7 @@ func testAccAzureRMActiveDirectoryServicePrincipal_group(t *testing.T) {
CheckDestroy: testCheckAzureRMRoleAssignmentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMRoleAssingment_group(ri, id),
Config: testAccAzureRMRoleAssignment_group(ri, id),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRoleAssignmentExists("azurerm_role_assignment.test"),
),
Expand Down Expand Up @@ -287,6 +290,24 @@ func testCheckAzureRMRoleAssignmentDestroy(s *terraform.State) error {
return nil
}

func testAccAzureRMRoleAssignment_managementGroup(t *testing.T) {
groupId := uuid.New().String()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMRoleAssignmentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMRoleAssignment_managementGroupConfig(groupId),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRoleAssignmentExists("azurerm_role_assignment.test"),
),
},
},
})
}

func testAccAzureRMRoleAssignment_emptyNameConfig() string {
return `
data "azurerm_subscription" "primary" {}
Expand Down Expand Up @@ -398,7 +419,7 @@ resource "azurerm_role_assignment" "test" {
`, roleDefinitionId, rInt, roleAssignmentId)
}

func testAccAzureRMRoleAssingment_servicePrincipal(rInt int, roleAssignmentID string) string {
func testAccAzureRMRoleAssignment_servicePrincipal(rInt int, roleAssignmentID string) string {
return fmt.Sprintf(`
data "azurerm_subscription" "current" {}

Expand All @@ -419,7 +440,7 @@ resource "azurerm_role_assignment" "test" {
`, rInt, roleAssignmentID)
}

func testAccAzureRMRoleAssingment_group(rInt int, roleAssignmentID string) string {
func testAccAzureRMRoleAssignment_group(rInt int, roleAssignmentID string) string {
return fmt.Sprintf(`
data "azurerm_subscription" "current" {}

Expand All @@ -435,3 +456,25 @@ resource "azurerm_role_assignment" "test" {
}
`, rInt, roleAssignmentID)
}

func testAccAzureRMRoleAssignment_managementGroupConfig(groupId string) string {
return fmt.Sprintf(`
data "azurerm_subscription" "primary" {}

data "azurerm_client_config" "test" {}

data "azurerm_role_definition" "test" {
name = "Monitoring Reader"
}

resource "azurerm_management_group" "test" {
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}"
}
`, groupId)
}
2 changes: 1 addition & 1 deletion azurerm/resource_arm_role_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"

"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ github.com/Azure/azure-sdk-for-go v30.0.0+incompatible h1:6o1Yzl7wTBYg+xw0pY4qna
github.com/Azure/azure-sdk-for-go v30.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go v31.0.0+incompatible h1:18nT+M3yxnWcO66yoJyomlCoKMu578UHh0DjJBA5c1M=
github.com/Azure/azure-sdk-for-go v31.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go v32.3.0+incompatible h1:cPbYVpshHJc/lWNk0Gzhf8SLN+7qpdb8RQnRh0gntcI=
github.com/Azure/go-autorest v10.15.4+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/Azure/go-autorest v11.7.0+incompatible h1:gzma19dc9ejB75D90E5S+/wXouzpZyA+CV+/MJPSD/k=
github.com/Azure/go-autorest v11.7.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading