-
Notifications
You must be signed in to change notification settings - Fork 89
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
issue#511: Add custom domain data source #526
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,35 @@ | ||
--- | ||
page_title: "Data Source: auth0_custom_domain" | ||
description: |- | ||
Data source to retrieve the custom domain configuration. | ||
--- | ||
|
||
# Data Source: auth0_custom_domain | ||
|
||
Data source to retrieve the custom domain configuration. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- `custom_client_ip_header` (String) The HTTP header to fetch the client's IP address. Cannot be set on auth0_managed domains. | ||
- `domain` (String) Name of the custom domain. | ||
- `id` (String) The ID of this resource. | ||
- `origin_domain_name` (String) Once the configuration status is `ready`, the DNS name of the Auth0 origin server that handles traffic for the custom domain. | ||
- `primary` (Boolean) Indicates whether this is a primary domain. | ||
- `status` (String) Configuration status for the custom domain. Options include `disabled`, `pending`, `pending_verification`, and `ready`. | ||
- `tls_policy` (String) TLS policy for the custom domain. Available options are: `compatible` or `recommended`. Compatible includes TLS 1.0, 1.1, 1.2, and recommended only includes TLS 1.2. Cannot be set on self_managed domains. | ||
- `type` (String) Provisioning type for the custom domain. Options include `auth0_managed_certs` and `self_managed_certs`. | ||
- `verification` (List of Object) Configuration settings for verification. (see [below for nested schema](#nestedatt--verification)) | ||
|
||
<a id="nestedatt--verification"></a> | ||
### Nested Schema for `verification` | ||
|
||
Read-Only: | ||
|
||
- `methods` (List of Map of 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,58 @@ | ||
package customdomain | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/auth0/go-auth0/management" | ||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema" | ||
) | ||
|
||
// NewDataSource will return a new auth0_custom_domain data source. | ||
func NewDataSource() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: readCustomDomainForDataSource, | ||
Description: "Data source to retrieve the custom domain configuration.", | ||
Schema: dataSourceSchema(), | ||
} | ||
} | ||
|
||
func dataSourceSchema() map[string]*schema.Schema { | ||
return internalSchema.TransformResourceToDataSource(NewResource().Schema) | ||
} | ||
|
||
func readCustomDomainForDataSource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
api := meta.(*management.Management) | ||
|
||
customDomains, err := api.CustomDomain.List() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
// At the moment there can only ever | ||
// be one custom domain configured. | ||
customDomain := customDomains[0] | ||
|
||
data.SetId(customDomain.GetID()) | ||
|
||
result := multierror.Append( | ||
data.Set("domain", customDomain.GetDomain()), | ||
data.Set("type", customDomain.GetType()), | ||
data.Set("primary", customDomain.GetPrimary()), | ||
data.Set("status", customDomain.GetStatus()), | ||
data.Set("origin_domain_name", customDomain.GetOriginDomainName()), | ||
data.Set("custom_client_ip_header", customDomain.GetCustomClientIPHeader()), | ||
data.Set("tls_policy", customDomain.GetTLSPolicy()), | ||
) | ||
|
||
if customDomain.Verification != nil { | ||
result = multierror.Append(result, data.Set("verification", []map[string]interface{}{ | ||
{"methods": customDomain.Verification.Methods}, | ||
})) | ||
} | ||
|
||
return diag.FromErr(result.ErrorOrNil()) | ||
} |
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 @@ | ||
package customdomain_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/auth0/terraform-provider-auth0/internal/acctest" | ||
"github.com/auth0/terraform-provider-auth0/internal/template" | ||
) | ||
|
||
const testAccDataSourceCustomDomain = ` | ||
resource "auth0_custom_domain" "my_custom_domain" { | ||
domain = "{{.testName}}.auth.terraform-provider-auth0.com" | ||
type = "auth0_managed_certs" | ||
tls_policy = "recommended" | ||
} | ||
|
||
data "auth0_custom_domain" "test" { | ||
depends_on = [ auth0_custom_domain.my_custom_domain ] | ||
} | ||
` | ||
|
||
func TestAccDataSourceCustomDomain(t *testing.T) { | ||
testName := strings.ToLower(t.Name()) | ||
|
||
acctest.Test(t, resource.TestCase{ | ||
PreventPostDestroyRefresh: true, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: template.ParseTestName(testAccDataSourceCustomDomain, testName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.auth0_custom_domain.test", "domain", fmt.Sprintf("%s.auth.terraform-provider-auth0.com", testName)), | ||
resource.TestCheckResourceAttr("data.auth0_custom_domain.test", "type", "auth0_managed_certs"), | ||
resource.TestCheckResourceAttr("data.auth0_custom_domain.test", "status", "pending_verification"), | ||
resource.TestCheckResourceAttr("data.auth0_custom_domain.test", "origin_domain_name", ""), | ||
resource.TestCheckResourceAttr("data.auth0_custom_domain.test", "primary", "true"), | ||
resource.TestCheckResourceAttr("data.auth0_custom_domain.test", "verification.#", "1"), | ||
resource.TestCheckResourceAttr("data.auth0_custom_domain.test", "custom_client_ip_header", ""), | ||
resource.TestCheckResourceAttr("data.auth0_custom_domain.test", "tls_policy", "recommended"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just asking, do we use this context anywhere? To configure the API client? or is the instance
meta
already configured?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The meta property has access to the already configured api client, essentially it is the api client at the moment, however in the future we could create a struct that holds both the api client and the key/value mutex used throughout other resources. In this way we wouldn't use the mutex as a global property any more.
The context isn't used anywhere sadly 😢 but needs to be present within the function signature. Hopefully the Go SDK v1 introduces context passing as a first param in function calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the context (put not intended). Maybe mark it as unused with
_
then?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, too late 😬, my bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh, sorry already merged 😢 I can follow up on this, maybe tweaking our linter to check and fix such occurences.