-
Notifications
You must be signed in to change notification settings - Fork 10k
f-aws-workmail-domain, f-aws-workmail-default-domain #46931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
subham-ibmhc
wants to merge
15
commits into
main
Choose a base branch
from
f-aws-workmail-domain
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c0791ea
Initial implementation for domain and default_domain resources, added…
subham-ibmhc ae04327
cleanup
subham-ibmhc a659a4e
minor changes
subham-ibmhc a49efa5
stable changes for domain resource
subham-ibmhc 7d1a22a
default_domain stable changes
subham-ibmhc e4cbf39
cleanup tests, update documentation
subham-ibmhc 510b6e5
Add RI support to aws_workmail_domain
subham-ibmhc 1c65df4
Implement list for aws_workmail_domain
subham-ibmhc 2c67370
add changelog
subham-ibmhc db68fdf
fix semgrep and documentation
subham-ibmhc 950b0d1
fix documentation
subham-ibmhc d05c802
fix documentation
subham-ibmhc eacf3a1
Apply fixes suggested in PR review, add RI to default_domain
subham-ibmhc 8c661af
Add description for attributes
subham-ibmhc 9eda8ca
fix linting
subham-ibmhc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ```release-note:new-resource | ||
| aws_workmail_domain | ||
| ``` | ||
|
|
||
| ```release-note:new-resource | ||
| aws_workmail_default_domain | ||
| ``` | ||
|
|
||
| ```release-note:new-list-resource | ||
| aws_workmail_domain | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| // Copyright IBM Corp. 2014, 2026 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package workmail | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/YakDriver/smarterr" | ||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/aws/aws-sdk-go-v2/service/workmail" | ||
| awstypes "github.com/aws/aws-sdk-go-v2/service/workmail/types" | ||
| "github.com/hashicorp/terraform-plugin-framework/diag" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
| "github.com/hashicorp/terraform-provider-aws/internal/errs" | ||
| "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" | ||
| "github.com/hashicorp/terraform-provider-aws/internal/framework" | ||
| "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" | ||
| "github.com/hashicorp/terraform-provider-aws/internal/retry" | ||
| "github.com/hashicorp/terraform-provider-aws/internal/smerr" | ||
| "github.com/hashicorp/terraform-provider-aws/names" | ||
| ) | ||
|
|
||
| // @FrameworkResource("aws_workmail_default_domain", name="Default Domain") | ||
| // @IdentityAttribute("organization_id") | ||
| // @Testing(hasNoPreExistingResource=true) | ||
| // @Testing(importStateIdAttribute="organization_id") | ||
| // @Testing(checkDestroyNoop=true) | ||
| func newDefaultDomainResource(_ context.Context) (resource.ResourceWithConfigure, error) { | ||
| r := &defaultDomainResource{} | ||
|
|
||
| return r, nil | ||
| } | ||
|
|
||
| const ( | ||
| ResNameDefaultDomain = "Default Domain" | ||
| ) | ||
|
|
||
| type defaultDomainResource struct { | ||
| framework.ResourceWithModel[defaultDomainResourceModel] | ||
| framework.WithNoOpDelete | ||
| framework.WithImportByIdentity | ||
| } | ||
|
|
||
| func (r *defaultDomainResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { | ||
| resp.Schema = schema.Schema{ | ||
| Attributes: map[string]schema.Attribute{ | ||
| names.AttrDomainName: schema.StringAttribute{ | ||
| Description: "Mail domain name to set as the default.", | ||
| Required: true, | ||
| }, | ||
| "organization_id": schema.StringAttribute{ | ||
| Description: "Identifier of the WorkMail organization.", | ||
| Required: true, | ||
| PlanModifiers: []planmodifier.String{ | ||
| stringplanmodifier.RequiresReplace(), | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (r *defaultDomainResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { | ||
| conn := r.Meta().WorkMailClient(ctx) | ||
|
|
||
| var plan defaultDomainResourceModel | ||
| smerr.AddEnrich(ctx, &resp.Diagnostics, req.Plan.Get(ctx, &plan)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice! Use of smarterr |
||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| smerr.AddEnrich(ctx, &resp.Diagnostics, r.putDefaultMailDomain(ctx, conn, &plan)) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| smerr.AddEnrich(ctx, &resp.Diagnostics, resp.State.Set(ctx, plan)) | ||
| } | ||
|
|
||
| func (r *defaultDomainResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { | ||
| conn := r.Meta().WorkMailClient(ctx) | ||
|
|
||
| var state defaultDomainResourceModel | ||
| smerr.AddEnrich(ctx, &resp.Diagnostics, req.State.Get(ctx, &state)) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| domainName, err := findDefaultDomainByOrgID(ctx, conn, state.OrganizationId.ValueString()) | ||
| if retry.NotFound(err) { | ||
| resp.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) | ||
| resp.State.RemoveResource(ctx) | ||
| return | ||
| } | ||
| if err != nil { | ||
| smerr.AddError(ctx, &resp.Diagnostics, err, smerr.ID, state.DomainName.String()) | ||
| return | ||
| } | ||
|
|
||
| state.DomainName = flex.StringValueToFramework(ctx, domainName) | ||
|
|
||
| smerr.AddEnrich(ctx, &resp.Diagnostics, resp.State.Set(ctx, &state)) | ||
| } | ||
|
|
||
| func (r *defaultDomainResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { | ||
| conn := r.Meta().WorkMailClient(ctx) | ||
|
|
||
| var plan defaultDomainResourceModel | ||
| smerr.AddEnrich(ctx, &resp.Diagnostics, req.Plan.Get(ctx, &plan)) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| smerr.AddEnrich(ctx, &resp.Diagnostics, r.putDefaultMailDomain(ctx, conn, &plan)) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| smerr.AddEnrich(ctx, &resp.Diagnostics, resp.State.Set(ctx, plan)) | ||
| } | ||
|
|
||
| func (r *defaultDomainResource) putDefaultMailDomain(ctx context.Context, conn *workmail.Client, plan *defaultDomainResourceModel) diag.Diagnostics { | ||
| var diags diag.Diagnostics | ||
|
|
||
| var input workmail.UpdateDefaultMailDomainInput | ||
| smerr.AddEnrich(ctx, &diags, flex.Expand(ctx, plan, &input)) | ||
| if diags.HasError() { | ||
| return diags | ||
| } | ||
|
|
||
| _, err := conn.UpdateDefaultMailDomain(ctx, &input) | ||
| if err != nil { | ||
| smerr.AddError(ctx, &diags, err, smerr.ID, plan.DomainName.String()) | ||
| } | ||
|
|
||
| return diags | ||
| } | ||
| func findDefaultDomainByOrgID(ctx context.Context, conn *workmail.Client, orgID string) (string, error) { | ||
| input := workmail.ListMailDomainsInput{ | ||
| OrganizationId: aws.String(orgID), | ||
| } | ||
|
|
||
| pages := workmail.NewListMailDomainsPaginator(conn, &input) | ||
| for pages.HasMorePages() { | ||
| page, err := pages.NextPage(ctx) | ||
| if err != nil { | ||
| if errs.IsA[*awstypes.ResourceNotFoundException](err) { | ||
| return "", smarterr.NewError(&retry.NotFoundError{ | ||
| LastError: err, | ||
| }) | ||
| } | ||
| return "", smarterr.NewError(err) | ||
| } | ||
|
|
||
| for _, d := range page.MailDomains { | ||
| if d.DefaultDomain { | ||
| return aws.ToString(d.DomainName), nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return "", smarterr.NewError(&retry.NotFoundError{ | ||
| Message: fmt.Sprintf("no default domain found for WorkMail organization %s", orgID), | ||
| }) | ||
| } | ||
|
|
||
| type defaultDomainResourceModel struct { | ||
| framework.WithRegionModel | ||
| OrganizationId types.String `tfsdk:"organization_id"` | ||
| DomainName types.String `tfsdk:"domain_name"` | ||
| } | ||
196 changes: 196 additions & 0 deletions
196
internal/service/workmail/default_domain_identity_gen_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.