Skip to content

Commit

Permalink
Don't include application_id in SP update (#1069)
Browse files Browse the repository at this point in the history
Improved SCIM error message propagation and now include `scimType` field.

Fixes #1065
Fixes #1051
  • Loading branch information
nfx authored Jan 28, 2022
1 parent 278dde1 commit 0633258
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 0.4.7
* Added optional `force` argument to `databricks_group` resource to ignore `cannot create group: Group with name X already exists.` errors and implicitly import the specific group into Terraform state, enforcing entitlements defined in the instance of resource ([#1066](https://github.com/databrickslabs/terraform-provider-databricks/pull/1066)).
* Fixed `databricks_service_principal` `display_name` update ([#1065](https://github.com/databrickslabs/terraform-provider-databricks/issues/1065)).
* Added documentation for Unity Catalog resources.

Updated dependency versions:

* Bump gopkg.in/ini.v1 from 1.66.2 to 1.66.3

## 0.4.6

Expand Down
4 changes: 4 additions & 0 deletions common/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type APIErrorBody struct {
// for RFC 7644 Section 3.7.3 https://tools.ietf.org/html/rfc7644#section-3.7.3
ScimDetail string `json:"detail,omitempty"`
ScimStatus string `json:"status,omitempty"`
ScimType string `json:"scimType,omitempty"`
API12Error string `json:"error,omitempty"`
}

Expand Down Expand Up @@ -208,6 +209,9 @@ func (c *DatabricksClient) parseError(resp *http.Response) APIError {
} else {
errorBody.Message = errorBody.ScimDetail
}
// add more context from SCIM responses
errorBody.Message = fmt.Sprintf("%s %s", errorBody.ScimType, errorBody.Message)
errorBody.Message = strings.Trim(errorBody.Message, " ")
errorBody.ErrorCode = fmt.Sprintf("SCIM_%s", errorBody.ScimStatus)
}
if resp.StatusCode == 403 {
Expand Down
19 changes: 8 additions & 11 deletions scim/resource_service_principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ func ResourceServicePrincipal() *schema.Resource {
m["active"].Default = true
return m
})
spFromData := func(d *schema.ResourceData) (user User, err error) {
spFromData := func(d *schema.ResourceData) User {
var u entity
common.DataToStructPointer(d, servicePrincipalSchema, &u)
return User{
ApplicationID: u.ApplicationID,
DisplayName: u.DisplayName,
Active: u.Active,
Entitlements: readEntitlementsFromData(d),
}, nil
}
}
return common.Resource{
Schema: servicePrincipalSchema,
Expand All @@ -95,10 +95,7 @@ func ResourceServicePrincipal() *schema.Resource {
return nil
},
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
sp, err := spFromData(d)
if err != nil {
return err
}
sp := spFromData(d)
if c.IsAws() && sp.ApplicationID != "" {
return fmt.Errorf("application_id is not allowed for service principals in Databricks on AWS")
}
Expand All @@ -121,11 +118,11 @@ func ResourceServicePrincipal() *schema.Resource {
return sp.Entitlements.readIntoData(d)
},
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
sp, err := spFromData(d)
if err != nil {
return err
}
return NewServicePrincipalsAPI(ctx, c).Update(d.Id(), sp)
return NewServicePrincipalsAPI(ctx, c).Update(d.Id(), User{
DisplayName: d.Get("display_name").(string),
Active: d.Get("active").(bool),
Entitlements: readEntitlementsFromData(d),
})
},
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
return NewServicePrincipalsAPI(ctx, c).Delete(d.Id())
Expand Down

0 comments on commit 0633258

Please sign in to comment.