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

r/role_assignment: adding validation for scope #10438

Merged
merged 3 commits into from
Feb 3, 2021
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
3 changes: 3 additions & 0 deletions .teamcity/components/settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var serviceTestConfigurationOverrides = mapOf(
// Spring Cloud only allows a max of 10 provisioned
"appplatform" to testConfiguration(5, defaultStartHour),

// these tests all conflict with one another
"authorization" to testConfiguration(1, defaultStartHour),

// The AKS API has a low rate limit
"containers" to testConfiguration(5, defaultStartHour),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
managementGroupValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managementgroup/validate"
resourceValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource/validate"
subscriptionValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/subscription/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down Expand Up @@ -48,6 +52,12 @@ func resourceArmRoleAssignment() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.Any(
managementGroupValidate.ManagementGroupID,
subscriptionValidate.SubscriptionID,
resourceValidate.ResourceGroupID,
azure.ValidateResourceID,
),
},

"role_definition_id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,7 @@ import (

type RoleAssignmentResource struct{}

func TestAccRoleAssignment(t *testing.T) {
// NOTE: this is a combined test rather than separate split out tests due to
// Azure only being happy about provisioning a couple at a time
acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){
"basic": {
"roleName": testAccRoleAssignment_roleName,
"custom": testAccRoleAssignment_custom,
},
"basic_empty_name": {
"emptyName": testAccRoleAssignment_emptyName,
},
"built_in": {
"builtin": testAccRoleAssignment_builtin,
},
"data_actions": {
"dataActions": testAccRoleAssignment_dataActions,
},
"requires_import": {
"requiresImport": testAccRoleAssignment_requiresImport,
},
"assignment": {
"sp": testAccActiveDirectoryServicePrincipal_servicePrincipal,
"spType": testAccActiveDirectoryServicePrincipal_servicePrincipalWithType,
"group": testAccActiveDirectoryServicePrincipal_group,
},
"management": {
"assign": testAccRoleAssignment_managementGroup,
},
})
}

func testAccRoleAssignment_emptyName(t *testing.T) {
func TestAccRoleAssignment_emptyName(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
r := RoleAssignmentResource{}

Expand All @@ -64,7 +33,7 @@ func testAccRoleAssignment_emptyName(t *testing.T) {
})
}

func testAccRoleAssignment_roleName(t *testing.T) {
func TestAccRoleAssignment_roleName(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
id := uuid.New().String()

Expand All @@ -83,7 +52,7 @@ func testAccRoleAssignment_roleName(t *testing.T) {
})
}

func testAccRoleAssignment_requiresImport(t *testing.T) {
func TestAccRoleAssignment_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
id := uuid.New().String()

Expand All @@ -105,7 +74,7 @@ func testAccRoleAssignment_requiresImport(t *testing.T) {
})
}

func testAccRoleAssignment_dataActions(t *testing.T) {
func TestAccRoleAssignment_dataActions(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
id := uuid.New().String()

Expand All @@ -123,7 +92,7 @@ func testAccRoleAssignment_dataActions(t *testing.T) {
})
}

func testAccRoleAssignment_builtin(t *testing.T) {
func TestAccRoleAssignment_builtin(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
id := uuid.New().String()

Expand All @@ -140,7 +109,7 @@ func testAccRoleAssignment_builtin(t *testing.T) {
})
}

func testAccRoleAssignment_custom(t *testing.T) {
func TestAccRoleAssignment_custom(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
roleDefinitionId := uuid.New().String()
roleAssignmentId := uuid.New().String()
Expand All @@ -159,7 +128,7 @@ func testAccRoleAssignment_custom(t *testing.T) {
})
}

func testAccActiveDirectoryServicePrincipal_servicePrincipal(t *testing.T) {
func TestAccRoleAssignment_ServicePrincipal(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
ri := acceptance.RandTimeInt()
id := uuid.New().String()
Expand All @@ -177,7 +146,7 @@ func testAccActiveDirectoryServicePrincipal_servicePrincipal(t *testing.T) {
})
}

func testAccActiveDirectoryServicePrincipal_servicePrincipalWithType(t *testing.T) {
func TestAccRoleAssignment_ServicePrincipalWithType(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
ri := acceptance.RandTimeInt()
id := uuid.New().String()
Expand All @@ -194,7 +163,7 @@ func testAccActiveDirectoryServicePrincipal_servicePrincipalWithType(t *testing.
})
}

func testAccActiveDirectoryServicePrincipal_group(t *testing.T) {
func TestAccRoleAssignment_ServicePrincipalGroup(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
ri := acceptance.RandTimeInt()
id := uuid.New().String()
Expand All @@ -212,7 +181,7 @@ func testAccActiveDirectoryServicePrincipal_group(t *testing.T) {
}

// TODO - "real" management group with appropriate required for testing
func testAccRoleAssignment_managementGroup(t *testing.T) {
func TestAccRoleAssignment_managementGroup(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test")
groupId := uuid.New().String()

Expand Down