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

Allow to set event_bus_name as ARN on EventBridge aws_cloudwatch_event_rule resource. #20312

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d3fe849
Delete dependabot.yml
richardowen Jul 22, 2021
0388e0d
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Jul 22, 2021
8218ac8
Add acceptance test for AWS EventBridge event bus configuration using…
francesco-fucile Jul 23, 2021
057922a
EventBridge event bus rule, READ operation: update rule ID validation…
francesco-fucile Jul 23, 2021
a26f49f
Fix TestAccAWSCloudWatchEventRule_EventBusArn test.
francesco-fucile Jul 23, 2021
eea3ee7
Update READ function for event bus rule to preserve event bus ARNs.
francesco-fucile Jul 23, 2021
3c68959
Don't import event bus rule on test.
francesco-fucile Jul 26, 2021
e4e9f51
Reintroduce import tests for event bus rule.
francesco-fucile Jul 26, 2021
7480f54
Allow for setting event_bus_name as ARN for aws_cloudwatch_event_target.
francesco-fucile Jul 26, 2021
a00d2e3
Fix EventBusArn event bus target test.
francesco-fucile Jul 28, 2021
7c19db3
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Jul 28, 2021
fc027d5
Update changelog.
francesco-fucile Jul 28, 2021
434d25e
Revert "Delete dependabot.yml"
francesco-fucile Jul 29, 2021
c9ae082
Add new TF configuration for event bus rule with arn test.
francesco-fucile Jul 29, 2021
a738343
Fix typo on event rule test.
francesco-fucile Jul 29, 2021
7973c17
Remove event bus rule dependency on AWS_DEFAULT_REGION env var.
francesco-fucile Jul 29, 2021
57c882e
Fix event target test.
francesco-fucile Jul 30, 2021
2d1b90d
Remove reliance on EVENT_BRIDGE_EVENT_BUS_ARN env var.
francesco-fucile Aug 2, 2021
9826f83
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Aug 2, 2021
c63664c
Remove unused function.
francesco-fucile Aug 3, 2021
7b40c16
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Aug 3, 2021
bcf3e5b
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Aug 4, 2021
d6a005a
Rename parameters for test function for clarity.
francesco-fucile Aug 4, 2021
d6f6a05
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Aug 6, 2021
e5b2178
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Aug 9, 2021
eb3b166
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Aug 10, 2021
14e0d41
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Aug 12, 2021
8f4af03
Merge remote-tracking branch 'hashicorp/main' into f-add_arn_support_…
francesco-fucile Aug 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .github/dependabot.yml

This file was deleted.

12 changes: 11 additions & 1 deletion aws/internal/service/cloudwatchevents/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
awsarn "github.com/aws/aws-sdk-go/aws/arn"
events "github.com/aws/aws-sdk-go/service/cloudwatchevents"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -47,7 +48,16 @@ func Rule(conn *events.CloudWatchEvents, eventBusName, ruleName string) (*events
input.EventBusName = aws.String(eventBusName)
}

return conn.DescribeRule(&input)
out, err := conn.DescribeRule(&input)

if err == nil && awsarn.IsARN(eventBusName) {
eventBusArn, _ := awsarn.Parse(eventBusName)
eventBusArn.Resource = "event-bus/" + *out.EventBusName
updatedEventBusArn := eventBusArn.String()
out.EventBusName = &updatedEventBusArn
}

return out, err

}

Expand Down
4 changes: 3 additions & 1 deletion aws/internal/service/cloudwatchevents/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"regexp"
"strings"

awsarn "github.com/aws/aws-sdk-go/aws/arn"
)

var (
Expand Down Expand Up @@ -54,7 +56,7 @@ func RuleParseID(id string) (string, string, error) {
i := strings.LastIndex(id, ruleIDSeparator)
busName := id[:i]
statementID := id[i+1:]
if partnerEventBusPattern.MatchString(busName) && statementID != "" {
if (partnerEventBusPattern.MatchString(busName) || awsarn.IsARN(busName)) && statementID != "" {
return busName, statementID, nil
}
}
Expand Down
44 changes: 44 additions & 0 deletions aws/resource_aws_cloudwatch_event_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"log"
"os"
"regexp"
"strings"
"testing"

"github.com/aws/aws-sdk-go/aws"
awsarn "github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/cloudwatchevents"
events "github.com/aws/aws-sdk-go/service/cloudwatchevents"
"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -530,6 +532,48 @@ func TestAccAWSCloudWatchEventRule_PartnerEventBus(t *testing.T) {
})
}

func TestAccAWSCloudWatchEventRule_EventBusArn(t *testing.T) {
key := "EVENT_BRIDGE_EVENT_BUS_ARN"
busArn, err := awsarn.Parse(os.Getenv(key))
if err != nil {
t.Skipf("Environment variable %s is missing or is not a valid ARN", key)
}
busName := strings.Replace(busArn.Resource, "event-bus/", "", 1)

var v events.DescribeRuleOutput
rName := acctest.RandomWithPrefix("tf-acc-test-rule")
resourceName := "aws_cloudwatch_event_rule.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCloudWatchEventRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCloudWatchEventRulePartnerEventBusConfig(rName, busArn.String()),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchEventRuleExists(resourceName, &v),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "events", regexp.MustCompile(fmt.Sprintf(`rule/%s/%s$`, busName, rName))),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "event_bus_name", busArn.String()),
testAccCheckResourceAttrEquivalentJSON(resourceName, "event_pattern", "{\"source\":[\"aws.ec2\"]}"),
resource.TestCheckResourceAttr(resourceName, "is_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "role_arn", ""),
resource.TestCheckResourceAttr(resourceName, "schedule_expression", ""),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckCloudWatchEventRuleExists(n string, rule *events.DescribeRuleOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
1 change: 1 addition & 0 deletions docs/MAINTAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ Environment variables (beyond standard AWS Go SDK ones) used by acceptance testi
| `DX_VIRTUAL_INTERFACE_ID` | Identifier for Direct Connect Virtual Interface testing. |
| `EC2_SECURITY_GROUP_RULES_PER_GROUP_LIMIT` | EC2 Quota for Rules per Security Group. Defaults to 50. **DEPRECATED:** Can be augmented or replaced with Service Quotas lookup. |
| `EVENT_BRIDGE_PARTNER_EVENT_BUS_NAME` | Amazon EventBridge partner event bus name. |
| `EVENT_BRIDGE_EVENT_BUS_ARN` | Amazon EventBridge event bus ARN. |
| `EVENT_BRIDGE_PARTNER_EVENT_SOURCE_NAME` | Amazon EventBridge partner event source name. |
| `GCM_API_KEY` | API Key for Google Cloud Messaging in Pinpoint and SNS Platform Application testing. |
| `GITHUB_TOKEN` | GitHub token for CodePipeline testing. |
Expand Down