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

Refactor Pinpoint application resource to use keyvaluetags package #11368

Merged
merged 4 commits into from
Jan 10, 2020

Conversation

ewbankkit
Copy link
Contributor

@ewbankkit ewbankkit commented Dec 19, 2019

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates #10688.

Release note for CHANGELOG:

resource/aws_pinpoint_app: Add plan-time validation for `limit` configuration block's `daily`, `maximum_duration`, `messages_per_second` and `total` arguments

Output from acceptance testing:

# Resource in supported region:
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSPinpointApp_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSPinpointApp_ -timeout 120m
=== RUN   TestAccAWSPinpointApp_basic
=== PAUSE TestAccAWSPinpointApp_basic
=== RUN   TestAccAWSPinpointApp_CampaignHookLambda
=== PAUSE TestAccAWSPinpointApp_CampaignHookLambda
=== RUN   TestAccAWSPinpointApp_Limits
=== PAUSE TestAccAWSPinpointApp_Limits
=== RUN   TestAccAWSPinpointApp_QuietTime
=== PAUSE TestAccAWSPinpointApp_QuietTime
=== RUN   TestAccAWSPinpointApp_Tags
=== PAUSE TestAccAWSPinpointApp_Tags
=== CONT  TestAccAWSPinpointApp_basic
=== CONT  TestAccAWSPinpointApp_Tags
=== CONT  TestAccAWSPinpointApp_QuietTime
=== CONT  TestAccAWSPinpointApp_Limits
=== CONT  TestAccAWSPinpointApp_CampaignHookLambda
--- PASS: TestAccAWSPinpointApp_QuietTime (24.91s)
--- PASS: TestAccAWSPinpointApp_Limits (25.52s)
--- PASS: TestAccAWSPinpointApp_basic (25.77s)
--- PASS: TestAccAWSPinpointApp_CampaignHookLambda (49.29s)
--- PASS: TestAccAWSPinpointApp_Tags (58.52s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	58.586s
# Test in unsupported region:
$ AWS_DEFAULT_REGION=us-east-2 make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSPinpointApp_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSPinpointApp_ -timeout 120m
=== RUN   TestAccAWSPinpointApp_basic
=== PAUSE TestAccAWSPinpointApp_basic
=== RUN   TestAccAWSPinpointApp_CampaignHookLambda
=== PAUSE TestAccAWSPinpointApp_CampaignHookLambda
=== RUN   TestAccAWSPinpointApp_Limits
=== PAUSE TestAccAWSPinpointApp_Limits
=== RUN   TestAccAWSPinpointApp_QuietTime
=== PAUSE TestAccAWSPinpointApp_QuietTime
=== RUN   TestAccAWSPinpointApp_Tags
=== PAUSE TestAccAWSPinpointApp_Tags
=== CONT  TestAccAWSPinpointApp_basic
=== CONT  TestAccAWSPinpointApp_QuietTime
=== CONT  TestAccAWSPinpointApp_Tags
=== CONT  TestAccAWSPinpointApp_Limits
=== CONT  TestAccAWSPinpointApp_CampaignHookLambda
--- SKIP: TestAccAWSPinpointApp_basic (1.94s)
    provider_test.go:349: skipping tests; region us-east-2 does not support pinpoint service
--- SKIP: TestAccAWSPinpointApp_Limits (1.94s)
    provider_test.go:349: skipping tests; region us-east-2 does not support pinpoint service
--- SKIP: TestAccAWSPinpointApp_Tags (1.94s)
    provider_test.go:349: skipping tests; region us-east-2 does not support pinpoint service
--- SKIP: TestAccAWSPinpointApp_CampaignHookLambda (1.94s)
    provider_test.go:349: skipping tests; region us-east-2 does not support pinpoint service
--- SKIP: TestAccAWSPinpointApp_QuietTime (1.96s)
    provider_test.go:349: skipping tests; region us-east-2 does not support pinpoint service
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	1.989s
# Test sweeper:
$ TEST=./aws SWEEP=us-east-1 SWEEPARGS=-sweep-run=aws_pinpoint_app make sweep
WARNING: This will destroy infrastructure. Use only in development accounts.
go test ./aws -v -sweep=us-east-1 -sweep-run=aws_pinpoint_app
2020/01/07 12:25:34 [DEBUG] Running Sweepers for region (us-east-1):
2020/01/07 12:25:34 [DEBUG] Running Sweeper (aws_pinpoint_app) in region (us-east-1)
2020/01/07 12:25:34 [INFO] Building AWS auth structure
2020/01/07 12:25:34 [INFO] Setting AWS metadata API timeout to 100ms
2020/01/07 12:25:35 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
2020/01/07 12:25:35 [INFO] AWS Auth provider used: "EnvProvider"
2020/01/07 12:25:35 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/01/07 12:25:36 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/01/07 12:25:37 [INFO] Deleting Pinpoint app terraform-test-pinpointapp-quiet
2020/01/07 12:25:37 [INFO] Deleting Pinpoint app tf-k9xafc8yk1
2020/01/07 12:25:37 [INFO] Deleting Pinpoint app terraform-20200107154813751800000001
2020/01/07 12:25:37 Sweeper Tests ran successfully:
	- aws_pinpoint_app
ok  	github.com/terraform-providers/terraform-provider-aws/aws	3.526s
# S3 bucket acceptance that was edited:
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSS3Bucket_acceleration'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSS3Bucket_acceleration -timeout 120m
=== RUN   TestAccAWSS3Bucket_acceleration
=== PAUSE TestAccAWSS3Bucket_acceleration
=== CONT  TestAccAWSS3Bucket_acceleration
--- PASS: TestAccAWSS3Bucket_acceleration (74.88s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	74.909s

@ewbankkit ewbankkit requested a review from a team December 19, 2019 15:39
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. needs-triage Waiting for first response or review from a maintainer. service/pinpoint Issues and PRs that pertain to the pinpoint service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Dec 19, 2019
@ewbankkit
Copy link
Contributor Author

Waiting for merge of #11352 to add the custom transformation for Pinpoint TagResource() method.

@@ -87,20 +88,24 @@ func resourceAwsPinpointApp() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"daily": {
Type: schema.TypeInt,
Optional: true,
Type: schema.TypeInt,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add validations as described here for CampaignLimits.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -43,23 +90,18 @@ func TestAccAWSPinpointApp_basic(t *testing.T) {
}

func TestAccAWSPinpointApp_CampaignHookLambda(t *testing.T) {
oldDefaultRegion := os.Getenv("AWS_DEFAULT_REGION")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pinpoint is now available in regions other than us-east-1.

handler = "lambdapinpoint.handler"
runtime = "nodejs8.10"
runtime = "nodejs12.x"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upgrade Nodejs runtime version - #11514.

@@ -267,76 +293,69 @@ EOF
}

data "aws_caller_identity" "aws" {}
data "aws_region" "current" {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Region agnostic - #8316.

@ewbankkit

This comment has been minimized.

daily = 3
maximum_duration = 600
messages_per_second = 50
total = 100
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change total to 100 else we get an error like

--- FAIL: TestAccAWSPinpointApp_Limits (10.75s)
    testing.go:640: Step 0 error: errors during apply:
        
        Error: BadRequestException: Campaign Total limit needs to be less than or equal to 100. Value entered: 500
        	status code: 400, request id: 8ce2c134-a525-45cd-b9b4-f5c54f589e5a
        
          on /var/folders/4j/lf5jdq5j4y91g80ytf6qzjwmk6drp5/T/tf-test284836860/main.tf line 6:
          (source code not available)

@ghost ghost added the service/s3 Issues and PRs that pertain to the s3 service. label Jan 7, 2020
@@ -330,10 +330,23 @@ func testAccEC2VPCOnlyPreCheck(t *testing.T) {
}
}

func testAccHasServicePreCheck(service string, t *testing.T) {
func testAccPartitionHasServicePreCheck(serviceId string, t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rename to better explain purpose.

}
}

func testAccRegionHasServicePreCheck(serviceId string, t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checks that the acceptance test regions supports the specified service.

Copy link
Member

Choose a reason for hiding this comment

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

This addition is okay for this and other particular cases, but experience over time has shown the AWS Go SDK endpoints information continually being out of date for some services, which is why we do not use it in many places. We'll always want to prefer behavioral checks (attempting to call an API) over using the endpoint information. 👍 I will add a comment to this function on merge to note that preference.


campaign_hook {
lambda_function_name = "${aws_lambda_function.test.arn}"
mode = "DELIVERY"
}

depends_on = ["aws_lambda_permission.test"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prevents random test failures.

Copy link
Member

Choose a reason for hiding this comment

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

❤️ Thanks!

@ewbankkit ewbankkit changed the title [WIP] Refactor Pinpoint application resource to use keyvaluetags package Refactor Pinpoint application resource to use keyvaluetags package Jan 7, 2020
@ewbankkit
Copy link
Contributor Author

Removing WIP.
Ready for review.


resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccRegionHasServicePreCheck("pinpoint", t) },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to explicitly pre-check that the test region has the Pinpoint service instead of just failing the test as the Pinpoint APIs hang in unsupported regions rather than return errors.

Copy link
Member

@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.

LGTM, thanks @ewbankkit 🚀

Output from acceptance testing:

--- PASS: TestAccAWSPinpointApp_basic (15.45s)
--- PASS: TestAccAWSPinpointApp_CampaignHookLambda (47.58s)
--- PASS: TestAccAWSPinpointApp_Limits (22.38s)
--- PASS: TestAccAWSPinpointApp_QuietTime (19.65s)
--- PASS: TestAccAWSPinpointApp_Tags (47.07s)

--- PASS: TestAccAWSS3Bucket_acceleration (38.79s)

}
}

func testAccRegionHasServicePreCheck(serviceId string, t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

This addition is okay for this and other particular cases, but experience over time has shown the AWS Go SDK endpoints information continually being out of date for some services, which is why we do not use it in many places. We'll always want to prefer behavioral checks (attempting to call an API) over using the endpoint information. 👍 I will add a comment to this function on merge to note that preference.

@@ -87,20 +88,24 @@ func resourceAwsPinpointApp() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"daily": {
Type: schema.TypeInt,
Optional: true,
Type: schema.TypeInt,
Copy link
Member

Choose a reason for hiding this comment

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

👍


campaign_hook {
lambda_function_name = "${aws_lambda_function.test.arn}"
mode = "DELIVERY"
}

depends_on = ["aws_lambda_permission.test"]
Copy link
Member

Choose a reason for hiding this comment

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

❤️ Thanks!

@bflad bflad merged commit bba2d08 into hashicorp:master Jan 10, 2020
@bflad bflad added this to the v2.45.0 milestone Jan 10, 2020
@bflad bflad added technical-debt Addresses areas of the codebase that need refactoring or redesign. enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Jan 10, 2020
bflad added a commit that referenced this pull request Jan 10, 2020
@ewbankkit ewbankkit deleted the pinpoint-keyvaluetags branch January 10, 2020 19:28
@ghost
Copy link

ghost commented Jan 17, 2020

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

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Mar 27, 2020

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 Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/pinpoint Issues and PRs that pertain to the pinpoint service. service/s3 Issues and PRs that pertain to the s3 service. size/XL Managed by automation to categorize the size of a PR. technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants