Skip to content

Commit

Permalink
Moved role def sp assingment test
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte committed Nov 7, 2018
1 parent 0b36ba7 commit 63fc501
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
47 changes: 0 additions & 47 deletions azurerm/resource_arm_azuread_service_principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/google/uuid"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down Expand Up @@ -33,31 +32,6 @@ func TestAccAzureRMActiveDirectoryServicePrincipal_basic(t *testing.T) {
})
}

func TestAccAzureRMActiveDirectoryServicePrincipal_roleAssignment(t *testing.T) {
resourceName := "azurerm_azuread_service_principal.test"

ri := acctest.RandInt()
id := uuid.New().String()
config := testAccAzureRMActiveDirectoryServicePrincipal_roleAssignment(ri, id)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMActiveDirectoryServicePrincipalDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMActiveDirectoryServicePrincipalExists(resourceName),
testCheckAzureRMRoleAssignmentExists("azurerm_role_assignment.test"),
resource.TestCheckResourceAttrSet(resourceName, "display_name"),
resource.TestCheckResourceAttrSet(resourceName, "application_id"),
),
},
},
})
}

func testCheckAzureRMActiveDirectoryServicePrincipalExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down Expand Up @@ -115,24 +89,3 @@ resource "azurerm_azuread_service_principal" "test" {
}
`, id)
}

func testAccAzureRMActiveDirectoryServicePrincipal_roleAssignment(rInt int, roleAssignmentID string) string {
return fmt.Sprintf(`
data "azurerm_subscription" "current" {}
resource "azurerm_azuread_application" "test" {
name = "acctestspa-%d"
}
resource "azurerm_azuread_service_principal" "test" {
application_id = "${azurerm_azuread_application.test.application_id}"
}
resource "azurerm_role_assignment" "test" {
name = "%s"
scope = "${data.azurerm_subscription.current.id}"
role_definition_name = "Reader"
principal_id = "${azurerm_azuread_service_principal.test.id}"
}
`, rInt, roleAssignmentID)
}
49 changes: 49 additions & 0 deletions azurerm/resource_arm_role_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func TestAccAzureRMRoleAssignment(t *testing.T) {
"builtin": testAccAzureRMRoleAssignment_builtin,
"custom": testAccAzureRMRoleAssignment_custom,
},
"assingment": {
"sp": testAccAzureRMActiveDirectoryServicePrincipal_roleAssignment,
},
"import": {
"basic": testAccAzureRMRoleAssignment_importBasic,
"custom": testAccAzureRMRoleAssignment_importCustom,
Expand Down Expand Up @@ -195,6 +198,31 @@ func testCheckAzureRMRoleAssignmentDestroy(s *terraform.State) error {
return nil
}

func testAccAzureRMActiveDirectoryServicePrincipal_roleAssignment(t *testing.T) {
resourceName := "azurerm_azuread_service_principal.test"

ri := acctest.RandInt()
id := uuid.New().String()
config := testAccAzureRMActiveDirectoryServicePrincipal_roleAssignment(ri, id)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMActiveDirectoryServicePrincipalDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMActiveDirectoryServicePrincipalExists(resourceName),
testCheckAzureRMRoleAssignmentExists("azurerm_role_assignment.test"),
resource.TestCheckResourceAttrSet(resourceName, "display_name"),
resource.TestCheckResourceAttrSet(resourceName, "application_id"),
),
},
},
})
}

func testAccAzureRMRoleAssignment_emptyNameConfig() string {
return `
data "azurerm_subscription" "primary" {}
Expand Down Expand Up @@ -292,3 +320,24 @@ resource "azurerm_role_assignment" "test" {
}
`, roleDefinitionId, rInt, roleAssignmentId)
}

func testAccAzureRMActiveDirectoryServicePrincipal_roleAssignment(rInt int, roleAssignmentID string) string {
return fmt.Sprintf(`
data "azurerm_subscription" "current" {}
resource "azurerm_azuread_application" "test" {
name = "acctestspa-%d"
}
resource "azurerm_azuread_service_principal" "test" {
application_id = "${azurerm_azuread_application.test.application_id}"
}
resource "azurerm_role_assignment" "test" {
name = "%s"
scope = "${data.azurerm_subscription.current.id}"
role_definition_name = "Reader"
principal_id = "${azurerm_azuread_service_principal.test.id}"
}
`, rInt, roleAssignmentID)
}

0 comments on commit 63fc501

Please sign in to comment.