forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for partner event bus and source
- Loading branch information
Showing
11 changed files
with
298 additions
and
6 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,7 @@ | ||
```release-note:enhancement | ||
resource/aws_cloudwatch_event_bus: Support partner event bus creation | ||
``` | ||
|
||
```release-note:new-data-source | ||
aws_cloudwatch_event_source | ||
``` |
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,73 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
events "github.com/aws/aws-sdk-go/service/cloudwatchevents" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceAwsCloudWatchEventSource() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsCloudWatchEventSourceRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name_prefix": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created_by": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsCloudWatchEventSourceRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).cloudwatcheventsconn | ||
|
||
input := &events.ListEventSourcesInput{} | ||
if v, ok := d.GetOk("name_prefix"); ok { | ||
input.NamePrefix = aws.String(v.(string)) | ||
} | ||
|
||
log.Printf("[DEBUG] Listing cloudwatch Event sources: %s", input) | ||
|
||
resp, err := conn.ListEventSources(input) | ||
if err != nil { | ||
return fmt.Errorf("error listing cloudwatch event sources: %w", err) | ||
} | ||
|
||
if resp == nil || len(resp.EventSources) == 0 { | ||
return fmt.Errorf("no matching partner event source") | ||
} | ||
if len(resp.EventSources) > 1 { | ||
return fmt.Errorf("multiple event sources matched; use additional constraints to reduce matches to a single event source") | ||
} | ||
|
||
es := resp.EventSources[0] | ||
|
||
d.SetId(aws.StringValue(es.Name)) | ||
d.Set("arn", es.Arn) | ||
d.Set("created_by", es.CreatedBy) | ||
d.Set("name", es.Name) | ||
d.Set("state", es.State) | ||
|
||
return nil | ||
} |
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,51 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/cloudwatchevents" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsCloudWatchEventSource(t *testing.T) { | ||
//resourceName := "aws_cloudwatch_event_bus.test" | ||
dataSourceName := "data.aws_cloudwatch_event_source.test" | ||
|
||
key := "EVENT_BRIDGE_PARTNER_EVENT_BUS_NAME" | ||
busName := os.Getenv(key) | ||
if busName == "" { | ||
t.Skipf("Environment variable %s is not set", key) | ||
} | ||
parts := strings.Split(busName, "/") | ||
if len(parts) < 2 { | ||
t.Errorf("unable to parse partner event bus name %s", busName) | ||
} | ||
namePrefix := parts[0] + "/" + parts[1] | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAwsDataSourcePartnerEventSourceConfig(namePrefix), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "name", busName), | ||
resource.TestCheckResourceAttr(dataSourceName, "created_by", namePrefix), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "arn"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAwsDataSourcePartnerEventSourceConfig(namePrefix string) string { | ||
return fmt.Sprintf(` | ||
data "aws_cloudwatch_event_source" "test" { | ||
name_prefix = "%s" | ||
} | ||
`, namePrefix) | ||
} |
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
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
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
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
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
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
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,40 @@ | ||
--- | ||
subcategory: "CloudWatch" | ||
layout: "aws" | ||
page_title: "AWS: aws_cloudwatch_event_source" | ||
description: |- | ||
Get information on an EventBridge (Cloudwatch) Event Source. | ||
--- | ||
|
||
# Data Source: aws_cloudwatch_event_source | ||
|
||
Use this data source to get information about an EventBridge Partner Event Source. This data source will only return one partner event source. An error will be returned if multiple sources match the same name prefix. | ||
|
||
~> **Note:** EventBridge was formerly known as CloudWatch Events. The functionality is identical. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_cloudwatch_event_source" "examplepartner" { | ||
name_prefix = "aws.partner/examplepartner.com" | ||
} | ||
resource "aws_cloudwatch_event_bus" "examplepartner" { | ||
name = data.aws_cloudwatch_event_source.examplepartner.name | ||
event_source_name = data.aws_cloudwatch_event_source.examplepartner.name | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name_prefix` - (Optional) A name prefix to filter results returned. Only API destinations with a name that starts with the prefix are returned | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `arn` - The ARN of the Partner event source | ||
* `created_by` - The name of the SaaS partner that created the event source. | ||
* `state` - The state of the event source (`ACTIVE` or `PENDING`) |
Oops, something went wrong.