Skip to content

add import support for forwardemail_domain and forwardemail_alias#10

Open
tdyas wants to merge 5 commits intoforwardemail:mainfrom
tdyas:feat/add-import-support
Open

add import support for forwardemail_domain and forwardemail_alias#10
tdyas wants to merge 5 commits intoforwardemail:mainfrom
tdyas:feat/add-import-support

Conversation

@tdyas
Copy link

@tdyas tdyas commented Feb 21, 2026

What

Add support for importing forwardemail_domain and forwardemail_alias resources.

Why

Allow existing users to migrate their existing ForwardEmail configurations into Terraform.

References

crmne and others added 4 commits August 9, 2025 23:34
- Add ImportState support to domain resources using passthrough
- Add custom import function for alias resources with "domain/alias" format
- Set name field during Read operations to support import state

This allows existing ForwardEmail resources to be imported into Terraform:
- Domains: terraform import forwardemail_domain.example "example.com"
- Aliases: terraform import forwardemail_alias.example "example.com/alias"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

// resourceAliasImport imports an alias using the format "domain/alias_name"
func resourceAliasImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "/")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an ID right? The alias import function uses the alias name as the resource identifier instead of the API-assigned ID, which means subsequent Terraform operations (read, update, delete) will pass a name where the API expects an ID.

Copy link
Author

Choose a reason for hiding this comment

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

Good point. This seems like a bug in this code which came from the other author going by the code from the original PR.

My own PR used alias.Id as the ID as retrieved from the API, but I didn't catch the issue in this code. Will fix.

Copy link
Author

Choose a reason for hiding this comment

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

Also, user experience question: Should we support just specifying the API ID in addition to this DOMAIN/NAME format. Although frankly I'd rather the format be NAME@DOMAIN which fits with the alias being an email alias. Thoughts?

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants