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

azuread_application - allow custom approle #171

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 3 additions & 2 deletions azuread/helpers/graph/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func FlattenAppRoles(in *[]graphrbac.AppRole) []interface{} {
appRoles := make([]interface{}, 0)
for _, role := range *in {
appRole := make(map[string]interface{})

if role.ID != nil {
appRole["id"] = *role.ID
}
Expand All @@ -126,8 +127,8 @@ func FlattenAppRoles(in *[]graphrbac.AppRole) []interface{} {
if role.IsEnabled != nil {
appRole["is_enabled"] = *role.IsEnabled
}
if role.Value != nil {
appRole["value"] = *role.Value
if v := role.Value; v != nil && *v != "" {
appRole["value"] = *v
}
appRoles = append(appRoles, appRole)
}
Expand Down
57 changes: 57 additions & 0 deletions azuread/resource_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,31 @@ func TestAccAzureADApplication_appRolesNoValue(t *testing.T) {
})
}

func TestAccAzureADApplication_appRolesCustomID(t *testing.T) {
rn := "azuread_application.test"
ri := tf.AccRandTimeInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckADApplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccADApplication_appRolesCustomID(ri),
Check: resource.ComposeTestCheckFunc(
testCheckADApplicationExists(rn),
resource.TestCheckResourceAttr(rn, "app_role.#", "1"),
),
},
{
ResourceName: rn,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureADApplication_appRolesUpdate(t *testing.T) {
rn := "azuread_application.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -683,9 +708,41 @@ resource "azuread_application" "test" {

func testAccADApplication_appRolesUpdate(ri int) string {
return fmt.Sprintf(`

resource "azuread_group" "test" {
name = "acctestGroup-%[1]d"
}

resource "azuread_application" "test" {
name = "acctestApp-%d"

required_resource_access {
resource_app_id = "00000003-0000-0000-c000-000000000000"

resource_access {
id = "${azuread_group.test.id}"
type = "Role"
}
}

app_role {
id = "${azuread_group.test.id}"
allowed_member_types = [ "User" ]
description = "Role mapped from AD group AWS-1234567890-role"
display_name = "kt's acceptance test'"
is_enabled = true

value = "arn:aws:iam::1234567890:role/role,arn:aws:iam::1234567890:saml-provider/Azure-AD"
}
}
`, ri)
}

func testAccADApplication_appRolesUpdate(ri int) string {
return fmt.Sprintf(`
resource "azuread_application" "test" {
name = "acctest-APP-%[1]d"

app_role {
allowed_member_types = ["User"]
description = "Admins can manage roles and perform all task actions"
Expand Down