Skip to content

feat: add import support for domains and aliases#7

Closed
crmne wants to merge 2 commits intoforwardemail:mainfrom
crmne:feat/add-import-support
Closed

feat: add import support for domains and aliases#7
crmne wants to merge 2 commits intoforwardemail:mainfrom
crmne:feat/add-import-support

Conversation

@crmne
Copy link

@crmne crmne commented Aug 9, 2025

Summary

This PR adds import functionality to the ForwardEmail Terraform provider, allowing users to import existing domains and aliases into their Terraform state.

Changes

  • Added ImportState support to domain resources using passthrough context
  • Added custom import function for alias resources with "domain/alias" format
  • Set name field during Read operations to properly support import state

Usage Examples

Import a domain

terraform import forwardemail_domain.example "example.com"

Import an alias

terraform import forwardemail_alias.example "example.com/alias-name"
# For catch-all aliases:
terraform import forwardemail_alias.catchall "example.com/*"

Testing

Successfully tested importing:

  • Multiple domains
  • Regular aliases (e.g., hello@domain.com)
  • Catch-all aliases (*@domain.com)
  • Aliases with labels and recipient verification settings

All imports correctly populated the Terraform state with the proper configuration from the ForwardEmail API.

Motivation

Without import support, users with existing ForwardEmail configurations cannot adopt Terraform management without recreating all their resources, which would cause service disruption.

🤖 Generated with Claude Code

- 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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds import support for domains and aliases in the ForwardEmail Terraform provider, enabling users to manage existing resources without recreating them.

  • Added ImportState support to domain resources using passthrough context
  • Added custom import function for alias resources with "domain/alias" format parsing
  • Set name field during Read operations to properly support import state

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
forwardemail/resource_forwardemail_domain.go Adds import support with passthrough context and sets name field in Read operation
forwardemail/resource_forwardemail_alias.go Adds custom import function with domain/alias parsing and sets name field in Read operation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@crmne crmne requested a review from RoseSecurity September 29, 2025 12:42
Copy link
Collaborator

@RoseSecurity RoseSecurity left a comment

Choose a reason for hiding this comment

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

Awesome, thanks again for this contribution. @crmne Would you be able to add an import.sh and import-by-string-id.tf in the examples directory to show how to use this functionality and regenerate the documentation for the registry using: task docs?
Here is a reference

@tdyas
Copy link

tdyas commented Feb 17, 2026

I am interested in the import support added by this PR. I almost added such support myself this week. (I opened #9 to start adding such support for the forwardemail_alias resource, but then closed my PR once I found this PR.)

@crmne: I'd like to help getting this PR completed. Are you still working on this PR?

@RoseSecurity
Copy link
Collaborator

I am interested in the import support added by this PR. I almost added such support myself this week. (I opened #9 to start adding such support for the forwardemail_alias resource, but then closed my PR once I found this PR.)

@crmne: I'd like to help getting this PR completed. Are you still working on this PR?

If you don't get a timely response, feel free to open a new PR with the changes I recommended and we can work to get this merged.

@tdyas
Copy link

tdyas commented Feb 18, 2026

I added the import docs support in this branch on my fork:

  • Upgraded github.com/hashicorp/terraform-plugin-docs dependency to v0.24.0 to gain support for generating docs for the import block syntax.
  • Restructured the examples directory to fit the directory layout expected by tfplugindocs. Otherwise, for example, adding an import.sh file does nothing.

@RoseSecurity
Copy link
Collaborator

I added the import docs support in this branch on my fork:

* Upgraded `github.com/hashicorp/terraform-plugin-docs` dependency to v0.24.0 to gain support for generating docs for the `import` block syntax.

* Restructured the `examples` directory to fit the directory layout expected by `tfplugindocs`. Otherwise, for example, adding an `import.sh` file does nothing.

Would you be able to open a PR for that branch here?

@tdyas
Copy link

tdyas commented Feb 21, 2026

@RoseSecurity: I opened #10

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.

4 participants