Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding auth0_pages data source #706

Merged
merged 17 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ automated workflows before upgrading.

The `auth0_global_client` resource and data source were introduced primarily to allow managing the `custom_login_page`
and `custom_login_page_on` attributes in order to manage the custom login page of a tenant. These are now deprecated in
favor of the `auth0_pages` resource.
favor of the `auth0_pages` resource and data source.

To ensure a smooth transition when we eventually remove the capability to manage the custom
login page through the `auth0_global_client`, we recommend proactively migrating to the `auth0_pages` resource.
To ensure a smooth transition when we eventually remove the capability to manage the custom
login page through the `auth0_global_client`, we recommend proactively migrating to the `auth0_pages` resource and data source.
This will help you stay prepared for future changes.

<table>
Expand Down Expand Up @@ -55,7 +55,7 @@ resource "auth0_pages" "my_pages" {
#### Tenant Pages

The `change_password`, `guardian_mfa_page` and `error_page` attributes on the `auth0_tenant` have been deprecated in
favor of managing them with the `auth0_pages` resource.
favor of managing them with the `auth0_pages` resource.

To ensure a smooth transition when we eventually remove the capability to manage these custom Auth0 pages through the
`auth0_tenant` resource, we recommend proactively migrating to the `auth0_pages` resource. This will help you stay
Expand Down Expand Up @@ -151,7 +151,7 @@ resource "auth0_branding" "my_branding" {
colors {
primary = "#0059d6"
page_background = "#000000"
}
}
}
```

Expand Down
64 changes: 64 additions & 0 deletions docs/data-sources/pages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
page_title: "Data Source: auth0_pages"
description: |-
Use this data source to access the HTML for the login, reset password, multi-factor authentication and error pages.
---

# Data Source: auth0_pages

Use this data source to access the HTML for the login, reset password, multi-factor authentication and error pages.

## Example Usage

```terraform
data "auth0_pages" "my_pages" {}
```

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

### Read-Only

- `change_password` (List of Object) Configuration settings for customizing the Password Reset page. (see [below for nested schema](#nestedatt--change_password))
- `error` (List of Object) Configuration settings for the Error pages. (see [below for nested schema](#nestedatt--error))
- `guardian_mfa` (List of Object) Configuration settings for customizing the Guardian Multi-Factor Authentication page. (see [below for nested schema](#nestedatt--guardian_mfa))
- `id` (String) The ID of this resource.
- `login` (List of Object) Configuration settings for customizing the Login page. (see [below for nested schema](#nestedatt--login))

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

Read-Only:

- `enabled` (Boolean)
- `html` (String)


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

Read-Only:

- `html` (String)
- `show_log_link` (Boolean)
- `url` (String)


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

Read-Only:

- `enabled` (Boolean)
- `html` (String)


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

Read-Only:

- `enabled` (Boolean)
- `html` (String)


1 change: 1 addition & 0 deletions examples/data-sources/auth0_pages/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "auth0_pages" "my_pages" {}
31 changes: 31 additions & 0 deletions internal/auth0/page/data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package page

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema"
)

// NewDataSource will return a new auth0_page data source.
func NewDataSource() *schema.Resource {
return &schema.Resource{
ReadContext: readPagesForDataSource,
Description: "Use this data source to access the HTML for the login, reset password, multi-factor authentication and error pages.",
Schema: dataSourceSchema(),
}
}

func dataSourceSchema() map[string]*schema.Schema {
dataSourceSchema := internalSchema.TransformResourceToDataSource(NewResource().Schema)
return dataSourceSchema
}

func readPagesForDataSource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
// This resource is not identified by an id in the Auth0 management API.
data.SetId(id.UniqueId())
return readPages(ctx, data, meta)
}
63 changes: 63 additions & 0 deletions internal/auth0/page/data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package page_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"

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

const testAccDataPagesConfig = `
resource "auth0_pages" "my_pages" {
login {
enabled = true
html = "<html><body>My Custom Login Page</body></html>"
}

change_password {
enabled = true
html = "<html><body>My Custom Reset Password Page</body></html>"
}

guardian_mfa {
enabled = true
html = "<html><body>My Custom MFA Page</body></html>"
}

error {
show_log_link = true
html = "<html><body>My Custom Error Page</body></html>"
url = "https://example.com"
}
}

data "auth0_pages" "my_pages" {
depends_on = [ auth0_pages.my_pages ]
}
`

func TestAccDataSourcePages(t *testing.T) {
acctest.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
Config: acctest.ParseTestName(testAccDataPagesConfig, t.Name()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "login.#", "1"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "login.0.enabled", "true"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "login.0.html", "<html><body>My Custom Login Page</body></html>"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "change_password.#", "1"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "change_password.0.enabled", "true"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "change_password.0.html", "<html><body>My Custom Reset Password Page</body></html>"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "guardian_mfa.#", "1"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "guardian_mfa.0.enabled", "true"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "guardian_mfa.0.html", "<html><body>My Custom MFA Page</body></html>"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "error.#", "1"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "error.0.show_log_link", "true"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "error.0.html", "<html><body>My Custom Error Page</body></html>"),
resource.TestCheckResourceAttr("data.auth0_pages.my_pages", "error.0.url", "https://example.com"),
),
},
},
})
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func New() *schema.Provider {
"auth0_connection": connection.NewDataSource(),
"auth0_custom_domain": customdomain.NewDataSource(),
"auth0_organization": organization.NewDataSource(),
"auth0_pages": page.NewDataSource(),
"auth0_resource_server": resourceserver.NewDataSource(),
"auth0_role": role.NewDataSource(),
"auth0_tenant": tenant.NewDataSource(),
Expand Down
Loading