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

feat: Add description arg/attr for aws_cloudwatch_event_bus resource and data source #39980

Merged
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
6 changes: 6 additions & 0 deletions .changelog/39980.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
resource/aws_cloudwatch_event_bus: Add `description` argument
```
```release-note:enhancement
data-source/aws_cloudwatch_event_bus: Add `description` attribute
```
19 changes: 18 additions & 1 deletion internal/service/events/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func resourceBus() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
names.AttrDescription: {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 512),
},
"event_source_name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -76,6 +81,10 @@ func resourceBusCreate(ctx context.Context, d *schema.ResourceData, meta interfa
Tags: getTagsIn(ctx),
}

if v, ok := d.GetOk(names.AttrDescription); ok {
input.Description = aws.String(v.(string))
}

if v, ok := d.GetOk("event_source_name"); ok {
input.EventSourceName = aws.String(v.(string))
}
Expand Down Expand Up @@ -133,6 +142,7 @@ func resourceBusRead(ctx context.Context, d *schema.ResourceData, meta interface
}

d.Set(names.AttrARN, output.Arn)
d.Set(names.AttrDescription, output.Description)
d.Set("kms_key_identifier", output.KmsKeyIdentifier)
d.Set(names.AttrName, output.Name)

Expand All @@ -143,11 +153,18 @@ func resourceBusUpdate(ctx context.Context, d *schema.ResourceData, meta interfa
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EventsClient(ctx)

if d.HasChange("kms_key_identifier") {
if d.HasChanges(names.AttrDescription, "kms_key_identifier") {
input := &eventbridge.UpdateEventBusInput{
Name: aws.String(d.Get(names.AttrName).(string)),
}

// To unset the description, the only way is to explicitly set it to the empty string
if v, ok := d.GetOk(names.AttrDescription); ok {
input.Description = aws.String(v.(string))
} else {
input.Description = aws.String("")
}

if v, ok := d.GetOk("kms_key_identifier"); ok {
input.KmsKeyIdentifier = aws.String(v.(string))
}
Expand Down
5 changes: 5 additions & 0 deletions internal/service/events/bus_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func dataSourceBus() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
names.AttrDescription: {
Type: schema.TypeString,
Computed: true,
},
"kms_key_identifier": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -48,6 +52,7 @@ func dataSourceBusRead(ctx context.Context, d *schema.ResourceData, meta interfa

d.SetId(eventBusName)
d.Set(names.AttrARN, output.Arn)
d.Set(names.AttrDescription, output.Description)
d.Set("kms_key_identifier", output.KmsKeyIdentifier)
d.Set(names.AttrName, output.Name)

Expand Down
2 changes: 2 additions & 0 deletions internal/service/events/bus_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestAccEventsBusDataSource_kmsKeyIdentifier(t *testing.T) {
{
Config: testAccBusDataSourceConfig_kmsKeyIdentifier(busName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrDescription, resourceName, names.AttrDescription),
resource.TestCheckResourceAttrPair(dataSourceName, "kms_key_identifier", resourceName, "kms_key_identifier"),
),
},
Expand Down Expand Up @@ -124,6 +125,7 @@ resource "aws_kms_key_policy" "test" {

resource "aws_cloudwatch_event_bus" "test" {
name = %[1]q
description = "Test event bus"
kms_key_identifier = aws_kms_key.test.arn
}

Expand Down
39 changes: 34 additions & 5 deletions internal/service/events/bus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (

func TestAccEventsBus_basic(t *testing.T) {
ctx := acctest.Context(t)
var v1, v2, v3 eventbridge.DescribeEventBusOutput
var v1, v2, v3, v4, v5 eventbridge.DescribeEventBusOutput
busName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
busNameModified := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_cloudwatch_event_bus.test"
description := "Test event bus"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand All @@ -40,6 +41,7 @@ func TestAccEventsBus_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckBusExists(ctx, resourceName, &v1),
acctest.CheckResourceAttrRegionalARN(resourceName, names.AttrARN, "events", fmt.Sprintf("event-bus/%s", busName)),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, ""),
resource.TestCheckNoResourceAttr(resourceName, "event_source_name"),
resource.TestCheckResourceAttr(resourceName, names.AttrName, busName),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
Expand All @@ -51,11 +53,28 @@ func TestAccEventsBus_basic(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccBusConfig_basic(busNameModified),
Config: testAccBusConfig_description(busName, description),
Check: resource.ComposeTestCheckFunc(
testAccCheckBusExists(ctx, resourceName, &v2),
testAccCheckBusRecreated(&v1, &v2),
testAccCheckBusNotRecreated(&v1, &v2),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, description),
),
},
{
Config: testAccBusConfig_basic(busName),
Check: resource.ComposeTestCheckFunc(
testAccCheckBusExists(ctx, resourceName, &v3),
testAccCheckBusNotRecreated(&v2, &v3),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, ""),
),
},
{
Config: testAccBusConfig_basic(busNameModified),
Check: resource.ComposeTestCheckFunc(
testAccCheckBusExists(ctx, resourceName, &v4),
testAccCheckBusRecreated(&v3, &v4),
acctest.CheckResourceAttrRegionalARN(resourceName, names.AttrARN, "events", fmt.Sprintf("event-bus/%s", busNameModified)),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, ""),
resource.TestCheckNoResourceAttr(resourceName, "event_source_name"),
resource.TestCheckResourceAttr(resourceName, names.AttrName, busNameModified),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
Expand All @@ -64,8 +83,9 @@ func TestAccEventsBus_basic(t *testing.T) {
{
Config: testAccBusConfig_tags1(busNameModified, names.AttrKey, names.AttrValue),
Check: resource.ComposeTestCheckFunc(
testAccCheckBusExists(ctx, resourceName, &v3),
testAccCheckBusNotRecreated(&v2, &v3),
testAccCheckBusExists(ctx, resourceName, &v5),
testAccCheckBusNotRecreated(&v4, &v5),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, ""),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"),
resource.TestCheckResourceAttr(resourceName, "tags.key", names.AttrValue),
),
Expand Down Expand Up @@ -302,6 +322,15 @@ resource "aws_cloudwatch_event_bus" "test" {
`, name)
}

func testAccBusConfig_description(name, description string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_event_bus" "test" {
name = %[1]q
description = %[2]q
}
`, name, description)
}

func testAccBusConfig_tags1(name, key, value string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_event_bus" "test" {
Expand Down
8 changes: 5 additions & 3 deletions website/docs/d/cloudwatch_event_bus.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ data "aws_cloudwatch_event_bus" "example" {

## Argument Reference

* `name` - (Required) Friendly EventBridge event bus name.
* `name` - (Required) Name of the event bus.

## Attribute Reference

This data source exports the following attributes in addition to the arguments above:

* `arn` - ARN.
* `kms_key_identifier` - The identifier of the AWS KMS customer managed key for EventBridge to use to encrypt events on this event bus, if one has been specified.
* `arn` - ARN of the event bus.
* `description` - Event bus description.
* `id` - Name of the event bus.
* `kms_key_identifier` - Identifier of the AWS KMS customer managed key for EventBridge to use to encrypt events on this event bus, if one has been specified.
22 changes: 15 additions & 7 deletions website/docs/r/cloudwatch_event_bus.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data "aws_cloudwatch_event_source" "examplepartner" {

resource "aws_cloudwatch_event_bus" "examplepartner" {
name = data.aws_cloudwatch_event_source.examplepartner.name
description = "Event bus for example partner events"
event_source_name = data.aws_cloudwatch_event_source.examplepartner.name
}
```
Expand All @@ -35,17 +36,24 @@ resource "aws_cloudwatch_event_bus" "examplepartner" {

This resource supports the following arguments:

* `name` - (Required) The name of the new event bus. The names of custom event buses can't contain the / character. To create a partner event bus, ensure the `name` matches the `event_source_name`.
* `event_source_name` - (Optional) The partner event source that the new event bus will be matched with. Must match `name`.
* `kms_key_identifier` - (Optional) The identifier of the AWS KMS customer managed key for EventBridge to use, if you choose to use a customer managed key to encrypt events on this event bus. The identifier can be the key Amazon Resource Name (ARN), KeyId, key alias, or key alias ARN.
* `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
The following arguments are required:

* `name` - (Required) Name of the new event bus. The names of custom event buses can't contain the / character. To create a partner event bus, ensure that the `name` matches the `event_source_name`.

The following arguments are optional:

* `description` - (Optional) Event bus description.
* `event_source_name` - (Optional) Partner event source that the new event bus will be matched with. Must match `name`.
* `kms_key_identifier` - (Optional) Identifier of the AWS KMS customer managed key for EventBridge to use, if you choose to use a customer managed key to encrypt events on this event bus. The identifier can be the key Amazon Resource Name (ARN), KeyId, key alias, or key alias ARN.
* `tags` - (Optional) Map of tags assigned to the resource. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.

## Attribute Reference

This resource exports the following attributes in addition to the arguments above:

* `arn` - The Amazon Resource Name (ARN) of the event bus.
* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).
* `arn` - ARN of the event bus.
* `id` - Name of the event bus.
* `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).

## Import

Expand All @@ -58,7 +66,7 @@ import {
}
```

Using `terraform import`, import EventBridge event buses using the `name` (which can also be a partner event source name). For example:
Using `terraform import`, import EventBridge event buses using the name of the event bus (which can also be a partner event source name). For example:

```console
% terraform import aws_cloudwatch_event_bus.messenger chat-messages
Expand Down
Loading