diff --git a/auth0/provider.go b/auth0/provider.go index 618915ce..9d4183bc 100644 --- a/auth0/provider.go +++ b/auth0/provider.go @@ -45,21 +45,22 @@ func init() { }, }, ResourcesMap: map[string]*schema.Resource{ - "auth0_client": newClient(), - "auth0_global_client": newGlobalClient(), - "auth0_client_grant": newClientGrant(), - "auth0_connection": newConnection(), - "auth0_custom_domain": newCustomDomain(), - "auth0_resource_server": newResourceServer(), - "auth0_rule": newRule(), - "auth0_rule_config": newRuleConfig(), - "auth0_hook": newHook(), - "auth0_prompt": newPrompt(), - "auth0_email": newEmail(), - "auth0_email_template": newEmailTemplate(), - "auth0_user": newUser(), - "auth0_tenant": newTenant(), - "auth0_role": newRole(), + "auth0_client": newClient(), + "auth0_global_client": newGlobalClient(), + "auth0_client_grant": newClientGrant(), + "auth0_connection": newConnection(), + "auth0_custom_domain": newCustomDomain(), + "auth0_custom_domain_verification": newCustomDomainVerification(), + "auth0_resource_server": newResourceServer(), + "auth0_rule": newRule(), + "auth0_rule_config": newRuleConfig(), + "auth0_hook": newHook(), + "auth0_prompt": newPrompt(), + "auth0_email": newEmail(), + "auth0_email_template": newEmailTemplate(), + "auth0_user": newUser(), + "auth0_tenant": newTenant(), + "auth0_role": newRole(), }, ConfigureFunc: Configure, } diff --git a/auth0/resource_auth0_custom_domain_verification.go b/auth0/resource_auth0_custom_domain_verification.go new file mode 100644 index 00000000..9fec95aa --- /dev/null +++ b/auth0/resource_auth0_custom_domain_verification.go @@ -0,0 +1,62 @@ +package auth0 + +import ( + "net/http" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + + "gopkg.in/auth0.v4" + "gopkg.in/auth0.v4/management" +) + +func newCustomDomainVerification() *schema.Resource { + return &schema.Resource{ + + Create: createCustomDomainVerification, + Read: readCustomDomainVerification, + Delete: deleteCustomDomainVerification, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "custom_domain_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + } +} + +func createCustomDomainVerification(d *schema.ResourceData, m interface{}) error { + api := m.(*management.Management) + c, err := api.CustomDomain.Verify(d.Get("custom_domain_id").(string)) + if err != nil { + return err + } + d.SetId(auth0.StringValue(c.ID)) + return nil +} + +func readCustomDomainVerification(d *schema.ResourceData, m interface{}) error { + api := m.(*management.Management) + c, err := api.CustomDomain.Read(d.Id()) + if err != nil { + if mErr, ok := err.(management.Error); ok { + if mErr.Status() == http.StatusNotFound { + d.SetId("") + return nil + } + } + return err + } + + d.SetId(auth0.StringValue(c.ID)) + d.Set("custom_domain_id", auth0.StringValue(c.ID)) + return nil +} + +func deleteCustomDomainVerification(d *schema.ResourceData, m interface{}) error { + return nil +} diff --git a/website/auth0.erb b/website/auth0.erb index 076e7508..4d38190f 100644 --- a/website/auth0.erb +++ b/website/auth0.erb @@ -11,6 +11,7 @@