-
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
Add resource aws_cloudwatch_event_bus #10256
Add resource aws_cloudwatch_event_bus #10256
Conversation
693b51e
to
a549a0f
Compare
Hi, What is the current state of this? Very keen to try it out - thanks for the feature! Cheers |
ac0cd8a
to
042aec0
Compare
@kurtmaile conflicts are resolved. It's ready for review. |
Great thanks sorry for delay getting back - seems to have passed and is merged. Assume then its available in the next release? Cheers! |
Anything blocking this besides the merge conflicts? Can I help push this forward somehow? |
aws/validators.go
Outdated
errors = append(errors, fmt.Errorf("%q cannot be less than 1 character: %q", k, value)) | ||
} else if len(value) > 256 { | ||
errors = append(errors, fmt.Errorf("%q cannot be longer than 256 characters: %q", k, value)) | ||
} else if value == "default" { |
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 tried this PR and used it to specify the event_bus_name
attribute on aws_cloudwatch_event_rule
and aws_cloudwatch_event_target
but this check for default
leads to an issue.
The event_bus_name
default
does not need to be specified but when you omit this it will be added to the statefile because the AWS API contains it in the response. This will then lead to a change on the next apply as it would be changed from default
to null
.
As this validation forbids to specify default
it currently is not working.
I suggest to have different validations for the event_bus_name
attribute on aws_cloudwatch_event_rule
and aws_cloudwatch_event_target
and for the name
attribute on the aws_cloudwatch_event_bus
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.
Good catch! I would leave the current validation though. The issue was that event_bus_name
in the statefile was updated with a value from AWS API. I think event_bus_name
is kinda part of the identification for aws_cloudwatch_event_rule
and aws_cloudwatch_event_target
, so it shouldn't be updated. At least that's how I fixed now. Otherwise I think that event_bus_name
should be a required attribute. But I prefer as an optional attribute to not break current configurations. The idea is that we should always omit event_bus_name
if we want to use the default
event bus.
Also I changed the import for aws_cloudwatch_event_rule
and aws_cloudwatch_event_target
. I use #
instead of /
, eg event-bus-name#rule-name#target-id
or rule-name#target-id
for the default event bus, because an event bus name can contain /
, it's possible to detect such names, since all of them start with aws.partner/
. Not sure, if it's better to use /
or #
for imports here 🤔
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 reverted some changes, so #
is not used to import aws_cloudwatch_event_rule
and aws_cloudwatch_event_target
042aec0
to
d47b9a4
Compare
Hi, Any update in this one? EventBridge support would be awesome, and it looks like the PR is in a pretty good state - any chance of a (rough) ETA on this getting in to a release? |
@alexanderkalach As it will not be possible to create partner event buses (you have to be a SaaS provider, not just a regular AWS customer) with Terraform (currently) I suggest removing the |
d47b9a4
to
8295926
Compare
@ewbankkit good point, thanks! I updated the PR. |
} | ||
|
||
output, err := conn.DescribeEventBus(input) | ||
if err != 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.
We need to handle the case where the resource has been deleted outside Terraform by checking for a NotFound error, maybe:
if isAWSErr(err, events.ErrCodeResourceNotFoundException, "") {
log.Printf("[WARN] CloudWatch Event Bus (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
other errors can be wrapped:
if err != nil {
return fmt.Errorf("error reading CloudWatch Event Bus: %s", err)
}
This can be tested by adding a _disappears
test case, for example:
https://github.com/terraform-providers/terraform-provider-aws/blob/4875ae5fef0990f4a7e3768c81fcc732b90e0f13/aws/resource_aws_cloudwatch_log_stream_test.go#L33-L52
return nil | ||
} | ||
|
||
func testAccCheckCloudWatchEventBusExists(n string) resource.TestCheckFunc { |
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.
May want to add a 2nd parameter v *events.DescribeEventBusOutput
and set it (after the resp == nil
check):
*v = *resp
func init() { | ||
resource.AddTestSweepers("aws_cloudwatch_event_bus", &resource.Sweeper{ | ||
Name: "aws_cloudwatch_event_bus", | ||
F: testSweepCloudWatchEventBuses, |
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 looks like an event bus can't be deleted if it has associated rules or targets so we'll need to add
Dependencies: []string{...},
here.
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: validateCloudWatchEventBusName, |
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.
Maybe don't validate event_bus_name
here as that would exclude specifying default
which is a valid event bus name when manipulating events. We'll then need to suppress the difference between ""
and "default"
.
id := aws.StringValue(input.Name) | ||
eventBusName := aws.StringValue(input.EventBusName) | ||
if len(eventBusName) > 0 { | ||
id = eventBusName + "-" + id |
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 suggest using /
as the separator as it's not a valid event bus name character while -
is.
Also don't prefix the name if it's default
(see comment above).
@@ -255,6 +262,10 @@ func resourceAwsCloudWatchEventTargetCreate(d *schema.ResourceData, meta interfa | |||
} | |||
|
|||
id := rule + "-" + targetId | |||
eventBusName := aws.StringValue(input.EventBusName) | |||
if len(eventBusName) > 0 { |
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 as for aws_cloudwatch_event_rule
.
aws/validators.go
Outdated
@@ -2407,3 +2407,28 @@ func validateRoute53ResolverName(v interface{}, k string) (ws []string, errors [ | |||
|
|||
return | |||
} | |||
|
|||
func validateCloudWatchEventBusName(v interface{}, k string) (ws []string, errors []error) { |
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.
Could be simplified (using approach suggested in #8424) to
var validateCloudWatchEventBusName = validation.All(
validation.StringLenBetween(1, 256),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9._\-]+$`), ""),
StringNotInSlice([]string{"default"}, false), // To implement :)
)
@alexanderkalach Great work. I left some additional comments. The base |
8295926
to
6fb8fc9
Compare
@ewbankkit Thank you for the review. I updated the PR. Also removed the code related to changes of |
|
||
func TestAccAWSCloudWatchEventBus_basic(t *testing.T) { | ||
var eventBusOutput cloudwatchevents.DescribeEventBusOutput | ||
busName := acctest.RandString(15) |
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.
Minor thing: Prefer acctest.RandomWithPrefix("tf-acc-test")
so that we can easily distinguish provider acceptance resources in the AWS console.
_, err := conn.DeleteEventBus(&cloudwatchevents.DeleteEventBusInput{ | ||
Name: aws.String(d.Id()), | ||
}) | ||
if err != 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.
Please add the "resource not found" checking you now have in resourceAwsCloudWatchEventBusRead()
here also.
Thanks.
@alexanderkalach Thank for addressing my previous comments. % make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudWatchEventBus_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSCloudWatchEventBus_ -timeout 120m
=== RUN TestAccAWSCloudWatchEventBus_basic
=== PAUSE TestAccAWSCloudWatchEventBus_basic
=== RUN TestAccAWSCloudWatchEventBus_disappears
=== PAUSE TestAccAWSCloudWatchEventBus_disappears
=== CONT TestAccAWSCloudWatchEventBus_basic
=== CONT TestAccAWSCloudWatchEventBus_disappears
--- PASS: TestAccAWSCloudWatchEventBus_disappears (19.68s)
--- PASS: TestAccAWSCloudWatchEventBus_basic (40.30s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 41.534s
% TEST=./aws SWEEP=us-west-2 SWEEPARGS=-sweep-run=aws_cloudwatch_event_bus make sweep
WARNING: This will destroy infrastructure. Use only in development accounts.
go test ./aws -v -sweep=us-west-2 -sweep-run=aws_cloudwatch_event_bus -timeout 60m
2020/02/24 09:26:37 [DEBUG] Running Sweepers for region (us-west-2):
2020/02/24 09:26:37 [DEBUG] Sweeper (aws_cloudwatch_event_rule) has dependency (aws_cloudwatch_event_target), running..
2020/02/24 09:26:37 [DEBUG] Running Sweeper (aws_cloudwatch_event_target) in region (us-west-2)
2020/02/24 09:26:37 [INFO] Building AWS auth structure
2020/02/24 09:26:37 [INFO] Setting AWS metadata API timeout to 100ms
2020/02/24 09:26:39 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
2020/02/24 09:26:39 [INFO] AWS Auth provider used: "EnvProvider"
2020/02/24 09:26:39 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/02/24 09:26:39 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/02/24 09:26:40 [DEBUG] Running Sweeper (aws_cloudwatch_event_rule) in region (us-west-2)
2020/02/24 09:26:40 [INFO] Building AWS auth structure
2020/02/24 09:26:40 [INFO] Setting AWS metadata API timeout to 100ms
2020/02/24 09:26:42 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
2020/02/24 09:26:42 [INFO] AWS Auth provider used: "EnvProvider"
2020/02/24 09:26:42 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/02/24 09:26:42 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/02/24 09:26:43 [DEBUG] No CloudWatch Event Rules to sweep
2020/02/24 09:26:43 [DEBUG] Sweeper (aws_cloudwatch_event_target) already ran in region (us-west-2)
2020/02/24 09:26:43 [DEBUG] Sweeper (aws_cloudwatch_event_bus) has dependency (aws_cloudwatch_event_rule), running..
2020/02/24 09:26:43 [DEBUG] Sweeper (aws_cloudwatch_event_rule) has dependency (aws_cloudwatch_event_target), running..
2020/02/24 09:26:43 [DEBUG] Sweeper (aws_cloudwatch_event_target) already ran in region (us-west-2)
2020/02/24 09:26:43 [DEBUG] Sweeper (aws_cloudwatch_event_rule) already ran in region (us-west-2)
2020/02/24 09:26:43 [DEBUG] Sweeper (aws_cloudwatch_event_bus) has dependency (aws_cloudwatch_event_target), running..
2020/02/24 09:26:43 [DEBUG] Sweeper (aws_cloudwatch_event_target) already ran in region (us-west-2)
2020/02/24 09:26:43 [DEBUG] Running Sweeper (aws_cloudwatch_event_bus) in region (us-west-2)
2020/02/24 09:26:43 [INFO] Building AWS auth structure
2020/02/24 09:26:43 [INFO] Setting AWS metadata API timeout to 100ms
2020/02/24 09:26:45 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
2020/02/24 09:26:45 [INFO] AWS Auth provider used: "EnvProvider"
2020/02/24 09:26:45 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/02/24 09:26:45 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/02/24 09:26:46 Sweeper Tests ran successfully:
- aws_cloudwatch_event_target
- aws_cloudwatch_event_rule
- aws_cloudwatch_event_bus
ok github.com/terraform-providers/terraform-provider-aws/aws 10.303s |
6fb8fc9
to
f1dd310
Compare
@ewbankkit I updated the PR according to the last comments. Thanks. |
LGTM. % make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudWatchEventBus_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSCloudWatchEventBus_ -timeout 120m
=== RUN TestAccAWSCloudWatchEventBus_basic
=== PAUSE TestAccAWSCloudWatchEventBus_basic
=== RUN TestAccAWSCloudWatchEventBus_disappears
=== PAUSE TestAccAWSCloudWatchEventBus_disappears
=== CONT TestAccAWSCloudWatchEventBus_basic
=== CONT TestAccAWSCloudWatchEventBus_disappears
--- PASS: TestAccAWSCloudWatchEventBus_disappears (17.49s)
--- PASS: TestAccAWSCloudWatchEventBus_basic (36.14s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 37.530s |
Any update on the current state of this - being able to define non-default event busses in AWS via Terraform would be extremely helpful. |
Wanted to check in a month after the last comment, has there been any update on getting this merged in? We are currently having to use a combination of cloud formation and terraform in order to manage EventBridge resources |
I've created PRs for aws_cloudwatch_event_rule and aws_cloudwatch_event_target. It should be enough to close #9330 |
@alexanderkalach Thanks for the additional PRs. |
Notification of Recent and Upcoming Changes to ContributionsThank you for this contribution! There have been a few recent development changes that affect this pull request. We apologize for the inconvenience, especially if there have been long review delays up until now. Please note that this is automated message from an unmonitored account. See the FAQ for additional information on the maintainer team and review prioritization. If you are unable to complete these updates, please leave a comment for the community and maintainers so someone can potentially continue the work. The maintainers will encourage other contributors to use the existing contribution as the base for additional changes as appropriate. Otherwise, contributions that do not receive updated code or comments from the original contributor may be closed in the future so the maintainers can focus on active items. For the most up to date information about Terraform AWS Provider development, see the Contributing Guide. Additional technical debt changes can be tracked with the As part of updating a pull request with these changes, the most current unit testing and linting will run. These may report issues that were not previously reported. Terraform 0.12 SyntaxReference: #8950 Version 3 and later of the Terraform AWS Provider, which all existing contributions would potentially be added, only supports Terraform 0.12 and later. Certain syntax elements of Terraform 0.11 and earlier show deprecation warnings during runs with Terraform 0.12. Documentation and test configurations, such as those including deprecated string interpolations ( Action Required: Terraform Plugin SDK Version 2Reference: #14551 The Terraform AWS Provider has been upgraded to the latest version of the Terraform Plugin SDK. Generally, most changes to contributions should only involve updating Go import paths in source code files. Please see the referenced issue for additional information. Removal of website/aws.erb FileReference: #14712 Any changes to the Upcoming Change of Git Branch NamingReference: #14292 Development environments will need their upstream Git branch updated from Upcoming Change of GitHub OrganizationReference: #14715 This repository will be migrating from https://github.com/terraform-providers/terraform-provider-aws to https://github.com/hashicorp/terraform-provider-aws. No practitioner or developer action is anticipated and most GitHub functionality will automatically redirect to the new location. Go import paths including |
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.
LGTM 🚀
--- PASS: TestAccAWSCloudWatchEventBus_default (17.28s)
--- PASS: TestAccAWSCloudWatchEventBus_disappears (46.43s)
--- PASS: TestAccAWSCloudWatchEventBus_basic (113.36s)
--- PASS: TestAccAWSCloudWatchEventBus_tags (139.77s)
Fantastic!!! Great work @alexanderkalach @ewbankkit @gdavison - Your work on this is really very, very appreciated 👍 |
This has been released in version 3.12.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
Relates #9330
Release note for CHANGELOG:
Output from acceptance testing: