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

fix custom_domain registration #129

Merged
merged 1 commit into from
Dec 31, 2023
Merged
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
40 changes: 22 additions & 18 deletions provider/resource_frontegg_workspace.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package provider

import (
"context"
"errors"
"fmt"
"log"
"reflect"
@@ -51,6 +52,10 @@ type fronteggCustomDomain struct {
CustomDomain string `json:"customDomain"`
}

type fronteggCustomDomainVerification struct {
Verified bool `json:"verified"`
}

type fronteggAuth struct {
ID string `json:"id"`
AllowNotVerifiedUsersLogin bool `json:"allowNotVerifiedUsersLogin"`
@@ -1458,29 +1463,28 @@ func resourceFronteggWorkspaceUpdate(ctx context.Context, d *schema.ResourceData
in := fronteggCustomDomain{CustomDomain: domain.(string)}

customDomainErr := clientHolder.ApiClient.Post(ctx, fronteggCustomDomainURL, in, nil)
if customDomainErr != nil {
diag.FromErr(customDomainErr)
}

var err error
verified := false
if customDomainErr != nil && strings.Contains(customDomainErr.Error(), "CName not found") {
// Retry for up to a minute if the CName is not found, in case it
// was just installed and DNS is still propagating.
err = retry.RetryContext(ctx, time.Minute, func() *retry.RetryError {
if err := clientHolder.ApiClient.Post(ctx, fronteggCustomDomainVerifyURL, verified, nil); err != nil || !verified {
if strings.Contains(err.Error(), "CName not found") || !verified {
return retry.RetryableError(err)
} else {
return retry.NonRetryableError(err)
}
var out fronteggCustomDomainVerification
err = retry.RetryContext(ctx, time.Minute, func() *retry.RetryError {
if err := clientHolder.ApiClient.Post(ctx, fronteggCustomDomainVerifyURL, nil, &out); err != nil {
if strings.Contains(err.Error(), "CName not found") {
return retry.RetryableError(err)
} else {
return retry.NonRetryableError(err)
}
}
if !out.Verified {
return retry.RetryableError(errors.New("domain not yet verified"))
} else {
return nil
})
}

if verified {
err = clientHolder.ApiClient.Post(ctx, fronteggCustomDomainURL, in, nil)
}
}
})

if !verified || err != nil {
if err != nil {
return diag.FromErr(err)
}
}