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

New resource: aws_pinpoint_app #5956

Merged
merged 14 commits into from
Sep 28, 2018

Conversation

marcoreni
Copy link
Contributor

This is the first step to address #4990 .

More will (slowly) follow.

Changes proposed in this pull request:

  • New resource aws_pinpoint_app with related acceptance tests and docs

NOTE: cloudwatch_metrics_enabled is currently not returned by GetApplicationSettings requests so it's not currently handled inside the resource.

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSPinpointApp'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSPinpointApp -timeout 120m
=== RUN   TestAccAWSPinpointApp_basic
--- PASS: TestAccAWSPinpointApp_basic (19.40s)
=== RUN   TestAccAWSPinpointApp_CampaignHookLambda
--- PASS: TestAccAWSPinpointApp_CampaignHookLambda (41.61s)
=== RUN   TestAccAWSPinpointApp_Limits
--- PASS: TestAccAWSPinpointApp_Limits (17.05s)
=== RUN   TestAccAWSPinpointApp_QuietTime
--- PASS: TestAccAWSPinpointApp_QuietTime (24.47s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       103.733s

@ghost ghost added size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Sep 21, 2018
@bflad bflad added the service/pinpoint Issues and PRs that pertain to the pinpoint service. label Sep 24, 2018
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 @marcoreni! Thanks for submitting this -- its off to a good start. Please see the below for initial comments. Let us know if you have any questions or do not have time to implement the feedback. 😄

// Default: false,
//},
"campaign_hook": {
Type: schema.TypeSet,
Copy link
Contributor

Choose a reason for hiding this comment

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

We prefer Type: schema.TypeList for MaxItems: 1 attributes, which allows dropping `Set, simplification of the attribute testing, and easier future maintenance. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fd77a5b

},
},
"limits": {
Type: schema.TypeSet,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. We prefer Type: schema.TypeList for MaxItems: 1 attributes, which allows dropping `Set, simplification of the attribute testing, and easier future maintenance. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fd77a5b

},
},
"quiet_time": {
Type: schema.TypeSet,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. We prefer Type: schema.TypeList for MaxItems: 1 attributes, which allows dropping `Set, simplification of the attribute testing, and easier future maintenance. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fd77a5b


output, err := pinpointconn.CreateApp(req)
if err != nil {
return fmt.Errorf("[ERROR] creating Pinpoint app: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Using the hclog style [ERROR] can be replaced with the human readable error as it will be placed in the middle of the error messaging from Terraform to operators

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0b9d8ff

aws/resource_aws_pinpoint_app.go Show resolved Hide resolved

m := map[string]interface{}{}

if ch.LambdaFunctionName != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the nil checks by using the AWS Go SDK helpers here, e.g.

m["lambda_function_name"] = aws.StringValue(ch.LambdaFunctionName)

Especially for ch.Mode below, which does not need the != "" check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been struggling with this while testing the resource. The issue I've encountered is that GetApplicationSettings returns an empty object for campaign_hook, limits and quiet_time even if none of the children attributes is set.

In this case, if I used

m["lambda_function_name"] = aws.StringValue(ch.LambdaFunctionName)
m["mode"] = aws.StringValue(ch.Mode)
m["web_url"] = aws.StringValue(ch.WebUrl)

I'd get a map filled with empty values, but that would cause failures on the state diff (for example, on the _basic test):

        DIFF:

        UPDATE: aws_pinpoint_app.test_app
          campaign_hook.#: "1" => "0"

        STATE:

        aws_pinpoint_app.test_app:
          ID = ff3857dd45734e7ab07d9cb5141f0221
          provider = provider.aws
          application_id = ff3857dd45734e7ab07d9cb5141f0221
          campaign_hook.# = 1
          campaign_hook.0.lambda_function_name =
          campaign_hook.0.mode =
          campaign_hook.0.web_url =
          name = terraform-20180928131703355600000001

Any suggestions on how to handle this scenario?

Copy link
Contributor

Choose a reason for hiding this comment

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

Great question! We'll be looking to come up with a better solution to this problem in the future, but for now, you can add the following DiffSuppressFunc to the campaign_hook attribute that ignores that the API is always returning the "container" attribute:

DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
  if old == "1" && new == "0" {
    return true
  }
  return false
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Totally missed DiffSuppressFunc while exploring the code looking for a workaround :D Fixed in 4d39884

d.Set("name", app.ApplicationResponse.Name)
d.Set("application_id", app.ApplicationResponse.Id)

d.Set("campaign_hook", flattenCampaignHook(settings.ApplicationSettingsResource.CampaignHook))
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 error check d.Set() when attempting to set more complex types like lists and maps to ensure they are properly being read into the Terraform state:

if err := d.Set("campaign_hook", flattenCampaignHook(settings.ApplicationSettingsResource.CampaignHook)); err != nil {
  return fmt.Errorf("error setting campaign_hook: %s", err)
}
if err := d.Set("limits", flattenCampaignLimits(settings.ApplicationSettingsResource.Limits)); err != nil {
  return fmt.Errorf("error setting limits: %s", err)
}
if err := d.Set("quiet_time", flattenQuietTime(settings.ApplicationSettingsResource.QuietTime)); err != nil {
  return fmt.Errorf("error setting campaign_hook: %s", err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1ea7cda

m := map[string]interface{}{}

if qt.End != nil {
m["end"] = qt.End
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this would be found by the d.Set() error checking, but this should be converting the string pointer to a string:

m["end"] = aws.StringValue(qt.End)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ea1e963


## Import

CodeBuild Project can be imported using the `application-id`, e.g.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy-paste typo (CodeBuild Project) 😎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 96756bf

aws/resource_aws_pinpoint_app_test.go Show resolved Hide resolved
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Sep 28, 2018
@bflad
Copy link
Contributor

bflad commented Sep 28, 2018

I dropped a note about the DiffSuppressFunc which should help out with the one problem you're seeing and looks like you're working through everything else already -- thanks so much! Let me know if there's anything else and when you're done. 😄

added DiffSuppressFunc to work around AWS returning empty objects
@marcoreni
Copy link
Contributor Author

Hey @bflad , thanks for the thorough review and all the inputs!

I applied all the requested changes. I committed them separately to ease the review. If you think it's better, I can squash them.

Regarding DiffSuppressFunc I decided to repeat it on all the attributes to make it more explicit to a future reader.

Let me know if there's anything else to be improved :)

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.

Looks great, @marcoreni! 🚀

--- PASS: TestAccAWSPinpointApp_basic (9.91s)
--- PASS: TestAccAWSPinpointApp_QuietTime (10.30s)
--- PASS: TestAccAWSPinpointApp_Limits (10.49s)
--- PASS: TestAccAWSPinpointApp_CampaignHookLambda (26.57s)

@bflad bflad added this to the v1.39.0 milestone Sep 28, 2018
@bflad bflad merged commit a75fc98 into hashicorp:master Sep 28, 2018
@marcoreni marcoreni deleted the feature/4990_pinpoint_app branch September 28, 2018 15:44
bflad added a commit that referenced this pull request Sep 28, 2018
@marcoreni marcoreni mentioned this pull request Oct 1, 2018
@ghost
Copy link

ghost commented Oct 3, 2018

This has been released in version 1.39.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "aws" {
	version = "~> 1.39.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Apr 3, 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 Apr 3, 2020
@breathingdust breathingdust removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. service/pinpoint Issues and PRs that pertain to the pinpoint service. size/XL Managed by automation to categorize the size of a PR. 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.

3 participants