Skip to content

Commit 0633258

Browse files
authored
Don't include application_id in SP update (#1069)
Improved SCIM error message propagation and now include `scimType` field. Fixes #1065 Fixes #1051
1 parent 278dde1 commit 0633258

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## 0.4.7
44
* 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)).
5+
* Fixed `databricks_service_principal` `display_name` update ([#1065](https://github.com/databrickslabs/terraform-provider-databricks/issues/1065)).
6+
* Added documentation for Unity Catalog resources.
7+
8+
Updated dependency versions:
9+
10+
* Bump gopkg.in/ini.v1 from 1.66.2 to 1.66.3
511

612
## 0.4.6
713

common/http.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type APIErrorBody struct {
4343
// for RFC 7644 Section 3.7.3 https://tools.ietf.org/html/rfc7644#section-3.7.3
4444
ScimDetail string `json:"detail,omitempty"`
4545
ScimStatus string `json:"status,omitempty"`
46+
ScimType string `json:"scimType,omitempty"`
4647
API12Error string `json:"error,omitempty"`
4748
}
4849

@@ -208,6 +209,9 @@ func (c *DatabricksClient) parseError(resp *http.Response) APIError {
208209
} else {
209210
errorBody.Message = errorBody.ScimDetail
210211
}
212+
// add more context from SCIM responses
213+
errorBody.Message = fmt.Sprintf("%s %s", errorBody.ScimType, errorBody.Message)
214+
errorBody.Message = strings.Trim(errorBody.Message, " ")
211215
errorBody.ErrorCode = fmt.Sprintf("SCIM_%s", errorBody.ScimStatus)
212216
}
213217
if resp.StatusCode == 403 {

scim/resource_service_principal.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ func ResourceServicePrincipal() *schema.Resource {
6969
m["active"].Default = true
7070
return m
7171
})
72-
spFromData := func(d *schema.ResourceData) (user User, err error) {
72+
spFromData := func(d *schema.ResourceData) User {
7373
var u entity
7474
common.DataToStructPointer(d, servicePrincipalSchema, &u)
7575
return User{
7676
ApplicationID: u.ApplicationID,
7777
DisplayName: u.DisplayName,
7878
Active: u.Active,
7979
Entitlements: readEntitlementsFromData(d),
80-
}, nil
80+
}
8181
}
8282
return common.Resource{
8383
Schema: servicePrincipalSchema,
@@ -95,10 +95,7 @@ func ResourceServicePrincipal() *schema.Resource {
9595
return nil
9696
},
9797
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
98-
sp, err := spFromData(d)
99-
if err != nil {
100-
return err
101-
}
98+
sp := spFromData(d)
10299
if c.IsAws() && sp.ApplicationID != "" {
103100
return fmt.Errorf("application_id is not allowed for service principals in Databricks on AWS")
104101
}
@@ -121,11 +118,11 @@ func ResourceServicePrincipal() *schema.Resource {
121118
return sp.Entitlements.readIntoData(d)
122119
},
123120
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
124-
sp, err := spFromData(d)
125-
if err != nil {
126-
return err
127-
}
128-
return NewServicePrincipalsAPI(ctx, c).Update(d.Id(), sp)
121+
return NewServicePrincipalsAPI(ctx, c).Update(d.Id(), User{
122+
DisplayName: d.Get("display_name").(string),
123+
Active: d.Get("active").(bool),
124+
Entitlements: readEntitlementsFromData(d),
125+
})
129126
},
130127
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
131128
return NewServicePrincipalsAPI(ctx, c).Delete(d.Id())

0 commit comments

Comments
 (0)