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

d/aws_cloudwatch_event_bus #23792

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .changelog/23792.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_cloudwatch_event_bus
```
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ func Provider() *schema.Provider {

"aws_cloudtrail_service_account": cloudtrail.DataSourceServiceAccount(),

"aws_cloudwatch_event_bus": events.DataSourceBus(),
"aws_cloudwatch_event_connection": events.DataSourceConnection(),
"aws_cloudwatch_event_source": events.DataSourceSource(),

Expand Down
49 changes: 49 additions & 0 deletions internal/service/events/bus_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package events

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/eventbridge"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
)

func DataSourceBus() *schema.Resource {
return &schema.Resource{
Read: dataSourceBusRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func dataSourceBusRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).EventsConn

name := d.Get("name").(string)

input := &eventbridge.DescribeEventBusInput{
Name: aws.String(name),
}

output, err := conn.DescribeEventBus(input)
if err != nil {
return fmt.Errorf("error reading EventBridge Bus (%s): %w", name, err)
}

d.Set("arn", output.Arn)
d.Set("name", output.Name)

d.SetId(name)

return nil
}
44 changes: 44 additions & 0 deletions internal/service/events/bus_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package events_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/eventbridge"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccEventsBusDataSource_basic(t *testing.T) {
busName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
dataSourceName := "data.aws_cloudwatch_event_bus.test"
resourceName := "aws_cloudwatch_event_bus.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, eventbridge.EndpointsID),
Providers: acctest.Providers,
Steps: []resource.TestStep{
{
Config: testAccEventsBusDataSourceConfig(busName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
),
},
},
})
}

func testAccEventsBusDataSourceConfig(busName string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_event_bus" "test" {
name = %[1]q
}

data "aws_cloudwatch_event_bus" "test" {
name = aws_cloudwatch_event_bus.test.name
}
`, busName)
}
29 changes: 29 additions & 0 deletions website/docs/d/cloudwatch_event_bus.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
subcategory: "CloudWatch"
layout: "aws"
page_title: "AWS: aws_cloudwatch_event_bus"
description: |-
Get information on an EventBridge (Cloudwatch) Event Bus.
---

# Data Source: aws_cloudwatch_event_bus

This data source can be used to fetch information about a specific
EventBridge event bus. Use this data source to compute the ARN of
an event bus, given the name of the bus.

## Example Usage

```terraform
data "aws_cloudwatch_event_bus" "example" {
name = "example-bus-name"
}
```

## Argument Reference

* `name` - (Required) The friendly EventBridge event bus name.

## Attributes Reference

* `arn` - The Amazon Resource Name (ARN) specifying the role.