Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions forwardemail/resource_forwardemail_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package forwardemail

import (
"context"
"fmt"
"strings"

"github.com/forwardemail/forwardemail-api-go/forwardemail"
"github.com/google/go-cmp/cmp"
Expand All @@ -12,6 +14,9 @@ import (
func resourceAlias() *schema.Resource {
return &schema.Resource{
Description: "A resource to create Forward Email domain aliases.",
Importer: &schema.ResourceImporter{
StateContext: importAliasState,
},
Schema: map[string]*schema.Schema{
"domain": {
Type: schema.TypeString,
Expand Down Expand Up @@ -119,6 +124,7 @@ func resourceAliasRead(ctx context.Context, d *schema.ResourceData, meta interfa
}

for k, v := range map[string]interface{}{
"name": name,
"domain": alias.Domain.Name,
"recipient_verification": alias.HasRecipientVerification,
"enabled": alias.IsEnabled,
Expand Down Expand Up @@ -201,3 +207,26 @@ func toChanges(p, c interface{}) []interface{} {

return nil
}

// importAliasState imports an alias using the format "domain/alias_name"
func importAliasState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "/")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid import ID format. Expected: domain/alias_name")
}

domain := parts[0]
name := parts[1]

d.Set("domain", domain)
d.Set("name", name)
d.SetId(name)

// Call read to populate the rest of the fields
diags := resourceAliasRead(ctx, d, meta)
if diags.HasError() {
return nil, fmt.Errorf("failed to read alias: %v", diags[0].Summary)
}

return []*schema.ResourceData{d}, nil
}
4 changes: 4 additions & 0 deletions forwardemail/resource_forwardemail_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
func resourceDomain() *schema.Resource {
return &schema.Resource{
Description: "A resource to create Forward Email domains.",
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -108,6 +111,7 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf
}

for k, v := range map[string]interface{}{
"name": name,
"adult_content_protection": domain.HasAdultContentProtection,
"phishing_protection": domain.HasPhishingProtection,
"executable_protection": domain.HasExecutableProtection,
Expand Down