-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Conversation
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.
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. 😄
aws/resource_aws_pinpoint_app.go
Outdated
// Default: false, | ||
//}, | ||
"campaign_hook": { | ||
Type: schema.TypeSet, |
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.
We prefer Type: schema.TypeList
for MaxItems: 1
attributes, which allows dropping `Set, simplification of the attribute testing, and easier future maintenance. 👍
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.
Fixed in fd77a5b
aws/resource_aws_pinpoint_app.go
Outdated
}, | ||
}, | ||
"limits": { | ||
Type: schema.TypeSet, |
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.
Same here. We prefer Type: schema.TypeList
for MaxItems: 1
attributes, which allows dropping `Set, simplification of the attribute testing, and easier future maintenance. 👍
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.
Fixed in fd77a5b
aws/resource_aws_pinpoint_app.go
Outdated
}, | ||
}, | ||
"quiet_time": { | ||
Type: schema.TypeSet, |
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.
Same here. We prefer Type: schema.TypeList
for MaxItems: 1
attributes, which allows dropping `Set, simplification of the attribute testing, and easier future maintenance. 👍
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.
Fixed in fd77a5b
aws/resource_aws_pinpoint_app.go
Outdated
|
||
output, err := pinpointconn.CreateApp(req) | ||
if err != nil { | ||
return fmt.Errorf("[ERROR] creating Pinpoint app: %s", err) |
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.
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
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.
Fixed in 0b9d8ff
aws/resource_aws_pinpoint_app.go
Outdated
|
||
m := map[string]interface{}{} | ||
|
||
if ch.LambdaFunctionName != nil { |
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.
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.
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.
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?
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.
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
},
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.
Thanks! Totally missed DiffSuppressFunc
while exploring the code looking for a workaround :D Fixed in 4d39884
aws/resource_aws_pinpoint_app.go
Outdated
d.Set("name", app.ApplicationResponse.Name) | ||
d.Set("application_id", app.ApplicationResponse.Id) | ||
|
||
d.Set("campaign_hook", flattenCampaignHook(settings.ApplicationSettingsResource.CampaignHook)) |
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.
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)
}
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.
Fixed in 1ea7cda
aws/resource_aws_pinpoint_app.go
Outdated
m := map[string]interface{}{} | ||
|
||
if qt.End != nil { | ||
m["end"] = qt.End |
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.
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)
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.
Fixed in ea1e963
website/docs/r/pinpoint_app.markdown
Outdated
|
||
## Import | ||
|
||
CodeBuild Project can be imported using the `application-id`, e.g. |
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.
Copy-paste typo (CodeBuild Project
) 😎
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.
Fixed in 96756bf
…turn on missing resource
I dropped a note about the |
added DiffSuppressFunc to work around AWS returning empty objects
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 Let me know if there's anything else to be improved :) |
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.
Looks great, @marcoreni! 🚀
--- PASS: TestAccAWSPinpointApp_basic (9.91s)
--- PASS: TestAccAWSPinpointApp_QuietTime (10.30s)
--- PASS: TestAccAWSPinpointApp_Limits (10.49s)
--- PASS: TestAccAWSPinpointApp_CampaignHookLambda (26.57s)
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 ... |
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! |
This is the first step to address #4990 .
More will (slowly) follow.
Changes proposed in this pull request:
NOTE:
cloudwatch_metrics_enabled
is currently not returned byGetApplicationSettings
requests so it's not currently handled inside the resource.Output from acceptance testing: