Skip to content

Commit

Permalink
DXCDT-644: Added tests for SCIM resource and data source, as well as …
Browse files Browse the repository at this point in the history
…updated for API changes
  • Loading branch information
acwest committed Jul 5, 2024
1 parent 51ef335 commit 51cd673
Show file tree
Hide file tree
Showing 16 changed files with 6,008 additions and 2,609 deletions.
47 changes: 47 additions & 0 deletions docs/data-sources/scim_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
page_title: "Data Source: auth0_scim_configuration"
description: |-
Data source to retrieve a specific Auth0 connection by connection_id or name.
---

# Data Source: auth0_scim_configuration

Data source to retrieve a specific Auth0 connection by `connection_id` or `name`.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `connection_id` (String) ID of the connection for this SCIM configuration.

### Read-Only

- `connection_name` (String) Name of the connection for this SCIM configuration.
- `default_mapping` (Set of Object) Default mapping between Auth0 attributes and SCIM attributes for this connectiion. (see [below for nested schema](#nestedatt--default_mapping))
- `id` (String) The ID of this resource.
- `mapping` (Set of Object) Mapping between Auth0 attributes and SCIM attributes. (see [below for nested schema](#nestedatt--mapping))
- `strategy` (String) Schema of the connection for this SCIM configuration.
- `tenant_name` (String) Name of the tenant for this SCIM configuration.
- `user_id_attribute` (String) User ID attribute for generation unique of user ids.

<a id="nestedatt--default_mapping"></a>
### Nested Schema for `default_mapping`

Read-Only:

- `auth0` (String)
- `scim` (String)


<a id="nestedatt--mapping"></a>
### Nested Schema for `mapping`

Read-Only:

- `auth0` (String)
- `scim` (String)


50 changes: 50 additions & 0 deletions docs/resources/scim_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
page_title: "Resource: auth0_scim_configuration"
description: |-
With this resource, you can use SCIM to manage a connection.
---

# Resource: auth0_scim_configuration

With this resource, you can use `SCIM` to manage a connection.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `connection_id` (String) ID of the connection for this SCIM configuration.

### Optional

- `mapping` (Block Set) Mapping between Auth0 attributes and SCIM attributes. If `mapping` is set, `user_id_attribute` must be set as well. (see [below for nested schema](#nestedblock--mapping))
- `user_id_attribute` (String) User ID attribute for generation unique of user ids. If `user_id_attribute` is set, `mapping` must be set as well. Defaults to `externalId`.

### Read-Only

- `connection_name` (String) Name of the connection for this SCIM configuration.
- `default_mapping` (Set of Object) Default mapping between Auth0 attributes and SCIM attributes for this connectiion. (see [below for nested schema](#nestedatt--default_mapping))
- `id` (String) The ID of this resource.
- `strategy` (String) Schema of the connection for this SCIM configuration.
- `tenant_name` (String) Name of the tenant for this SCIM configuration.

<a id="nestedblock--mapping"></a>
### Nested Schema for `mapping`

Required:

- `auth0` (String) The field location in the Auth0 schema.
- `scim` (String) The field location in the SCIM schema.


<a id="nestedatt--default_mapping"></a>
### Nested Schema for `default_mapping`

Read-Only:

- `auth0` (String)
- `scim` (String)


10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
github.com/PuerkitoBio/rehttp v1.4.0
github.com/auth0/go-auth0 v1.7.1-0.20240626072303-25c4eba656f2
github.com/auth0/go-auth0 v1.7.1-0.20240705143414-4125b95164a8
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-multierror v1.1.1
Expand Down Expand Up @@ -75,15 +75,15 @@ require (
github.com/yuin/goldmark-meta v1.1.0 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e // indirect
google.golang.org/grpc v1.64.0 // indirect
Expand Down
20 changes: 8 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/auth0/go-auth0 v1.7.0 h1:THNAa+r4vRqRft7nO4pSH1KoFpBj7HS/LuxwoxUw99M=
github.com/auth0/go-auth0 v1.7.0/go.mod h1:k1+9letwAlJR1UIlHJVekSOm/WOOJiRHt39rLUfsO+A=
github.com/auth0/go-auth0 v1.7.1-0.20240626072303-25c4eba656f2 h1:RHI32M9d+HjPwTh2mbv54UKzhYNunwK5qqI1ZN6WFdE=
github.com/auth0/go-auth0 v1.7.1-0.20240626072303-25c4eba656f2/go.mod h1:k1+9letwAlJR1UIlHJVekSOm/WOOJiRHt39rLUfsO+A=
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48=
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0/go.mod h1:6L7zgvqo0idzI7IO8de6ZC051AfXb5ipkIJ7bIA2tGA=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
Expand Down Expand Up @@ -223,8 +219,8 @@ go.abhg.dev/goldmark/frontmatter v0.2.0/go.mod h1:XqrEkZuM57djk7zrlRUB02x8I5J0px
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d h1:N0hmiNbwsSNwHBAvR3QB5w25pUwH4tK0Y/RltD1j1h4=
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand Down Expand Up @@ -259,8 +255,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
Expand All @@ -271,13 +267,13 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
Expand Down
110 changes: 4 additions & 106 deletions internal/auth0/connection/data_source_scim.go
Original file line number Diff line number Diff line change
@@ -1,117 +1,15 @@
package connection

import (
"context"

"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/auth0/terraform-provider-auth0/internal/config"
)

// NewScimConfigurationDataSource will return a new auth0_scim_configuration data source.
func NewScimConfigurationDataSource() *schema.Resource {
// NewSCIMConfigurationDataSource will return a new auth0_scim_configuration data source.
func NewSCIMConfigurationDataSource() *schema.Resource {
return &schema.Resource{
ReadContext: readScimConfigurationForDataSource,
ReadContext: readSCIMConfiguration,
Description: "Data source to retrieve a specific Auth0 connection by `connection_id` or `name`.",
Schema: map[string]*schema.Schema{
"connection_id": {
Type: schema.TypeString,
Optional: true,
Description: "ID of the connection for this SCIM configuration. If not provided, `connection_name` must be set.",
ExactlyOneOf: []string{"connection_id", "connection_name"},
},
"connection_name": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the connection for this SCIM configuration. If not provided, `connection_id` must be set. " +
"For performance, it is advised to use the `connection_id` as a lookup if possible.",
ExactlyOneOf: []string{"connection_id", "connection_name"},

},
"strategy": {
Type: schema.TypeString,
Computed: true,
Description: "Schema of the connection for this SCIM configuration.",
},
"tenant_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the tenant for this SCIM configuration.",
},
"user_id_attribute": {
Type: schema.TypeString,
Computed: true,
Description: "User ID attribute for generation unique user ids.",
},
"mapping": {
Type: schema.TypeSet,
Computed: true,
Description: "Mapping between Auth0 attributes and SCIM attributes.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"auth0": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The field location in the Auth0 schema.",
},
"scim": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The field location in the SCIM schema.",
},
},
},
},
"default_mapping": {
Type: schema.TypeSet,
Computed: true,
Description: "Default mapping between Auth0 attributes and SCIM attributes for this connection.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"auth0": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The field location in the Auth0 schema.",
},
"scim": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "The field location in the SCIM schema.",
},
},
},
},
},
Schema: scimDataSourceSchema,
}
}

func readScimConfigurationForDataSource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

connectionID := data.Get("connection_id").(string)

scimConfiguration, err := api.Connection.ReadScimConfiguration(ctx, connectionID)
if err != nil {
return diag.FromErr(err)
}
defaultScimConfiguration, err := api.Connection.ReadScimDefaultConfiguration(ctx, connectionID)
if err != nil {
return diag.FromErr(err)
}
data.SetId(connectionID)

result := multierror.Append(
flattenScimConfigurationForDataSource(data, scimConfiguration),
data.Set("default_mapping", flattenScimMappings(defaultScimConfiguration.GetMapping())),
)

return diag.FromErr(result.ErrorOrNil())
}

Loading

0 comments on commit 51cd673

Please sign in to comment.