Skip to content
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

[WIP] new resource for ses domain identity Policy #5128

Merged
merged 2 commits into from
Jun 19, 2019

Conversation

gmyers-amfam
Copy link
Contributor

Changes proposed in this pull request:

  • Adding a new resource for aws_ses_domain_identity_policy

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSSESDomainIdentityPolicy'

...

This is my first Terraform pull request and I'm a novice when it comes to Go. I tried running the make testacc command above but got a lot of "cannot find package" errors. Is anyone able to assist in either getting me up to speed, or getting this PR polished and tested?

A note on this resource: SES Domain Identities can have any number of policies attached to them, similar to how an S3 bucket has a policy. SES Domain Identity Policies allow for things like cross-account sending access (by setting the 'Principals' field in the policy accordingly) which is clearly missing from Terraform at the moment, hence this PR.

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jul 9, 2018
@bflad bflad added new-resource Introduces a new resource. service/ses Issues and PRs that pertain to the ses service. labels Jul 9, 2018
@rmetzler
Copy link

I'm not sure, why this merge request is stale for the last 5 month. My guess is, it's because of the [WIP] in the title. As a Terraform user I would like to be able to use this resource. Could we please move forward on this issue?

@leoblanc
Copy link

leoblanc commented Dec 20, 2018

@gmyers-amfam Nice work, thanks. We want to use this resource too. How can we unblock the merging step? Who can approve this PR? I guess that removing the "WIP" word from the title (if it's ready) and ping an approver could help. Thanks in advance.

@SijmenHuizenga
Copy link
Contributor

@gmyers-amfam Looking at the code i can make a wild guess what the blocking issues are: It seems that there is no documentation added in this pull-request. Since this change introduces a new resource there should probably be added a documentation page on the website with this pull-request. Also, i can imagine this pull-request becomes easier for the maintainers to merge if there were some tests included. So lets first add some docs and tests, next remove the [wip] and lastly ping the maintainers.

@leoblanc
Copy link

leoblanc commented Mar 4, 2019

Hi, any updates? We are terraforming SES and we have SES domain identity policies. Thanks

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Hi @gmyers-amfam 👋 Thanks for submitting this. See the below for initial feedback. Please reach out if you have any questions or do not have time to implement the items.

Delete: resourceAwsSesDomainIdentityPolicyDelete,

Schema: map[string]*schema.Schema{
"arn": {
Copy link
Contributor

Choose a reason for hiding this comment

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

This attribute should be changed to identity or identity_arn to match the expected value. If the API is always setting this to the ARN, we should likely name it identity_arn and validate it via:

ValidateFunc: validateArn,

Required: true,
ForceNew: true,
},
"name": {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can validate this argument via:

ValidateFunc: validation.All(
	validation.StringLenBetween(1, 64),
	validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9\-\_]$`), "must contain only alphanumeric characters, dashes, and underscores"),
),

Reference: https://docs.aws.amazon.com/ses/latest/APIReference/API_PutIdentityPolicy.html


_, err := conn.PutIdentityPolicy(&req)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

We should return error context for operators and code maintainers, e.g.

Suggested change
return err
return fmt.Errorf("error creating SES Identity (%s) Policy: %s", identityARN, err)


_, err := conn.PutIdentityPolicy(&req)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

We should return error context here for operators and code maintainers:

Suggested change
return err
return fmt.Errorf("error updating SES Identity (%s) Policy (%s): %s", identityARN, policyName, err)


policiesOutput, err := conn.GetIdentityPolicies(&ses.GetIdentityPoliciesInput{
Identity: aws.String(arn),
PolicyNames: policyNames,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The above logic can be simplified with:

Suggested change
PolicyNames: policyNames,
PolicyNames: aws.StringSlice([]string{policyName}),

return nil
}

return err
Copy link
Contributor

Choose a reason for hiding this comment

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

We should return error context here for operators and code maintainers:

Suggested change
return err
return fmt.Errorf("error reading SES Identity (%s) Policy (%s): %s", identityARN, policyName, err)


log.Printf("[DEBUG] Deleting SES Domain Identity Policy: %s", req)
_, err := conn.DeleteIdentityPolicy(&req)
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

We should return error context here for operators and code maintainers:

Suggested change
return err
if err != nil {
return fmt.Errorf("error deleting SES Identity (%s) Policy (%s): %s", identityARN, policyName, err)
}
return nil

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsSESDomainIdentityDestroy,
Copy link
Contributor

Choose a reason for hiding this comment

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

A new CheckDestroy function should be created that verifies from the API that all SES Identity Policy configured in the test configurations are deleted. See also: https://www.terraform.io/docs/extend/testing/acceptance-tests/testcase.html#checkdestroy

{
Config: testAccAWSSESDomainIdentityConfig_withPolicy(domain),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsSESDomainIdentityExists("aws_ses_domain_identity.test"),
Copy link
Contributor

Choose a reason for hiding this comment

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

A new testAccCheckAwsSESIdentityPolicyExists() check function should be created that verifies from the API that the SES Identity Policy referenced by the given resource name was in fact properly created.

@@ -545,6 +545,7 @@ func Provider() terraform.ResourceProvider {
"aws_secretsmanager_secret_version": resourceAwsSecretsManagerSecretVersion(),
"aws_ses_active_receipt_rule_set": resourceAwsSesActiveReceiptRuleSet(),
"aws_ses_domain_identity": resourceAwsSesDomainIdentity(),
"aws_ses_domain_identity_policy": resourceAwsSesDomainIdentityPolicy(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Two larger items:

  • Given that this resource can work with both SES Identity Policies for both domains and emails, we should consider naming it aws_ses_identity_policy as there would be no benefit to having separate resources between the two. The file, resource, and resource testing function names will need to be updated to reflect this change.
  • This new resource is missing resource documentation in a new website/docs/r/ses_identity_policy.html.markdown file and a website sidebar link in website/aws.erb

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Mar 29, 2019
@asaghri
Copy link

asaghri commented Jun 11, 2019

Any update regarding this ? That would be very useful !

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Jun 11, 2019
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jun 11, 2019
@bflad bflad self-assigned this Jun 11, 2019
@bflad bflad modified the milestones: v2.15.0, v2.16.0 Jun 11, 2019
@bflad
Copy link
Contributor

bflad commented Jun 19, 2019

Since we have not heard anything from the original author regarding this, the implementation has been finished in a followup commit. The new resource is named aws_ses_identity_policy (accepting both domain and email identities) and will be released in version 2.16.0 of the Terraform AWS Provider, likely later this week.

@bflad bflad merged commit 9f81792 into hashicorp:master Jun 19, 2019
bflad added a commit that referenced this pull request Jun 19, 2019
Reference: #5128 (review)

Output from acceptance testing:

```
--- PASS: TestAccAWSSESIdentityPolicy_Identity_Email (13.57s)
--- PASS: TestAccAWSSESIdentityPolicy_basic (13.92s)
--- PASS: TestAccAWSSESIdentityPolicy_Policy (20.09s)
```
bflad added a commit that referenced this pull request Jun 19, 2019
@bflad
Copy link
Contributor

bflad commented Jun 20, 2019

This has been released in version 2.16.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Nov 3, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 3, 2019
@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Nov 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/ses Issues and PRs that pertain to the ses service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants