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

aws_cloudtrail_event_data_store #38273

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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/38273.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_cloudtrail_event_data_store: Add `billing_mode` argument
```
12 changes: 12 additions & 0 deletions internal/service/cloudtrail/event_data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ func resourceEventDataStore() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"billing_mode": {
Type: schema.TypeString,
Optional: true,
Default: types.BillingModeExtendableRetentionPricing,
ValidateDiagFunc: enum.Validate[types.BillingMode](),
},
names.AttrKMSKeyID: {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -188,6 +194,7 @@ func resourceEventDataStoreCreate(ctx context.Context, d *schema.ResourceData, m

name := d.Get(names.AttrName).(string)
input := &cloudtrail.CreateEventDataStoreInput{
BillingMode: types.BillingMode(d.Get("billing_mode").(string)),
MultiRegionEnabled: aws.Bool(d.Get("multi_region_enabled").(bool)),
Name: aws.String(name),
OrganizationEnabled: aws.Bool(d.Get("organization_enabled").(bool)),
Expand Down Expand Up @@ -240,6 +247,7 @@ func resourceEventDataStoreRead(ctx context.Context, d *schema.ResourceData, met
}
d.Set(names.AttrARN, output.EventDataStoreArn)
d.Set(names.AttrKMSKeyID, output.KmsKeyId)
d.Set("billing_mode", output.BillingMode)
d.Set("multi_region_enabled", output.MultiRegionEnabled)
d.Set(names.AttrName, output.Name)
d.Set("organization_enabled", output.OrganizationEnabled)
Expand All @@ -262,6 +270,10 @@ func resourceEventDataStoreUpdate(ctx context.Context, d *schema.ResourceData, m
input.AdvancedEventSelectors = expandAdvancedEventSelector(d.Get("advanced_event_selector").([]interface{}))
}

if d.HasChange("billing_mode") {
input.BillingMode = types.BillingMode(d.Get("billing_mode").(string))
}

if d.HasChange("multi_region_enabled") {
input.MultiRegionEnabled = aws.Bool(d.Get("multi_region_enabled").(bool))
}
Expand Down
57 changes: 57 additions & 0 deletions internal/service/cloudtrail/event_data_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,42 @@ func TestAccCloudTrailEventDataStore_basic(t *testing.T) {
})
}

func TestAccCloudTrailEventDataStore_billingMode(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_cloudtrail_event_data_store.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.CloudTrailServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckEventDataStoreDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccEventDataStoreConfig_billingMode(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckEventDataStoreExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "billing_mode", "EXTENDABLE_RETENTION_PRICING"),
resource.TestCheckResourceAttr(resourceName, "termination_protection_enabled", acctest.CtTrue),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccEventDataStoreConfig_billingModeUpdated(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckEventDataStoreExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "billing_mode", "FIXED_RETENTION_PRICING"),
resource.TestCheckResourceAttr(resourceName, "termination_protection_enabled", acctest.CtFalse),
),
},
},
})
}

func TestAccCloudTrailEventDataStore_kmsKeyId(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -346,6 +382,27 @@ resource "aws_cloudtrail_event_data_store" "test" {
`, rName)
}

func testAccEventDataStoreConfig_billingMode(rName string) string {
return fmt.Sprintf(`
resource "aws_cloudtrail_event_data_store" "test" {
name = %[1]q

termination_protection_enabled = false # For ease of deletion.
}
`, rName)
}

func testAccEventDataStoreConfig_billingModeUpdated(rName string) string {
return fmt.Sprintf(`
resource "aws_cloudtrail_event_data_store" "test" {
name = %[1]q

billing_mode = "FIXED_RETENTION_PRICING"
termination_protection_enabled = false # For ease of deletion.
}
`, rName)
}

func testAccEventDataStoreConfig_kmsKeyId(rName string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "test" {
Expand Down
46 changes: 46 additions & 0 deletions internal/service/cloudtrail/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func RegisterSweepers() {
Name: "aws_cloudtrail",
F: sweepTrails,
})

resource.AddTestSweepers("aws_cloudtrail_event_data_store", &resource.Sweeper{
Name: "aws_cloudtrail_event_data_store",
F: sweepEventDataStores,
})
}

func sweepTrails(region string) error {
Expand Down Expand Up @@ -84,3 +89,44 @@ func sweepTrails(region string) error {

return nil
}

func sweepEventDataStores(region string) error {
ctx := sweep.Context(region)
client, err := sweep.SharedRegionalSweepClient(ctx, region)
if err != nil {
return fmt.Errorf("error getting client: %w", err)
}
conn := client.CloudTrailClient(ctx)
input := &cloudtrail.ListEventDataStoresInput{}
sweepResources := make([]sweep.Sweepable, 0)

pages := cloudtrail.NewListEventDataStoresPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if awsv2.SkipSweepError(err) {
log.Printf("[WARN] Skipping CloudTrail Event Data Store sweep for %s: %s", region, err)
return nil
}

if err != nil {
return fmt.Errorf("error listing CloudTrail Event Data Stores (%s): %w", region, err)
}

for _, v := range page.EventDataStores {
r := resourceEventDataStore()
d := r.Data(nil)
d.SetId(aws.ToString(v.EventDataStoreArn))

sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client))
}
}

err = sweep.SweepOrchestrator(ctx, sweepResources)

if err != nil {
return fmt.Errorf("error sweeping CloudTrail Event Data Stores (%s): %w", region, err)
}

return nil
}
1 change: 1 addition & 0 deletions website/docs/r/cloudtrail_event_data_store.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ resource "aws_cloudtrail_event_data_store" "example" {
This resource supports the following arguments:

- `name` - (Required) The name of the event data store.
- `billing_mode` - (Optional) The billing mode for the event data store. The valid values are `EXTENDABLE_RETENTION_PRICING` and `FIXED_RETENTION_PRICING`. Defaults to `EXTENDABLE_RETENTION_PRICING`.
- `advanced_event_selector` - (Optional) The advanced event selectors to use to select the events for the data store. For more information about how to use advanced event selectors, see [Log events by using advanced event selectors](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html#creating-data-event-selectors-advanced) in the CloudTrail User Guide.
- `multi_region_enabled` - (Optional) Specifies whether the event data store includes events from all regions, or only from the region in which the event data store is created. Default: `true`.
- `organization_enabled` - (Optional) Specifies whether an event data store collects events logged for an organization in AWS Organizations. Default: `false`.
Expand Down
Loading