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: support optional_claims #260

Merged
merged 4 commits into from
Jun 2, 2020
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
18 changes: 18 additions & 0 deletions azuread/data_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ func dataApplication() *schema.Resource {

"app_roles": graph.SchemaAppRolesComputed(),

"optional_claims": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_token": graph.SchemaOptionalClaims(),
"id_token": graph.SchemaOptionalClaims(),
// TODO: enable when https://github.com/Azure/azure-sdk-for-go/issues/9714 resolved
//"saml_token": graph.SchemaOptionalClaims(),
},
},
},

"required_resource_access": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -203,6 +217,10 @@ func dataApplicationRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error setting `required_resource_access`: %+v", err)
}

if err := d.Set("optional_claims", flattenADApplicationOptionalClaims(app.OptionalClaims)); err != nil {
return fmt.Errorf("setting `optional_claims`: %+v", err)
}

if v := app.PublicClient; v != nil && *v {
d.Set("type", "native")
} else {
Expand Down
5 changes: 5 additions & 0 deletions azuread/data_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccAzureADApplicationDataSource_byObjectId(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "homepage", fmt.Sprintf("https://acctest-APP-%d", ri)),
resource.TestCheckResourceAttr(dataSourceName, "identifier_uris.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "reply_urls.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "optional_claims.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "required_resource_access.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "type", "webapp/api"),
resource.TestCheckResourceAttr(dataSourceName, "app_roles.#", "0"),
Expand Down Expand Up @@ -65,6 +66,9 @@ func TestAccAzureADApplicationDataSource_byObjectIdComplete(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "identifier_uris.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "reply_urls.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "oauth2_allow_implicit_flow", "true"),
resource.TestCheckResourceAttr(dataSourceName, "optional_claims.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "optional_claims.0.access_token.#", "2"),
resource.TestCheckResourceAttr(dataSourceName, "optional_claims.0.id_token.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "required_resource_access.#", "2"),
resource.TestCheckResourceAttr(dataSourceName, "group_membership_claims", "All"),
resource.TestCheckResourceAttrSet(dataSourceName, "application_id"),
Expand Down Expand Up @@ -94,6 +98,7 @@ func TestAccAzureADApplicationDataSource_byName(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "homepage", fmt.Sprintf("https://acctest-APP-%d", ri)),
resource.TestCheckResourceAttr(dataSourceName, "identifier_uris.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "reply_urls.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "optional_claims.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "required_resource_access.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "oauth2_allow_implicit_flow", "false"),
resource.TestCheckResourceAttrSet(dataSourceName, "application_id"),
Expand Down
46 changes: 46 additions & 0 deletions azuread/helpers/graph/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

func SchemaAppRolesComputed() *schema.Schema {
Expand Down Expand Up @@ -103,6 +104,51 @@ func SchemaOauth2PermissionsComputed() *schema.Schema {
}
}

func SchemaOptionalClaims() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},

"source": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(
[]string{"user"},
false,
),
},
"essential": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"additional_properties": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(
[]string{
"dns_domain_and_sam_account_name",
"emit_as_roles",
"netbios_domain_and_sam_account_name",
"sam_account_name",
},
false,
),
},
},
},
},
}
}

func FlattenAppRoles(in *[]graphrbac.AppRole) []interface{} {
if in == nil {
return []interface{}{}
Expand Down
Loading