-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15727 from terraform-providers/add-eventbus-to-cl…
…oudwatch-event-rule Add eventbus to cloudwatch event rule
- Loading branch information
Showing
7 changed files
with
423 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package finder | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
events "github.com/aws/aws-sdk-go/service/cloudwatchevents" | ||
tfevents "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/cloudwatchevents" | ||
) | ||
|
||
func Rule(conn *events.CloudWatchEvents, eventBusName, ruleName string) (*events.DescribeRuleOutput, error) { | ||
input := events.DescribeRuleInput{ | ||
Name: aws.String(ruleName), | ||
} | ||
if eventBusName != "" { | ||
input.EventBusName = aws.String(eventBusName) | ||
} | ||
|
||
return conn.DescribeRule(&input) | ||
|
||
} | ||
|
||
func RuleByID(conn *events.CloudWatchEvents, ruleID string) (*events.DescribeRuleOutput, error) { | ||
busName, ruleName, err := tfevents.RuleParseID(ruleID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return Rule(conn, busName, ruleName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cloudwatchevents | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
const DefaultEventBusName = "default" | ||
|
||
const ruleIDSeparator = "/" | ||
|
||
func RuleCreateID(eventBusName, ruleName string) string { | ||
if eventBusName == "" || eventBusName == DefaultEventBusName { | ||
return ruleName | ||
} | ||
return eventBusName + ruleIDSeparator + ruleName | ||
} | ||
|
||
func RuleParseID(id string) (string, string, error) { | ||
parts := strings.Split(id, ruleIDSeparator) | ||
if len(parts) == 1 && parts[0] != "" { | ||
return DefaultEventBusName, parts[0], nil | ||
} | ||
if len(parts) == 2 && parts[0] != "" && parts[1] != "" { | ||
return parts[0], parts[1], nil | ||
} | ||
|
||
return "", "", fmt.Errorf("unexpected format for ID (%q), expected <event-bus-name>"+ruleIDSeparator+"<rule-name> or <rule-name>", id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.