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

Bugfix: work around an API bug where acceptMappedClaims cannot be set on create when holding Application.ReadWrite.OwnedBy role #1008

Merged
merged 1 commit into from
Feb 16, 2023
Merged
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
26 changes: 25 additions & 1 deletion internal/services/applications/application_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,9 +954,19 @@ func applicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta
}
tempDisplayName := fmt.Sprintf("TERRAFORM_UPDATE_%s", uuid)

api := expandApplicationApi(d.Get("api").([]interface{}))

// API bug: cannot set `acceptMappedClaims` when holding the Application.ReadWrite.OwnedBy role
// See /~https://github.com/hashicorp/terraform-provider-azuread/issues/914
var acceptMappedClaims *bool
if api.AcceptMappedClaims != nil && *api.AcceptMappedClaims {
acceptMappedClaims = api.AcceptMappedClaims
api.AcceptMappedClaims = nil
}

// Create a new application
properties := msgraph.Application{
Api: expandApplicationApi(d.Get("api").([]interface{})),
Api: api,
AppRoles: expandApplicationAppRoles(d.Get("app_role").(*schema.Set).List()),
Description: utils.NullableString(d.Get("description").(string)),
DisplayName: utils.String(tempDisplayName),
Expand Down Expand Up @@ -1056,6 +1066,20 @@ func applicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta
return tf.ErrorDiagF(err, "Failed to patch application after creating")
}

// API bug: cannot set `acceptMappedClaims` when holding the Application.ReadWrite.OwnedBy role
// See /~https://github.com/hashicorp/terraform-provider-azuread/issues/914
if acceptMappedClaims != nil {
api.AcceptMappedClaims = acceptMappedClaims
if _, err := client.Update(ctx, msgraph.Application{
DirectoryObject: msgraph.DirectoryObject{
Id: app.Id,
},
Api: api,
}); err != nil {
return tf.ErrorDiagPathF(err, "api.0.mapped_claims_enabled", "Failed to patch application after creating to set `api.0.mapped_claims_enabled` property")
}
}

if len(ownersExtra) > 0 {
// Add any remaining owners after the application is created
app.Owners = &ownersExtra
Expand Down