-
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.
Feat: Add resource for prompt partials (#918)
* Add resource for prompt partials * Added docs for prompt partials * Add cassette for tests * Add comment to public function * Adjust imports for linter * Teardown partials in tests * Go the TF config route * Wait on branding for test dependency * Fix auth0_prompt_partials --------- Co-authored-by: Michael Christenson II <michael.christensonii@okta.com> Co-authored-by: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com>
- Loading branch information
1 parent
b5d51e8
commit 21e8c52
Showing
13 changed files
with
1,400 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
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. | ||
--- | ||
|
||
# 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). | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "auth0_prompt_partials" "my_login_prompt_partials" { | ||
prompt = "login" | ||
form_content_start = "<div>Updated Form Content Start</div>" | ||
form_content_end = "<div>Updated Form Content End</div>" | ||
form_footer_start = "<div>Updated Footer Start</div>" | ||
form_footer_end = "<div>Updated Footer End</div>" | ||
secondary_actions_start = "<div>Updated Secondary Actions Start</div>" | ||
secondary_actions_end = "<div>Updated Secondary Actions End</div>" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `prompt` (String) The prompt that you are adding partials for. Options are: `login-id`, `login`, `login-password`, `signup`, `signup-id`, `signup-password`. | ||
|
||
### 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. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# This resource can be imported using the prompt name. | ||
# | ||
# Example: | ||
terraform import auth0_prompt_partials.my_login_prompt_partials "login" | ||
``` |
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,4 @@ | ||
# This resource can be imported using the prompt name. | ||
# | ||
# Example: | ||
terraform import auth0_prompt_partials.my_login_prompt_partials "login" |
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,10 @@ | ||
resource "auth0_prompt_partials" "my_login_prompt_partials" { | ||
prompt = "login" | ||
|
||
form_content_start = "<div>Updated Form Content Start</div>" | ||
form_content_end = "<div>Updated Form Content End</div>" | ||
form_footer_start = "<div>Updated Footer Start</div>" | ||
form_footer_end = "<div>Updated Footer End</div>" | ||
secondary_actions_start = "<div>Updated Secondary Actions Start</div>" | ||
secondary_actions_end = "<div>Updated Secondary Actions End</div>" | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package prompt | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"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" | ||
) | ||
|
||
var allowedPromptsWithPartials = []string{ | ||
string(management.PromptLoginID), | ||
string(management.PromptLogin), | ||
string(management.PromptLoginPassword), | ||
string(management.PromptSignup), | ||
string(management.PromptSignupID), | ||
string(management.PromptSignupPassword), | ||
} | ||
|
||
// NewPartialsResource creates a new resource for partial prompts. | ||
func NewPartialsResource() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: createPromptPartials, | ||
ReadContext: readPromptPartials, | ||
UpdateContext: updatePromptPartials, | ||
DeleteContext: deletePromptPartials, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
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).", | ||
Schema: map[string]*schema.Schema{ | ||
"form_content_start": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Content that goes at the start of the form.", | ||
}, | ||
"form_content_end": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Content that goes at the end of the form.", | ||
}, | ||
"form_footer_start": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Footer content for the start of the footer.", | ||
}, | ||
"form_footer_end": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Footer content for the end of the footer.", | ||
}, | ||
"secondary_actions_start": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Actions that go at the start of secondary actions.", | ||
}, | ||
"secondary_actions_end": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Actions that go at the end of secondary actions.", | ||
}, | ||
"prompt": { | ||
Type: schema.TypeString, | ||
ValidateFunc: validation.StringInSlice(allowedPromptsWithPartials, false), | ||
Description: "The prompt that you are adding partials for. " + | ||
"Options are: `" + strings.Join(allowedPromptsWithPartials, "`, `") + "`.", | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
func createPromptPartials(ctx context.Context, data *schema.ResourceData, meta any) diag.Diagnostics { | ||
prompt := data.Get("prompt").(string) | ||
data.SetId(prompt) | ||
return updatePromptPartials(ctx, data, meta) | ||
} | ||
|
||
func readPromptPartials(ctx context.Context, data *schema.ResourceData, meta any) diag.Diagnostics { | ||
api := meta.(*config.Config).GetAPI() | ||
|
||
promptPartials, err := api.Prompt.ReadPartials(ctx, management.PromptType(data.Id())) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return diag.FromErr(flattenPromptPartials(data, promptPartials)) | ||
} | ||
|
||
func updatePromptPartials(ctx context.Context, data *schema.ResourceData, meta any) diag.Diagnostics { | ||
api := meta.(*config.Config).GetAPI() | ||
|
||
promptPartials := expandPromptPartials(data) | ||
|
||
if err := api.Prompt.UpdatePartials(ctx, promptPartials); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return readPromptPartials(ctx, data, meta) | ||
} | ||
|
||
func deletePromptPartials(ctx context.Context, data *schema.ResourceData, meta any) diag.Diagnostics { | ||
api := meta.(*config.Config).GetAPI() | ||
|
||
prompt := data.Get("prompt").(string) | ||
|
||
if err := api.Prompt.DeletePartials(ctx, management.PromptType(prompt)); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.