diff --git a/auth0/resource_auth0_custom_domain_verification_test.go b/auth0/resource_auth0_custom_domain_verification_test.go index 7e133b49b..7b43ad217 100644 --- a/auth0/resource_auth0_custom_domain_verification_test.go +++ b/auth0/resource_auth0_custom_domain_verification_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func TestAccCustomDomainVerification(t *testing.T) { +func TestAccCustomDomainVerificationWithAuth0ManagedCerts(t *testing.T) { resource.Test(t, resource.TestCase{ ProviderFactories: map[string]func() (*schema.Provider, error){ "auth0": func() (*schema.Provider, error) { @@ -16,18 +16,39 @@ func TestAccCustomDomainVerification(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccCustomDomainVerification, + Config: testAccCustomDomainVerificationWithAuth0ManagedCerts, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "domain", "terraform-provider.auth0.com"), resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "type", "auth0_managed_certs"), - resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "custom_domain_id"), + // The status attribute is set to "pending_verification" + // here because Terraform has settled its state before + // attempting the custom domain verification. We need to + // refresh the state to move it along. + resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "status", "pending_verification"), + resource.TestCheckResourceAttrPair( + "auth0_custom_domain.my_custom_domain", "id", + "auth0_custom_domain_verification.my_custom_domain_verification", "custom_domain_id", + ), + resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "origin_domain_name"), + ), + }, + { + Config: testAccCustomDomainVerificationWithAuth0ManagedCerts, + Check: resource.ComposeTestCheckFunc( + // By applying an identical plan, we can reconcile the + // status attribute. + resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "status", "ready"), + resource.TestCheckResourceAttrPair( + "auth0_custom_domain.my_custom_domain", "origin_domain_name", + "auth0_custom_domain_verification.my_custom_domain_verification", "origin_domain_name", + ), ), }, }, }) } -const testAccCustomDomainVerification = ` +const testAccCustomDomainVerificationWithAuth0ManagedCerts = ` resource "auth0_custom_domain" "my_custom_domain" { domain = "terraform-provider.auth0.com" type = "auth0_managed_certs" @@ -38,3 +59,55 @@ resource "auth0_custom_domain_verification" "my_custom_domain_verification" { timeouts { create = "15m" } } ` + +func TestAccCustomDomainVerificationWithSelfManagedCerts(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProviderFactories: map[string]func() (*schema.Provider, error){ + "auth0": func() (*schema.Provider, error) { + return providerWithMockedAPI(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: testAccCustomDomainVerificationWithSelfManagedCerts, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "domain", "terraform-provider.auth0.com"), + resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "type", "self_managed_certs"), + resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "status", "pending_verification"), + resource.TestCheckResourceAttrPair( + "auth0_custom_domain.my_custom_domain", "id", + "auth0_custom_domain_verification.my_custom_domain_verification", "custom_domain_id", + ), + resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "origin_domain_name"), + resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "cname_api_key"), + ), + }, + { + Config: testAccCustomDomainVerificationWithSelfManagedCerts, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "status", "ready"), + resource.TestCheckResourceAttrPair( + "auth0_custom_domain.my_custom_domain", "origin_domain_name", + "auth0_custom_domain_verification.my_custom_domain_verification", "origin_domain_name", + ), + // Even though we can no longer read this from the API, it + // should remain set after refresh as we won't clear it out + // in the read operation. + resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "cname_api_key"), + ), + }, + }, + }) +} + +const testAccCustomDomainVerificationWithSelfManagedCerts = ` +resource "auth0_custom_domain" "my_custom_domain" { + domain = "terraform-provider.auth0.com" + type = "self_managed_certs" +} + +resource "auth0_custom_domain_verification" "my_custom_domain_verification" { + custom_domain_id = auth0_custom_domain.my_custom_domain.id + timeouts { create = "15m" } +} +` diff --git a/dockerfiles/wiremock/__files/custom_domain_verification/with_self_managed_certs/custom_domain_pending_verification.json b/dockerfiles/wiremock/__files/custom_domain_verification/with_self_managed_certs/custom_domain_pending_verification.json new file mode 100644 index 000000000..2e228d181 --- /dev/null +++ b/dockerfiles/wiremock/__files/custom_domain_verification/with_self_managed_certs/custom_domain_pending_verification.json @@ -0,0 +1,17 @@ +{ + "custom_domain_id": "cd_selfmanaged", + "domain": "terraform-provider.auth0.com", + "primary": true, + "status": "pending_verification", + "type": "self_managed_certs", + "verification": { + "methods": [ + { + "name": "txt", + "record": "a6124756-554d-4a4b-b140-787bdea2e89c", + "domain": "_cf-custom-hostname.terraform-provider.auth0.com" + } + ] + }, + "tls_policy": "recommended" +} diff --git a/dockerfiles/wiremock/__files/custom_domain_verification/with_self_managed_certs/custom_domain_ready.json b/dockerfiles/wiremock/__files/custom_domain_verification/with_self_managed_certs/custom_domain_ready.json new file mode 100644 index 000000000..8b895afb9 --- /dev/null +++ b/dockerfiles/wiremock/__files/custom_domain_verification/with_self_managed_certs/custom_domain_ready.json @@ -0,0 +1,18 @@ +{ + "custom_domain_id": "cd_selfmanaged", + "domain": "terraform-provider.auth0.com", + "primary": true, + "status": "ready", + "type": "self_managed_certs", + "origin_domain_name": "terraform-provider-cd-selfmanaged.edge.tenants.eu.auth0.com", + "verification": { + "methods": [ + { + "name": "txt", + "record": "a6124756-554d-4a4b-b140-787bdea2e89c", + "domain": "_cf-custom-hostname.terraform-provider.auth0.com" + } + ] + }, + "tls_policy": "recommended" +} diff --git a/dockerfiles/wiremock/__files/custom_domain_verification/with_self_managed_certs/custom_domain_verify.json b/dockerfiles/wiremock/__files/custom_domain_verification/with_self_managed_certs/custom_domain_verify.json new file mode 100644 index 000000000..aa6c6090d --- /dev/null +++ b/dockerfiles/wiremock/__files/custom_domain_verification/with_self_managed_certs/custom_domain_verify.json @@ -0,0 +1,19 @@ +{ + "custom_domain_id": "cd_selfmanaged", + "domain": "terraform-provider.auth0.com", + "primary": true, + "status": "ready", + "type": "self_managed_certs", + "origin_domain_name": "terraform-provider-cd-selfmanaged.edge.tenants.eu.auth0.com", + "cname_api_key": "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff", + "verification": { + "methods": [ + { + "name": "txt", + "record": "a6124756-554d-4a4b-b140-787bdea2e89c", + "domain": "_cf-custom-hostname.terraform-provider.auth0.com" + } + ] + }, + "tls_policy": "recommended" +} diff --git a/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/delete_custom_domain_204.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/delete_custom_domain_204.json new file mode 100644 index 000000000..107c28190 --- /dev/null +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/delete_custom_domain_204.json @@ -0,0 +1,9 @@ +{ + "request": { + "method": "DELETE", + "url": "/api/v2/custom-domains/cd_selfmanaged" + }, + "response": { + "status": 204 + } +} diff --git a/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/get_custom_domain_pending_verification_200.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/get_custom_domain_pending_verification_200.json new file mode 100644 index 000000000..c3f0cff68 --- /dev/null +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/get_custom_domain_pending_verification_200.json @@ -0,0 +1,15 @@ +{ + "scenarioName": "Custom domain verification with self-managed certificates", + "requiredScenarioState": "Started", + "request": { + "method": "GET", + "url": "/api/v2/custom-domains/cd_selfmanaged" + }, + "response": { + "status": 200, + "bodyFileName": "custom_domain_verification/with_self_managed_certs/custom_domain_pending_verification.json", + "headers": { + "Content-Type": "application/json" + } + } +} diff --git a/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/get_custom_domain_ready_200.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/get_custom_domain_ready_200.json new file mode 100644 index 000000000..e631d7293 --- /dev/null +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/get_custom_domain_ready_200.json @@ -0,0 +1,15 @@ +{ + "scenarioName": "Custom domain verification with self-managed certificates", + "requiredScenarioState": "Verified", + "request": { + "method": "GET", + "url": "/api/v2/custom-domains/cd_selfmanaged" + }, + "response": { + "status": 200, + "bodyFileName": "custom_domain_verification/with_self_managed_certs/custom_domain_ready.json", + "headers": { + "Content-Type": "application/json" + } + } +} diff --git a/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/post_custom_domain_201.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/post_custom_domain_201.json new file mode 100644 index 000000000..6b091294d --- /dev/null +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/post_custom_domain_201.json @@ -0,0 +1,21 @@ +{ + "request": { + "method": "POST", + "url": "/api/v2/custom-domains", + "bodyPatterns": [ + { + "equalToJson": { + "domain": "terraform-provider.auth0.com", + "type": "self_managed_certs" + } + } + ] + }, + "response": { + "status": 201, + "bodyFileName": "custom_domain_verification/with_self_managed_certs/custom_domain_pending_verification.json", + "headers": { + "Content-Type": "application/json" + } + } +} diff --git a/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/post_custom_domain_verify_200.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/post_custom_domain_verify_200.json new file mode 100644 index 000000000..00d8d08a1 --- /dev/null +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_self_managed_certs/post_custom_domain_verify_200.json @@ -0,0 +1,16 @@ +{ + "scenarioName": "Custom domain verification with self-managed certificates", + "requiredScenarioState": "Started", + "newScenarioState": "Verified", + "request": { + "method": "POST", + "url": "/api/v2/custom-domains/cd_selfmanaged/verify" + }, + "response": { + "status": 201, + "bodyFileName": "custom_domain_verification/with_self_managed_certs/custom_domain_verify.json", + "headers": { + "Content-Type": "application/json" + } + } +}