add import support for forwardemail_domain and forwardemail_alias#10
add import support for forwardemail_domain and forwardemail_alias#10tdyas wants to merge 5 commits intoforwardemail:mainfrom
forwardemail_domain and forwardemail_alias#10Conversation
- 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(), "/") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Does the ID need both the domain and alias ID in it?
What
Add support for importing
forwardemail_domainandforwardemail_aliasresources.Why
Allow existing users to migrate their existing ForwardEmail configurations into Terraform.
References