-
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
New resource r/aws_codestarnotification_rule #10991
New resource r/aws_codestarnotification_rule #10991
Conversation
hi @bflad, I am not sure what is the current community contribution review process, but any chance this can be reviewed soon? or am i missing something for proper PR? |
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 @spirius 👋 Thank you for submitting this. It was off to a good start! Please see the below initial feedback and let us know if you have any questions or do not have time to implement the items.
aws/provider.go
Outdated
@@ -420,6 +420,7 @@ func Provider() terraform.ResourceProvider { | |||
"aws_codebuild_webhook": resourceAwsCodeBuildWebhook(), | |||
"aws_codepipeline": resourceAwsCodePipeline(), | |||
"aws_codepipeline_webhook": resourceAwsCodePipelineWebhook(), | |||
"aws_codestarnotification_rule": resourceAwsCodeStarNotificationRule(), |
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.
Since the API Reference, Go SDK Reference, AWS CLI, and the new custom endpoint refer to the AWS service with a plural name (CodeStar Notifications), we should probably follow suit for consistency. The API also refers to these rules as "notification rules", so to prevent any future problems with other rules being introduced in this particular API, we should probably also include the longer resource naming. The recommendation here will be aws_codestarnotifications_notification_rule
even if it introduces a small stutter.
Can you please update the following:
- Function naming (e.g. find-replace
CodeStarNotificationRule
withCodeStarNotificationsNotificationRule
) - File naming, e.g.
git mv aws/resource_aws_codestarnotification_rule.go aws/resource_aws_codestarnotifications_notification_rule.go
git mv aws/resource_aws_codestarnotification_rule_test.go aws/resource_aws_codestarnotifications_notification_rule_test.go
git mv website/docs/r/codestarnotification_rule.html.markdown website/docs/r/codestarnotifications_notification_rule.html.markdown
- Resource naming and usage (e.g. find-replace
aws_codestarnotification_rule
withaws_codestarnotifications_notification_rule
)
"aws_codestarnotification_rule": resourceAwsCodeStarNotificationRule(), | |
"aws_codestarnotifications_notification_rule": resourceAwsCodeStarNotificationsNotificationRule(), |
Thanks so much.
Set: func(t interface{}) int { | ||
target := t.(map[string]interface{}) | ||
return schema.HashString(fmt.Sprintf("%s|%s", target["address"], target["type"])) | ||
}, |
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.
Our general recommendation is to omit the Set
function unless it is explicitly needed. In this case, the Terraform Plugin SDK should automatically skip the Computed: true
only attribute. 👍
} | ||
} | ||
|
||
func expandCodeStarNotificationRuleTargets(d *schema.ResourceData) []*codestarnotifications.Target { |
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.
Nit: Generally it is our practice to limit the "surface area" of input parameters for expand/flatten functions since it can be confusing when reading the calling code to know what the function actually needs from schema.ResourceData
.
func expandCodeStarNotificationRuleTargets(d *schema.ResourceData) []*codestarnotifications.Target { | |
func expandCodeStarNotificationRuleTargets(targetsData []interface{}) []*codestarnotifications.Target { |
And the calling code:
expandCodeStarNotificationRuleTargets(d.Get("target").(*schema.Set).List())
TargetAddress: getStringPtr(target, "address"), | ||
TargetType: getStringPtr(target, "type"), |
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.
There is not much usage of getStringPtr()
in this provider and we'd like to not introduce new usage (see also #5983). Since these attributes are Required and Optional+Default, its safe to access them via standard map access and type assertion:
TargetAddress: aws.String(target["address"].(string)),
TargetType: aws.String(target["type"].(string)),
In the future, the Terraform Plugin SDK will likely introduce stronger typed attribute fetching (potentially with cty
types), which is when we will likely want to re-introduce these types of abstractions.
} | ||
|
||
if v, ok := d.GetOk("tags"); ok { | ||
params.Tags = keyvaluetags.New(v) |
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 ignore AWS system tags and export as the service tagging type here (this is for future enhancements such as #7926) -- please see also the Contributing Guide section on adding resource tagging.
params.Tags = keyvaluetags.New(v) | |
params.Tags = keyvaluetags.New(v.(map[string]interface{})).IgnoreAws().CodestarnotificationsTags() |
website/aws.erb
Outdated
<a href="#">Resources</a> | ||
<ul class="nav nav-auto-expand"> | ||
<li> | ||
<a href="/docs/providers/aws/r/codestarnotification_rule.html">aws_codestarnotification_rule</a> |
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.
<a href="/docs/providers/aws/r/codestarnotification_rule.html">aws_codestarnotification_rule</a> | |
<a href="/docs/providers/aws/r/codestarnotifications_notification_rule.html">aws_codestarnotifications_notification_rule</a> |
@@ -0,0 +1,87 @@ | |||
--- | |||
subcategory: "CodeStar Notifications" |
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.
Since this PR was introduced, we have since added subcategory checking to the testing. This new subcategory can be added to the website/allowed-subcategories.txt
file to prevent the check from failing. 👍
* `resource` - (Required) The ARN of the resource to associate with the notification rule. | ||
* `status` - (Optional) The status of the notification rule. Possible balues are `ENABLED` and `DISABLED`, default is `ENABLED`. | ||
* `tags` - (Optional) A mapping of tags to assign to the resource. | ||
* `target` - (Optional) A `target` block. Can be specified multiple times. |
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.
It might be good to include a note here about the target requirement on creation:
* `target` - (Optional) A `target` block. Can be specified multiple times. | |
* `target` - (Optional) Configuration blocks containing notification target information. Can be specified multiple times. At least one target must be specified on creation. |
An `target` block supports the following arguments: | ||
|
||
* `address` - (Required) The ARN of noitifaction rule target, typically SNS topic. | ||
* `type` - (Required) The type of the notification target. Default value is `SNS`. |
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.
* `type` - (Required) The type of the notification target. Default value is `SNS`. | |
* `type` - (Optional) The type of the notification target. Default value is `SNS`. |
|
||
An `target` block supports the following arguments: | ||
|
||
* `address` - (Required) The ARN of noitifaction rule target, typically SNS topic. |
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.
Typo 😎
* `address` - (Required) The ARN of noitifaction rule target, typically SNS topic. | |
* `address` - (Required) The ARN of notification rule target. For example, a SNS Topic ARN. |
@bflad will this new resource “code star notification rule” also allow to be applied to CodeBuild to trigger an SNS topic? Just wanted to confirm, as I’m working on an AMI pipeline for AWS as we speak and need this notification rule in order to enable EBS encryption in case CodeBuild fails or stops. And when is the expected ETA we can see this in the latest Terraform minor version update? |
+1 |
1e65749
to
b85dbec
Compare
b85dbec
to
65f85e4
Compare
hi @bflad, finally found some free time to finalize the PR Acceptance test results:
|
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 work, @spirius, let's get it out! 🚀
Output from acceptance testing:
--- PASS: TestAccAWSCodeStarNotificationsNotificationRule_Tags (23.32s)
--- PASS: TestAccAWSCodeStarNotificationsNotificationRule_Targets (24.19s)
--- PASS: TestAccAWSCodeStarNotificationsNotificationRule_Basic (28.90s)
--- PASS: TestAccAWSCodeStarNotificationsNotificationRule_EventTypeIds (40.63s)
--- PASS: TestAccAWSCodeStarNotificationsNotificationRule_Status (41.29s)
|
||
targets := removedTargets.List() | ||
|
||
err := resource.Retry(time.Duration(5)*time.Second, func() *resource.RetryError { |
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.
This logic may be problematic in practice (#7873 / hashicorp/terraform-plugin-sdk#199), however it is more valuable to get this new resource out so folks can start trying it.
This has been released in version 2.49.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! |
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! |
Community Note
Closes #10792
Output from acceptance testing:
Notes
There are two types of resources involved in codestar notifications - rules and targets. Unfortunately targets do not have dedicated creation API, they are implicitly created while creating rules or when new subscription is added. So there is no explicit control over targets and therefore this implementation only introduces one new resource (
aws_codestarnotification_rule
), which maintains targets state as well. It tries to remove targets when rule is modified or removed, but targets that are attached to multiple rules will not be removed.References