Skip to content

Commit

Permalink
Add Support for auth0_prompt_screen_partial and `auth0_prompt_scree…
Browse files Browse the repository at this point in the history
…n_partials` in Prompt Resources (auth0#1013)

* Add-Support-for-Prompt-Screen-Partials

* Add auth0_prompt_screen_partial Resource and Required Docs

* Fix Linting

* Updated Go-auth0 Version 1.9.0 to 1.10.0

* Added Testcases for other insertionpoints as well

* Fixed Linting

* Added More testcases

* Correct depends on for datasource of prompt partials

Signed-off-by: BryanLewis-AtOkta <[email protected]>
  • Loading branch information
bryanlewis-okta committed Oct 24, 2024
1 parent feee8ba commit ef20947
Show file tree
Hide file tree
Showing 28 changed files with 7,523 additions and 37 deletions.
51 changes: 51 additions & 0 deletions docs/data-sources/prompt_screen_partials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
page_title: "Data Source: auth0_prompt_screen_partials"
description: |-
Data source to retrieve a specific Auth0 prompt screen partials by prompt_type.
---

# Data Source: auth0_prompt_screen_partials

Data source to retrieve a specific Auth0 prompt screen partials by `prompt_type`.

## Example Usage

```terraform
data "auth0_prompt_screen_partials" "prompt_screen_partials" {
prompt_type = "prompt-name"
}
```

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

### Required

- `prompt_type` (String) The type of prompt to customize.

### Read-Only

- `id` (String) The ID of this resource.
- `screen_partials` (Block List) The screen partials associated with the prompt type. (see [below for nested schema](#nestedblock--screen_partials))

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

Read-Only:

- `insertion_points` (List of Object) (see [below for nested schema](#nestedatt--screen_partials--insertion_points))
- `screen_name` (String) The name of the screen associated with the partials

<a id="nestedatt--screen_partials--insertion_points"></a>
### Nested Schema for `screen_partials.insertion_points`

Read-Only:

- `form_content_end` (String)
- `form_content_start` (String)
- `form_footer_end` (String)
- `form_footer_start` (String)
- `secondary_actions_end` (String)
- `secondary_actions_start` (String)


19 changes: 11 additions & 8 deletions docs/resources/prompt_partials.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---
page_title: "Resource: auth0_prompt_partials"
description: |-
With this resource, you can manage a customized sign up and login experience by adding custom content, form elements and css/javascript. You can read more about this here https://auth0.com/docs/customize/universal-login-pages/customize-signup-and-login-prompts.
With this resource, you can manage a customized sign up and login experience by adding custom content, form elements and css/javascript. You can read more about this here https://auth0.com/docs/customize/universal-login-pages/customize-signup-and-login-prompts.
---

# Resource: auth0_prompt_partials

With this resource, you can manage a customized sign up and login experience by adding custom content, form elements and css/javascript. You can read more about this [here](https://auth0.com/docs/customize/universal-login-pages/customize-signup-and-login-prompts).

!> **Deprecated:** `auth0_prompt_partials` has been deprecated. Please use `auth0_prompt_screen_partials` for managing multiple
prompt screens or `auth0_prompt_screen_partial` for managing a single prompt screen.

## Example Usage

```terraform
Expand All @@ -28,16 +31,16 @@ resource "auth0_prompt_partials" "my_login_prompt_partials" {

### Required

- `prompt` (String) The prompt that you are adding partials for. Options are: `login-id`, `login`, `login-password`, `signup`, `signup-id`, `signup-password`.
- `prompt` (String, Deprecated) The prompt that you are adding partials for. Options are: `login-id`, `login`, `login-password`, `signup`, `signup-id`, `signup-password`, `login-passwordless`.

### Optional

- `form_content_end` (String) Content that goes at the end of the form.
- `form_content_start` (String) Content that goes at the start of the form.
- `form_footer_end` (String) Footer content for the end of the footer.
- `form_footer_start` (String) Footer content for the start of the footer.
- `secondary_actions_end` (String) Actions that go at the end of secondary actions.
- `secondary_actions_start` (String) Actions that go at the start of secondary actions.
- `form_content_end` (String, Deprecated) Content that goes at the end of the form.
- `form_content_start` (String, Deprecated) Content that goes at the start of the form.
- `form_footer_end` (String, Deprecated) Footer content for the end of the footer.
- `form_footer_start` (String, Deprecated) Footer content for the start of the footer.
- `secondary_actions_end` (String, Deprecated) Actions that go at the end of secondary actions.
- `secondary_actions_start` (String, Deprecated) Actions that go at the start of secondary actions.

### Read-Only

Expand Down
70 changes: 70 additions & 0 deletions docs/resources/prompt_screen_partial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
page_title: "Resource: auth0_prompt_screen_partial"
description: |-
With this resource, you can manage a customized sign up and login experience by adding custom content, form elements and css/javascript. You can read more about this here https://auth0.com/docs/customize/universal-login-pages/customize-signup-and-login-prompts.
---

# Resource: auth0_prompt_screen_partial

With this resource, you can manage a customized sign up and login experience by adding custom content, form elements and css/javascript. You can read more about this [here](https://auth0.com/docs/customize/universal-login-pages/customize-signup-and-login-prompts).

!> This resource appends a specific prompt screen to the list of prompt screens displayed to the user during the authentication flow.
In contrast, the `auth0_prompt_screen_partials` resource manages the complete set of prompt screens that are displayed during the
authentication flow. To avoid potential issues, it is recommended not to use this resource in conjunction with the
`auth0_prompt_screen_partials` resource when managing prompt screens for the same prompt.

## Example Usage

```terraform
resource "auth0_prompt_screen_partial" "login" {
prompt_type = "login"
screen_name = "login"
insertion_points {
form_content_start = "<div>Form Content Start</div>"
form_content_end = "<div>Form Content End</div>"
}
}
```

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

### Required

- `prompt_type` (String) The prompt that you are adding partials for. Options are: `login-id`, `login`, `login-password`, `signup`, `signup-id`, `signup-password`, `login-passwordless`.
- `screen_name` (String) The name of the screen associated with the partials

### Optional

- `insertion_points` (Block List, Max: 1) The insertion points for the partials. (see [below for nested schema](#nestedblock--insertion_points))

### Read-Only

- `id` (String) The ID of this resource.

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

Optional:

- `form_content_end` (String) Content that goes at the end of the form.
- `form_content_start` (String) Content that goes at the start of the form.
- `form_footer_end` (String) Footer content for the end of the footer.
- `form_footer_start` (String) Footer content for the start of the footer.
- `secondary_actions_end` (String) Actions that go at the end of secondary actions.
- `secondary_actions_start` (String) Actions that go at the start of secondary actions.

## Import

Import is supported using the following syntax:

```shell
# This resource can be imported using the prompt name and screen_name.
#
# As this is not a resource identifiable by an ID within the Auth0 Management API,
# login can be imported using the prompt name and screen name using the format:
# prompt_name:screen_name
#
# Example:
terraform import auth0_prompt_screen_partial.login "login:login"
```
84 changes: 84 additions & 0 deletions docs/resources/prompt_screen_partials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
page_title: "Resource: auth0_prompt_screen_partials"
description: |-
With this resource, you can manage a customized sign up and login experience by adding custom content, form elements and css/javascript. You can read more about this here https://auth0.com/docs/customize/universal-login-pages/customize-signup-and-login-prompts.
---

# Resource: auth0_prompt_screen_partials

With this resource, you can manage a customized sign up and login experience by adding custom content, form elements and css/javascript. You can read more about this [here](https://auth0.com/docs/customize/universal-login-pages/customize-signup-and-login-prompts).

!> This resource manages the entire set of prompt screens enabled for a prompt. In contrast, the `auth0_prompt_screen_partial`
resource appends a specific prompt screen to the list of prompt screens displayed to the user during the authentication flow.
To avoid potential issues, it is recommended not to use this resource in conjunction with the `auth0_prompt_screen_partial`
resource when managing prompt screens for the same prompt.

## Example Usage

```terraform
resource "auth0_prompt_screen_partials" "prompt_screen_partials" {
prompt_type = "login-passwordless"
screen_partials {
screen_name = "login-passwordless-email-code"
insertion_points {
form_content_start = "<div>Form Content Start</div>"
form_content_end = "<div>Form Content End</div>"
}
}
screen_partials {
screen_name = "login-passwordless-sms-otp"
insertion_points {
form_content_start = "<div>Form Content Start</div>"
form_content_end = "<div>Form Content End</div>"
}
}
}
```

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

### Required

- `prompt_type` (String) The prompt that you are adding partials for. Options are: `login-id`, `login`, `login-password`, `signup`, `signup-id`, `signup-password`, `login-passwordless`.

### Optional

- `screen_partials` (Block List) (see [below for nested schema](#nestedblock--screen_partials))

### Read-Only

- `id` (String) The ID of this resource.

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

Required:

- `insertion_points` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--screen_partials--insertion_points))
- `screen_name` (String) The name of the screen associated with the partials

<a id="nestedblock--screen_partials--insertion_points"></a>
### Nested Schema for `screen_partials.insertion_points`

Optional:

- `form_content_end` (String) Content that goes at the end of the form.
- `form_content_start` (String) Content that goes at the start of the form.
- `form_footer_end` (String) Footer content for the end of the footer.
- `form_footer_start` (String) Footer content for the start of the footer.
- `secondary_actions_end` (String) Actions that go at the end of secondary actions.
- `secondary_actions_start` (String) Actions that go at the start of secondary actions.

## Import

Import is supported using the following syntax:

```shell
# This resource can be imported using the prompt name.
#
# Example:
terraform import auth0_prompt_screen_partials.prompt_screen_partials "login-passwordless"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "auth0_prompt_screen_partials" "prompt_screen_partials" {
prompt_type = "prompt-name"
}
8 changes: 8 additions & 0 deletions examples/resources/auth0_prompt_screen_partial/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This resource can be imported using the prompt name and screen_name.
#
# As this is not a resource identifiable by an ID within the Auth0 Management API,
# login can be imported using the prompt name and screen name using the format:
# prompt_name:screen_name
#
# Example:
terraform import auth0_prompt_screen_partial.login "login:login"
8 changes: 8 additions & 0 deletions examples/resources/auth0_prompt_screen_partial/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "auth0_prompt_screen_partial" "login" {
prompt_type = "login"
screen_name = "login"
insertion_points {
form_content_start = "<div>Form Content Start</div>"
form_content_end = "<div>Form Content End</div>"
}
}
4 changes: 4 additions & 0 deletions examples/resources/auth0_prompt_screen_partials/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This resource can be imported using the prompt name.
#
# Example:
terraform import auth0_prompt_screen_partials.prompt_screen_partials "login-passwordless"
19 changes: 19 additions & 0 deletions examples/resources/auth0_prompt_screen_partials/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "auth0_prompt_screen_partials" "prompt_screen_partials" {
prompt_type = "login-passwordless"

screen_partials {
screen_name = "login-passwordless-email-code"
insertion_points {
form_content_start = "<div>Form Content Start</div>"
form_content_end = "<div>Form Content End</div>"
}
}

screen_partials {
screen_name = "login-passwordless-sms-otp"
insertion_points {
form_content_start = "<div>Form Content Start</div>"
form_content_end = "<div>Form Content End</div>"
}
}
}
2 changes: 1 addition & 1 deletion 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.9.0
github.com/auth0/go-auth0 v1.10.0
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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.9.0 h1:IRCMQ9zLmFn8aAKkd+lopFo6IAdpARYSRf8i9ZACG48=
github.com/auth0/go-auth0 v1.9.0/go.mod h1:p9KEEkCehO7tcDf32r1r06Ji63mqZa1QZ6IfQ172bys=
github.com/auth0/go-auth0 v1.10.0 h1:7fjcuVjtTET5NEg8RPl3uYadGto7WZnBl31LcnXANWc=
github.com/auth0/go-auth0 v1.10.0/go.mod h1:VMTiemb4rn2TUPiH9obD2FoHS2FoTALTsnKU0NUXLxk=
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
48 changes: 48 additions & 0 deletions internal/auth0/prompt/data_source_screen_partials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package prompt

import (
"context"

"github.com/auth0/go-auth0/management"
"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"
internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema"
)

// NewPromptScreenPartialsDataSource creates a new data source to retrieve a specific Auth0 prompt screen partials by `prompt_type`.
func NewPromptScreenPartialsDataSource() *schema.Resource {
return &schema.Resource{
ReadContext: readPromptScreenPartialsDataSource,
Description: "Data source to retrieve a specific Auth0 prompt screen partials by `prompt_type`.",
Schema: getScreenPartialsDataSourceSchema(),
}
}

func getScreenPartialsDataSourceSchema() map[string]*schema.Schema {
dataSourceSchema := internalSchema.TransformResourceToDataSource(NewScreenPartialsResource().Schema)
internalSchema.SetExistingAttributesAsRequired(dataSourceSchema, "prompt_type")
dataSourceSchema["prompt_type"].Description = "The type of prompt to customize."
dataSourceSchema["prompt_type"].ValidateFunc = validation.StringInSlice(allowedPromptsWithPartials, false)
dataSourceSchema["screen_partials"].Description = "The screen partials associated with the prompt type."
dataSourceSchema["screen_partials"].Optional = true
return dataSourceSchema
}

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

promptType := data.Get("prompt_type").(string)
screenPartials, err := api.Prompt.GetPartials(ctx, management.PromptType(promptType))
if err != nil {
return diag.FromErr(err)
}
data.SetId(promptType)
if err := flattenPromptScreenPartials(data, screenPartials); err != nil {
return diag.FromErr(err)
}

return diag.FromErr(err)
}
Loading

0 comments on commit ef20947

Please sign in to comment.