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

Authorization: upgrading to the 2018-01-01 Preview SDK #1284

Merged
merged 4 commits into from
May 24, 2018
Merged
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
2 changes: 1 addition & 1 deletion azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

appinsights "github.com/Azure/azure-sdk-for-go/services/appinsights/mgmt/2015-05-01/insights"
"github.com/Azure/azure-sdk-for-go/services/authorization/mgmt/2015-07-01/authorization"
"github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation"
"github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2017-04-02/cdn"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute"
Expand All @@ -33,6 +32,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement"
"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/recoveryservices"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
"github.com/Azure/azure-sdk-for-go/services/relay/mgmt/2017-04-01/relay"
Expand Down
4 changes: 2 additions & 2 deletions azurerm/data_source_builtin_role_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ func dataSourceArmBuiltInRoleDefinitionRead(d *schema.ResourceData, meta interfa
return fmt.Errorf("Error loading Role Definition: %+v", err)
}

if props := role.Properties; props != nil {
if props := role.RoleDefinitionProperties; props != nil {
d.Set("name", props.RoleName)
d.Set("description", props.Description)
d.Set("type", props.Type)
d.Set("type", props.RoleType)

permissions := flattenRoleDefinitionPermissions(props.Permissions)
if err := d.Set("permissions", permissions); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions azurerm/data_source_role_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ func dataSourceArmRoleDefinitionRead(d *schema.ResourceData, meta interface{}) e

d.SetId(*role.ID)

if props := role.Properties; props != nil {
if props := role.RoleDefinitionProperties; props != nil {
d.Set("name", props.RoleName)
d.Set("description", props.Description)
d.Set("type", props.Type)
d.Set("type", props.RoleType)

permissions := flattenRoleDefinitionPermissions(props.Permissions)
if err := d.Set("permissions", permissions); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions azurerm/resource_arm_role_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/authorization/mgmt/2015-07-01/authorization"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-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 Expand Up @@ -99,7 +99,7 @@ func resourceArmRoleAssignmentCreate(d *schema.ResourceData, meta interface{}) e
}

properties := authorization.RoleAssignmentCreateParameters{
Properties: &authorization.RoleAssignmentProperties{
RoleAssignmentProperties: &authorization.RoleAssignmentProperties{
RoleDefinitionID: utils.String(roleDefinitionId),
PrincipalID: utils.String(principalId),
},
Expand Down Expand Up @@ -139,7 +139,7 @@ func resourceArmRoleAssignmentRead(d *schema.ResourceData, meta interface{}) err

d.Set("name", resp.Name)

if props := resp.Properties; props != nil {
if props := resp.RoleAssignmentPropertiesWithScope; props != nil {
d.Set("scope", props.Scope)
d.Set("role_definition_id", props.RoleDefinitionID)
d.Set("principal_id", props.PrincipalID)
Expand Down
51 changes: 44 additions & 7 deletions azurerm/resource_arm_role_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ func TestAccAzureRMRoleAssignment(t *testing.T) {
// Azure only being happy about provisioning a couple at a time
testCases := map[string]map[string]func(t *testing.T){
"basic": {
"emptyName": testAccAzureRMRoleAssignment_emptyName,
"roleName": testAccAzureRMRoleAssignment_roleName,
"builtin": testAccAzureRMRoleAssignment_builtin,
"custom": testAccAzureRMRoleAssignment_custom,
"emptyName": testAccAzureRMRoleAssignment_emptyName,
"roleName": testAccAzureRMRoleAssignment_roleName,
"dataActions": testAccAzureRMRoleAssignment_dataActions,
"builtin": testAccAzureRMRoleAssignment_builtin,
"custom": testAccAzureRMRoleAssignment_custom,
},
"import": {
"basic": testAccAzureRMRoleAssignment_importBasic,
Expand Down Expand Up @@ -81,6 +82,27 @@ func testAccAzureRMRoleAssignment_roleName(t *testing.T) {
})
}

func testAccAzureRMRoleAssignment_dataActions(t *testing.T) {
id := uuid.New().String()
resourceName := "azurerm_role_assignment.test"
config := testAccAzureRMRoleAssignment_dataActionsConfig(id)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMRoleAssignmentDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRoleAssignmentExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "role_definition_id"),
),
},
},
})
}

func testAccAzureRMRoleAssignment_builtin(t *testing.T) {
id := uuid.New().String()
config := testAccAzureRMRoleAssignment_builtinConfig(id)
Expand Down Expand Up @@ -180,7 +202,7 @@ data "azurerm_subscription" "primary" {}
data "azurerm_client_config" "test" {}

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

resource "azurerm_role_assignment" "test" {
Expand All @@ -200,7 +222,22 @@ data "azurerm_client_config" "test" {}
resource "azurerm_role_assignment" "test" {
name = "%s"
scope = "${data.azurerm_subscription.primary.id}"
role_definition_name = "Reader"
role_definition_name = "Log Analytics Reader"
principal_id = "${data.azurerm_client_config.test.service_principal_object_id}"
}
`, id)
}

func testAccAzureRMRoleAssignment_dataActionsConfig(id string) string {
return fmt.Sprintf(`
data "azurerm_subscription" "primary" {}

data "azurerm_client_config" "test" {}

resource "azurerm_role_assignment" "test" {
name = "%s"
scope = "${data.azurerm_subscription.primary.id}"
role_definition_name = "Virtual Machine User Login"
principal_id = "${data.azurerm_client_config.test.service_principal_object_id}"
}
`, id)
Expand All @@ -213,7 +250,7 @@ data "azurerm_subscription" "primary" {}
data "azurerm_client_config" "test" {}

data "azurerm_builtin_role_definition" "test" {
name = "Reader"
name = "Site Recovery Reader"
}

resource "azurerm_role_assignment" "test" {
Expand Down
9 changes: 4 additions & 5 deletions azurerm/resource_arm_role_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package azurerm

import (
"fmt"

"log"

"github.com/Azure/azure-sdk-for-go/services/authorization/mgmt/2015-07-01/authorization"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -90,10 +89,10 @@ func resourceArmRoleDefinitionCreateUpdate(d *schema.ResourceData, meta interfac
assignableScopes := expandRoleDefinitionAssignableScopes(d)

properties := authorization.RoleDefinition{
Properties: &authorization.RoleDefinitionProperties{
RoleDefinitionProperties: &authorization.RoleDefinitionProperties{
RoleName: utils.String(name),
Description: utils.String(description),
Type: utils.String(roleType),
RoleType: utils.String(roleType),
Permissions: &permissions,
AssignableScopes: &assignableScopes,
},
Expand Down Expand Up @@ -131,7 +130,7 @@ func resourceArmRoleDefinitionRead(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error loading Role Definition %q: %+v", d.Id(), err)
}

if props := resp.Properties; props != nil {
if props := resp.RoleDefinitionProperties; props != nil {
d.Set("name", props.RoleName)
d.Set("description", props.Description)

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