Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/data-sources/account.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "forwardemail_account Data Source - terraform-provider-forwardemail"
page_title: "forwardemail_account Data Source - forwardemail"
subcategory: ""
description: |-
A data source to get current account properties.
Expand Down
3 changes: 1 addition & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "forwardemail Provider"
subcategory: ""
description: |-

---
Expand Down Expand Up @@ -32,6 +31,6 @@ provider "forwardemail" {
<!-- schema generated by tfplugindocs -->
## Schema

### Optional
### Required

- `api_key` (String, Sensitive) The API key for Forward Email management
30 changes: 29 additions & 1 deletion docs/resources/alias.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "forwardemail_alias Resource - terraform-provider-forwardemail"
page_title: "forwardemail_alias Resource - forwardemail"
subcategory: ""
description: |-
A resource to create Forward Email domain aliases.
Expand All @@ -10,7 +10,16 @@ description: |-

A resource to create Forward Email domain aliases.

## Example Usage

```terraform
resource "forwardemail_alias" "infracompany" {
name = "Infra Company"
domain = "infracompany.com"

recipients = ["james@rhodes.com"]
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand All @@ -31,3 +40,22 @@ A resource to create Forward Email domain aliases.
### Read-Only

- `id` (String) The ID of this resource.

## Import

Import is supported using the following syntax:

In Terraform v1.5.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `id` attribute, for example:

```terraform
import {
to = forwardemail_alias.example
id = "Infra Company@infracompany.com"
}
```

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
terraform import forwardemail_alias.example 'Infra Company@infracompany.com'
```
27 changes: 26 additions & 1 deletion docs/resources/domain.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "forwardemail_domain Resource - terraform-provider-forwardemail"
page_title: "forwardemail_domain Resource - forwardemail"
subcategory: ""
description: |-
A resource to create Forward Email domains.
Expand All @@ -10,7 +10,13 @@ description: |-

A resource to create Forward Email domains.

## Example Usage

```terraform
resource "forwardemail_domain" "stark" {
name = "stark.com"
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand All @@ -30,3 +36,22 @@ A resource to create Forward Email domains.
### Read-Only

- `id` (String) The ID of this resource.

## Import

Import is supported using the following syntax:

In Terraform v1.5.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `id` attribute, for example:

```terraform
import {
to = forwardemail_domain.example
id = "example.com"
}
```

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
terraform import forwardemail_domain.example example.com
```
4 changes: 4 additions & 0 deletions examples/resources/forwardemail_alias/import-by-string-id.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {
to = forwardemail_alias.example
id = "Infra Company@infracompany.com"
}
1 change: 1 addition & 0 deletions examples/resources/forwardemail_alias/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import forwardemail_alias.example 'Infra Company@infracompany.com'
6 changes: 6 additions & 0 deletions examples/resources/forwardemail_alias/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "forwardemail_alias" "infracompany" {
name = "Infra Company"
domain = "infracompany.com"

recipients = ["james@rhodes.com"]
}
4 changes: 4 additions & 0 deletions examples/resources/forwardemail_domain/import-by-string-id.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {
to = forwardemail_domain.example
id = "example.com"
}
1 change: 1 addition & 0 deletions examples/resources/forwardemail_domain/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import forwardemail_domain.example example.com
3 changes: 3 additions & 0 deletions examples/resources/forwardemail_domain/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "forwardemail_domain" "stark" {
name = "stark.com"
}
4 changes: 4 additions & 0 deletions examples/resources/import-alias-from-name.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {
to = forwardemail_alias.example
id = "Infra Company@infracompany.com"
}
1 change: 1 addition & 0 deletions examples/resources/import-alias.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import forwardemail_alias.example 'Infra Company@infracompany.com'
49 changes: 49 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: resourceAliasImport,
},
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,46 @@ func toChanges(p, c interface{}) []interface{} {

return nil
}

// resourceAliasImport imports an alias using the format "domain/alias_name"
func resourceAliasImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client, ok := meta.(*forwardemail.Client)
if !ok {
return nil, fmt.Errorf("meta is not of type *forwardemail.Client")
}

parts := strings.SplitN(d.Id(), "@", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("invalid import ID format, expected ALIAS|ID@DOMAIN")
}

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

if domain == "" || nameOrId == "" {
return nil, fmt.Errorf("invalid import format %q, expected ALIAS|ID@DOMAIN", d.Id())
}

alias, err := client.GetAlias(domain, nameOrId)
if err != nil {
return nil, fmt.Errorf("error fetching forwardemail_alias %s@%s: %w", nameOrId, domain, err)
}

d.SetId(alias.Id)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the ID need both the domain and alias ID in it?


if err := d.Set("domain", domain); err != nil {
return nil, err
}

if err := d.Set("name", alias.Name); err != nil {
return nil, err
}

// 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
36 changes: 18 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/forwardemail/terraform-provider-forwardemail

go 1.23.3
go 1.24.0

require (
github.com/forwardemail/forwardemail-api-go v0.0.0-20241217201206-b20e80bb9561
github.com/google/go-cmp v0.6.0
github.com/hashicorp/terraform-plugin-docs v0.20.1
github.com/google/go-cmp v0.7.0
github.com/hashicorp/terraform-plugin-docs v0.24.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/jaswdr/faker v1.19.1
)
Expand All @@ -16,17 +16,17 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/ProtonMail/go-crypto v1.1.6 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/bmatcuk/doublestar/v4 v4.9.1 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/cli v1.1.6 // indirect
github.com/hashicorp/cli v1.1.7 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand All @@ -37,11 +37,11 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hc-install v0.9.0 // indirect
github.com/hashicorp/hc-install v0.9.2 // indirect
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.21.0 // indirect
github.com/hashicorp/terraform-json v0.23.0 // indirect
github.com/hashicorp/terraform-exec v0.24.0 // indirect
github.com/hashicorp/terraform-json v0.27.2 // indirect
github.com/hashicorp/terraform-plugin-go v0.25.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.4 // indirect
Expand All @@ -66,16 +66,16 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yuin/goldmark v1.7.7 // indirect
github.com/yuin/goldmark-meta v1.1.0 // indirect
github.com/zclconf/go-cty v1.16.1 // indirect
github.com/zclconf/go-cty v1.17.0 // indirect
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/crypto v0.42.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.29.0 // indirect
golang.org/x/mod v0.28.0 // indirect
golang.org/x/net v0.44.0 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/text v0.30.0 // indirect
golang.org/x/tools v0.37.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/grpc v1.69.4 // indirect
Expand Down
Loading