-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DXCDT-644: Added tests for SCIM resource and data source, as well as …
…updated for API changes
- Loading branch information
Showing
16 changed files
with
6,008 additions
and
2,609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
|
Oops, something went wrong.