-
Notifications
You must be signed in to change notification settings - Fork 108
feat: Add auth0_custom_domains data source for listing multiple custom domains
#1389
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
Open
duedares-rvj
wants to merge
11
commits into
main
Choose a base branch
from
DXCDT-1159/MCD_En_EA
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b7fb07a
feat: Added new data-source for MCD and support for filters
duedares-rvj 3e13c9e
Updated test cases
duedares-rvj 879e25f
updated tests
duedares-rvj e05320a
Merge branch 'main' into DXCDT-1159/MCD_En_EA
duedares-rvj fdcb84c
updated test cases
duedares-rvj 15937c1
Updated test cases
duedares-rvj 82b726c
updated test cases
duedares-rvj da55941
Added examples
duedares-rvj 8dd610c
Updated error
duedares-rvj 6f6b82e
Merge branch 'main' into DXCDT-1159/MCD_En_EA
duedares-rvj 510f774
Merge branch 'main' into DXCDT-1159/MCD_En_EA
duedares-rvj 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 hidden or 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 hidden or 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,88 @@ | ||
| --- | ||
| page_title: "Data Source: auth0_custom_domains" | ||
| description: |- | ||
| Data source to retrieve multiple custom domains based on a search query. | ||
| --- | ||
|
|
||
| # Data Source: auth0_custom_domains | ||
|
|
||
| Data source to retrieve multiple custom domains based on a search query. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```terraform | ||
| resource "auth0_custom_domain" "my_custom_domain_1" { | ||
| domain = "example1.auth.tempdomain.com" | ||
| type = "auth0_managed_certs" | ||
| tls_policy = "recommended" | ||
| domain_metadata = { | ||
| key1 : "foo1" | ||
| key2 : "bar1" | ||
| } | ||
| } | ||
|
|
||
| resource "auth0_custom_domain" "my_custom_domain_2" { | ||
| domain = "example2.auth.tempdomain.com" | ||
| type = "auth0_managed_certs" | ||
| tls_policy = "recommended" | ||
| domain_metadata = { | ||
| key1 : "foo2" | ||
| key2 : "bar2" | ||
| } | ||
| } | ||
|
|
||
| data "auth0_custom_domains" "test" { | ||
| q = "domain:example1* AND status:pending_verification" | ||
| } | ||
| ``` | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|
|
||
| ### Optional | ||
|
|
||
| - `q` (String) Search query string to filter custom domains. | ||
|
|
||
| ### Read-Only | ||
|
|
||
| - `custom_domains` (List of Object) List of custom domains matching the search criteria. (see [below for nested schema](#nestedatt--custom_domains)) | ||
| - `id` (String) The ID of this resource. | ||
|
|
||
| <a id="nestedatt--custom_domains"></a> | ||
| ### Nested Schema for `custom_domains` | ||
|
|
||
| Read-Only: | ||
|
|
||
| - `certificate` (List of Object) (see [below for nested schema](#nestedobjatt--custom_domains--certificate)) | ||
| - `custom_client_ip_header` (String) | ||
| - `domain` (String) | ||
| - `domain_metadata` (Map of String) | ||
| - `origin_domain_name` (String) | ||
| - `primary` (Boolean) | ||
| - `status` (String) | ||
| - `tls_policy` (String) | ||
| - `type` (String) | ||
| - `verification` (List of Object) (see [below for nested schema](#nestedobjatt--custom_domains--verification)) | ||
|
|
||
| <a id="nestedobjatt--custom_domains--certificate"></a> | ||
| ### Nested Schema for `custom_domains.certificate` | ||
|
|
||
| Read-Only: | ||
|
|
||
| - `certificate_authority` (String) | ||
| - `error_msg` (String) | ||
| - `renews_before` (String) | ||
| - `status` (String) | ||
|
|
||
|
|
||
| <a id="nestedobjatt--custom_domains--verification"></a> | ||
| ### Nested Schema for `custom_domains.verification` | ||
|
|
||
| Read-Only: | ||
|
|
||
| - `error_msg` (String) | ||
| - `last_verified_at` (String) | ||
| - `methods` (List of Map of String) | ||
| - `status` (String) | ||
|
|
||
|
|
This file contains hidden or 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 hidden or 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,23 @@ | ||
| resource "auth0_custom_domain" "my_custom_domain_1" { | ||
| domain = "example1.auth.tempdomain.com" | ||
| type = "auth0_managed_certs" | ||
| tls_policy = "recommended" | ||
| domain_metadata = { | ||
| key1 : "foo1" | ||
| key2 : "bar1" | ||
| } | ||
| } | ||
|
|
||
| resource "auth0_custom_domain" "my_custom_domain_2" { | ||
| domain = "example2.auth.tempdomain.com" | ||
| type = "auth0_managed_certs" | ||
| tls_policy = "recommended" | ||
| domain_metadata = { | ||
| key1 : "foo2" | ||
| key2 : "bar2" | ||
| } | ||
| } | ||
|
|
||
| data "auth0_custom_domains" "test" { | ||
| q = "domain:example1* AND status:pending_verification" | ||
| } | ||
This file contains hidden or 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 hidden or 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,77 @@ | ||
| package customdomain | ||
|
|
||
| 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/auth0/terraform-provider-auth0/internal/config" | ||
| internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema" | ||
| ) | ||
|
|
||
| // NewCustomDomainsDataSource returns a new auth0_custom_domains data source that allows | ||
| // listing custom domains by query filter. | ||
| func NewCustomDomainsDataSource() *schema.Resource { | ||
| return &schema.Resource{ | ||
| ReadContext: readCustomDomainsForDataSource, | ||
| Description: "Data source to retrieve multiple custom domains based on a search query.", | ||
| Schema: map[string]*schema.Schema{ | ||
| "q": { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use |
||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| Description: "Search query string to filter custom domains.", | ||
| }, | ||
| "custom_domains": { | ||
| Type: schema.TypeList, | ||
| Computed: true, | ||
| Description: "List of custom domains matching the search criteria.", | ||
| Elem: &schema.Resource{ | ||
| Schema: internalSchema.TransformResourceToDataSource(NewResource().Schema), | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func readCustomDomainsForDataSource(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
| api := meta.(*config.Config).GetAPI() | ||
| q := data.Get("q").(string) | ||
|
|
||
| var customDomains []*management.CustomDomain | ||
| var from string | ||
| options := []management.RequestOption{ | ||
| management.Take(100), | ||
| } | ||
|
|
||
| if q != "" { | ||
| options = append(options, management.Parameter("q", q)) | ||
| } | ||
|
|
||
| for { | ||
| if from != "" { | ||
| options = append(options, management.From(from)) | ||
| } | ||
|
|
||
| customDomainList, err := api.CustomDomain.ListWithPagination(ctx, options...) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| customDomains = append(customDomains, customDomainList.CustomDomains...) | ||
|
|
||
| if !customDomainList.HasNext() { | ||
| break | ||
| } | ||
| from = customDomainList.Next | ||
| } | ||
|
|
||
| data.SetId("custom-domains") | ||
| if err := flattenCustomDomainList(data, customDomains); err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
86 changes: 86 additions & 0 deletions
86
internal/auth0/customdomain/data_source_custom_domains_test.go
This file contains hidden or 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,86 @@ | ||
| package customdomain_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
|
|
||
| "github.com/auth0/terraform-provider-auth0/internal/acctest" | ||
| ) | ||
|
|
||
| const testAccCustomDomainFirst = ` | ||
| resource "auth0_custom_domain" "my_custom_domain1" { | ||
| domain = "authninja1.auth.tempdomain.com" | ||
| type = "self_managed_certs" | ||
| } | ||
| ` | ||
|
|
||
| const testAccCustomDomainSecond = testAccCustomDomainFirst + ` | ||
| resource "auth0_custom_domain" "my_custom_domain2" { | ||
| domain = "authninja2.auth.tempdomain.com" | ||
| type = "self_managed_certs" | ||
| } | ||
| ` | ||
|
|
||
| const testAccCustomDomainThird = testAccCustomDomainSecond + ` | ||
| resource "auth0_custom_domain" "my_custom_domain3" { | ||
| domain = "beacon.auth.tempdomain.com" | ||
| type = "self_managed_certs" | ||
| } | ||
| ` | ||
|
|
||
| const testAccDataSourceCustomDomainsFilter1 = ` | ||
| data "auth0_custom_domains" "filtered" { | ||
| q = "domain:authninja*" | ||
| } | ||
| ` | ||
|
|
||
| const testAccDataSourceCustomDomainsFilter2 = ` | ||
| data "auth0_custom_domains" "filtered" { | ||
| q = "domain:beacon*" | ||
| } | ||
| ` | ||
|
|
||
| func TestAccDataSourceCustomDomains(t *testing.T) { | ||
| acctest.Test(t, resource.TestCase{ | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| // We had to split this into two separate posts to work around an issue | ||
| // in the test recording library. We need to add X-Request-Id header to the POST requests | ||
| // to fix this, and make sure that go-vcr uses that to match requests. | ||
| Config: acctest.ParseTestName(testAccCustomDomainFirst, t.Name()), | ||
| }, | ||
| { | ||
| Config: acctest.ParseTestName(testAccCustomDomainSecond, t.Name()), | ||
| }, | ||
| { | ||
| Config: testAccCustomDomainThird + testAccDataSourceCustomDomainsFilter1, | ||
| Check: resource.ComposeTestCheckFunc( | ||
| resource.TestCheckResourceAttr("data.auth0_custom_domains.filtered", "q", "domain:authninja*"), | ||
| resource.TestCheckResourceAttr("data.auth0_custom_domains.filtered", "custom_domains.#", "2"), | ||
|
|
||
| resource.TestCheckTypeSetElemNestedAttrs("data.auth0_custom_domains.filtered", "custom_domains.*", map[string]string{ | ||
| "type": "self_managed_certs", | ||
| "status": "pending_verification", | ||
| }), | ||
| ), | ||
| }, | ||
| { | ||
| Config: testAccCustomDomainThird + testAccDataSourceCustomDomainsFilter2, | ||
| Check: resource.ComposeTestCheckFunc( | ||
| resource.TestCheckResourceAttr("data.auth0_custom_domains.filtered", "q", "domain:beacon*"), | ||
| resource.TestCheckResourceAttr("data.auth0_custom_domains.filtered", "custom_domains.#", "1"), | ||
|
|
||
| resource.TestCheckTypeSetElemNestedAttrs("data.auth0_custom_domains.filtered", "custom_domains.*", map[string]string{ | ||
| "type": "self_managed_certs", | ||
| "status": "pending_verification", | ||
| }), | ||
|
|
||
| resource.TestCheckTypeSetElemNestedAttrs("data.auth0_custom_domains.filtered", "custom_domains.*", map[string]string{ | ||
| "domain": "beacon.auth.tempdomain.com", | ||
| }), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
Also, Please update the template for custom_domains and custom_domains that highlights a note of fields that only support for EA users (like domain_metadata)