-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Add sesv2 data sources for email identity and mail from attributes #32026
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4068fdd
add data source for sesv2 email identity and email identity mail from
jchorl 105be1d
Merge branch 'main' into jchorl/sesdata
jar-b 3b79e6c
d/aws_sesv2_email_identity: use computed only attributes
jar-b 3cc2445
d/aws_sesv2_email_identity: append diags
jar-b 76cc415
d/aws_sesv2_email_identity_mail_from_attributes: use computed only at…
jar-b 1a30c77
d/aws_sesv2_email_identity_mail_from_attributes: append diags
jar-b 66f0eb8
chore: changelog
jar-b 9f0f412
r/aws_sesv2_email_identity(docs): use standard tags, tags_all descrip…
jar-b 753fe02
d/aws_sesv2_email_identity(docs): add tags description
jar-b 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 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,7 @@ | ||
```release-note:new-data-source | ||
aws_sesv2_email_identity | ||
``` | ||
|
||
```release-note:new-data-source | ||
aws_sesv2_email_identity_mail_from_attributes | ||
``` |
This file contains 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
This file contains 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,125 @@ | ||
package sesv2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
"github.com/hashicorp/terraform-provider-aws/internal/create" | ||
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
// @SDKDataSource("aws_sesv2_email_identity") | ||
// @Tags(identifierAttribute="arn") | ||
func DataSourceEmailIdentity() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadWithoutTimeout: dataSourceEmailIdentityRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"configuration_set_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"dkim_signing_attributes": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"current_signing_key_length": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"domain_signing_private_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"domain_signing_selector": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"last_key_generation_timestamp": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"next_signing_key_length": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"signing_attributes_origin": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tokens": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"email_identity": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"identity_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
names.AttrTags: tftags.TagsSchemaComputed(), | ||
"verified_for_sending_status": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
const ( | ||
DSNameEmailIdentity = "Email Identity Data Source" | ||
) | ||
|
||
func dataSourceEmailIdentityRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
conn := meta.(*conns.AWSClient).SESV2Client(ctx) | ||
|
||
name := d.Get("email_identity").(string) | ||
|
||
out, err := FindEmailIdentityByID(ctx, conn, name) | ||
if err != nil { | ||
return append(diags, create.DiagError(names.SESV2, create.ErrActionReading, DSNameEmailIdentity, name, err)...) | ||
} | ||
|
||
arn := emailIdentityNameToARN(meta, name) | ||
|
||
d.SetId(name) | ||
d.Set("arn", arn) | ||
d.Set("configuration_set_name", out.ConfigurationSetName) | ||
d.Set("email_identity", name) | ||
|
||
if out.DkimAttributes != nil { | ||
tfMap := flattenDKIMAttributes(out.DkimAttributes) | ||
tfMap["domain_signing_private_key"] = d.Get("dkim_signing_attributes.0.domain_signing_private_key").(string) | ||
tfMap["domain_signing_selector"] = d.Get("dkim_signing_attributes.0.domain_signing_selector").(string) | ||
|
||
if err := d.Set("dkim_signing_attributes", []interface{}{tfMap}); err != nil { | ||
return append(diags, create.DiagError(names.SESV2, create.ErrActionSetting, ResNameEmailIdentity, name, err)...) | ||
} | ||
} else { | ||
d.Set("dkim_signing_attributes", nil) | ||
} | ||
|
||
d.Set("identity_type", string(out.IdentityType)) | ||
d.Set("verified_for_sending_status", out.VerifiedForSendingStatus) | ||
|
||
return diags | ||
} |
This file contains 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,56 @@ | ||
package sesv2_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
func TestAccSESV2EmailIdentityDataSource_basic(t *testing.T) { | ||
ctx := acctest.Context(t) | ||
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
resourceName := "aws_sesv2_email_identity.test" | ||
dataSourceName := "data.aws_sesv2_email_identity.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(ctx, t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, names.SESV2EndpointID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
CheckDestroy: testAccCheckEmailIdentityDestroy(ctx), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccEmailIdentityDataSourceConfig_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckEmailIdentityExists(ctx, dataSourceName), | ||
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(resourceName, "email_identity", dataSourceName, "email_identity"), | ||
resource.TestCheckResourceAttrPair(resourceName, "dkim_signing_attributes.#", dataSourceName, "dkim_signing_attributes.#"), | ||
resource.TestCheckResourceAttrPair(resourceName, "dkim_signing_attributes.0.current_signing_key_length", dataSourceName, "dkim_signing_attributes.0.current_signing_key_length"), | ||
resource.TestCheckResourceAttrPair(resourceName, "dkim_signing_attributes.0.last_key_generation_timestamp", dataSourceName, "dkim_signing_attributes.0.last_key_generation_timestamp"), | ||
resource.TestCheckResourceAttrPair(resourceName, "dkim_signing_attributes.0.next_signing_key_length", dataSourceName, "dkim_signing_attributes.0.next_signing_key_length"), | ||
resource.TestCheckResourceAttrPair(resourceName, "dkim_signing_attributes.0.signing_attributes_origin", dataSourceName, "dkim_signing_attributes.0.signing_attributes_origin"), | ||
resource.TestCheckResourceAttrPair(resourceName, "dkim_signing_attributes.0.status", dataSourceName, "dkim_signing_attributes.0.status"), | ||
resource.TestCheckResourceAttrPair(resourceName, "dkim_signing_attributes.0.tokens.#", dataSourceName, "dkim_signing_attributes.0.tokens.#"), | ||
resource.TestCheckResourceAttrPair(resourceName, "identity_type", dataSourceName, "identity_type"), | ||
resource.TestCheckResourceAttrPair(resourceName, "verified_for_sending_status", dataSourceName, "verified_for_sending_status"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccEmailIdentityDataSourceConfig_basic(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_sesv2_email_identity" "test" { | ||
email_identity = %[1]q | ||
} | ||
|
||
data "aws_sesv2_email_identity" "test" { | ||
email_identity = aws_sesv2_email_identity.test.email_identity | ||
} | ||
`, rName) | ||
} |
63 changes: 63 additions & 0 deletions
63
internal/service/sesv2/email_identity_mail_from_attributes_data_source.go
This file contains 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,63 @@ | ||
package sesv2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
"github.com/hashicorp/terraform-provider-aws/internal/create" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
// @SDKDataSource("aws_sesv2_email_identity_mail_from_attributes") | ||
func DataSourceEmailIdentityMailFromAttributes() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadWithoutTimeout: dataSourceEmailIdentityMailFromAttributesRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"behavior_on_mx_failure": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"email_identity": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"mail_from_domain": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
const ( | ||
DSNameEmailIdentityMailFromAttributes = "Email Identity Mail From Attributes Data Source" | ||
) | ||
|
||
func dataSourceEmailIdentityMailFromAttributesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
conn := meta.(*conns.AWSClient).SESV2Client(ctx) | ||
|
||
name := d.Get("email_identity").(string) | ||
|
||
out, err := FindEmailIdentityByID(ctx, conn, name) | ||
|
||
if err != nil { | ||
return append(diags, create.DiagError(names.SESV2, create.ErrActionReading, ResNameEmailIdentityMailFromAttributes, name, err)...) | ||
} | ||
|
||
d.SetId(name) | ||
d.Set("email_identity", name) | ||
|
||
if out.MailFromAttributes != nil { | ||
d.Set("behavior_on_mx_failure", out.MailFromAttributes.BehaviorOnMxFailure) | ||
d.Set("mail_from_domain", out.MailFromAttributes.MailFromDomain) | ||
} else { | ||
d.Set("behavior_on_mx_failure", nil) | ||
d.Set("mail_from_domain", nil) | ||
} | ||
|
||
return diags | ||
} |
57 changes: 57 additions & 0 deletions
57
internal/service/sesv2/email_identity_mail_from_attributes_data_source_test.go
This file contains 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,57 @@ | ||
package sesv2_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/sesv2/types" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
func TestAccSESV2EmailIdentityMailFromAttributesDataSource_basic(t *testing.T) { | ||
ctx := acctest.Context(t) | ||
domain := acctest.RandomDomain() | ||
mailFromDomain1 := domain.Subdomain("test1") | ||
|
||
rName := domain.String() | ||
resourceName := "aws_sesv2_email_identity_mail_from_attributes.test" | ||
dataSourceName := "data.aws_sesv2_email_identity_mail_from_attributes.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(ctx, t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, names.SESV2EndpointID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
CheckDestroy: testAccCheckEmailIdentityDestroy(ctx), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccEmailIdentityMailFromAttributesDataSourceConfig_basic(rName, string(types.BehaviorOnMxFailureRejectMessage), mailFromDomain1.String()), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckEmailIdentityMailFromAttributesExists(ctx, dataSourceName), | ||
resource.TestCheckResourceAttrPair(resourceName, "email_identity", dataSourceName, "email_identity"), | ||
resource.TestCheckResourceAttrPair(resourceName, "behavior_on_mx_failure", dataSourceName, "behavior_on_mx_failure"), | ||
resource.TestCheckResourceAttrPair(resourceName, "mail_from_domain", dataSourceName, "mail_from_domain"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccEmailIdentityMailFromAttributesDataSourceConfig_basic(rName, behaviorOnMXFailure, mailFromDomain string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_sesv2_email_identity" "test" { | ||
email_identity = %[1]q | ||
} | ||
|
||
resource "aws_sesv2_email_identity_mail_from_attributes" "test" { | ||
email_identity = aws_sesv2_email_identity.test.email_identity | ||
behavior_on_mx_failure = %[2]q | ||
mail_from_domain = %[3]q | ||
} | ||
|
||
data "aws_sesv2_email_identity_mail_from_attributes" "test" { | ||
email_identity = aws_sesv2_email_identity_mail_from_attributes.test.email_identity | ||
} | ||
`, rName, behaviorOnMXFailure, mailFromDomain) | ||
} |
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.
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.
For my edification, why is this commit necessary? Do folks add diagnostics in non-error cases? Is this just setting up for a future where we may add diagnostics all throughout this function?
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.
The latter - future-proofing for cases where we might add non-error diagnostics. The newer Plugin-Framework uses this diagnostics pattern, so we try to make Plugin-SDK based resources look similar.
There are a bunch of legacy Plugin-SDK based resources that don't look this way, but when new stuff comes in its a simple enough change we usually switch over.