Skip to content

Commit 67cbd97

Browse files
feat(audit_trail): add new data source audit_trail_event (#3445)
* feat(audit_trail): add new data source audit_trail_event * fix: validate resource_type with warning instead of error * add: all filters + cassette * remove borderline test that 400s on purpose * add audittrail to ci * fix: handle resource_id in request with optional locality * docs: provide list of service_name and product_name possible values * add: better validation * tests: refacto * fix: orgID handling * add: recorded_after and recorded_before test * fix: typo * fix: better region handling and doc --------- Co-authored-by: Rémy Léone <[email protected]>
1 parent e70b788 commit 67cbd97

File tree

13 files changed

+3330
-1
lines changed

13 files changed

+3330
-1
lines changed

.github/codecov.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ component_management:
1414
name: applesilicon
1515
paths:
1616
- internal/services/applesilicon/**
17+
- component_id: audittrail
18+
name: audittrail
19+
paths:
20+
- internal/services/audittrail/**
1721
- component_id: autoscaling
1822
name: autoscaling
1923
paths:

.github/workflows/acceptance-tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
products:
1616
- account
1717
- applesilicon
18+
- audittrail
1819
- az
1920
- baremetal
2021
- billing
@@ -172,6 +173,7 @@ jobs:
172173
products:
173174
- account
174175
- applesilicon
176+
- audittrail
175177
- az
176178
- baremetal
177179
- billing

.github/workflows/nightly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
products:
1717
- account
1818
- applesilicon
19+
- audittrail
1920
- autoscaling
2021
- az
2122
- baremetal
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
subcategory: "Audit Trail"
3+
page_title: "Scaleway: scaleway_audit_trail_event"
4+
---
5+
6+
# scaleway_audit_trail_event
7+
8+
Use this data source to get a list of existing Audit Trail events.
9+
For more information refer to the [Audit Trail API documentation](https://www.scaleway.com/en/developers/api/audit-trail/).
10+
11+
## Example Usage
12+
13+
```hcl
14+
# Retrieve all audit trail events on the default organization
15+
data "scaleway_audit_trail_event" "find_all" {
16+
}
17+
18+
# Retrieve audit trail events on a specific organization
19+
data "scaleway_audit_trail_event" "find_by_org" {
20+
organization_id = "11111111-1111-1111-1111-111111111111"
21+
}
22+
23+
# Retrieve audit trail events on a specific project
24+
data "scaleway_audit_trail_event" "find_by_project" {
25+
project_id = "11111111-1111-1111-1111-111111111111"
26+
}
27+
28+
# Retrieve audit trail events for a specific type of resource
29+
data "scaleway_audit_trail_event" "find_by_resource_type" {
30+
resource_type = "instance_server"
31+
}
32+
33+
# Retrieve audit trail for a specific resource
34+
data "scaleway_audit_trail_event" "find_by_resource_id" {
35+
resource_id = "11111111-1111-1111-1111-111111111111"
36+
}
37+
38+
# Retrieve audit trail for a specific Scaleway product
39+
data "scaleway_audit_trail_event" "find_by_product_name" {
40+
product_name = "secret-manager"
41+
}
42+
43+
# Retrieve audit trail events with various filtering
44+
data "scaleway_audit_trail_event" "find_with_filters" {
45+
region = "fr-par"
46+
service_name = "instance"
47+
method_name = "CreateServer"
48+
principal_id = "11111111-1111-1111-1111-111111111111"
49+
source_ip = "192.0.2.1"
50+
status = 200
51+
recorded_after = "2025-10-01T00:00:00Z"
52+
recorded_before = "2025-12-31T23:59:59Z"
53+
order_by = "recorded_at_desc"
54+
}
55+
```
56+
57+
## Argument Reference
58+
59+
- `region` - (Optional) The [region](../guides/regions_and_zones.md#regions) you want to target. Defaults to the region specified in the [provider configuration](../index.md#region).
60+
- `organization_id` - (Optional. Defaults to [provider](../index.md#organization_id) `organization_id`) ID of the Organization containing the Audit Trail events.
61+
- `project_id` - (Optional) ID of the Project containing the Audit Trail events.
62+
- `resource_type` - (Optional) Type of the scaleway resources associated with the listed events. Possible values are: `secm_secret`, `secm_secret_version`, `kube_cluster`, `kube_pool`, `kube_node`, `kube_acl`, `keym_key`, `iam_user`, `iam_application`, `iam_group`, `iam_policy`, `iam_api_key`, `iam_ssh_key`, `iam_rule`, `iam_saml`, `iam_saml_certificate`, `secret_manager_secret`, `secret_manager_version`, `key_manager_key`, `account_user`, `account_organization`, `account_project`, `instance_server`, `instance_placement_group`, `instance_security_group`, `instance_volume`, `instance_snapshot`, `instance_image`, `apple_silicon_server`, `baremetal_server`, `baremetal_setting`, `ipam_ip`, `sbs_volume`, `sbs_snapshot`, `load_balancer_lb`, `load_balancer_ip`, `load_balancer_frontend`, `load_balancer_backend`, `load_balancer_route`, `load_balancer_acl`, `load_balancer_certificate`, `sfs_filesystem`, or `vpc_private_network`.
63+
- `resource_id` - (Optional) ID of the Scaleway resource associated with the listed events.
64+
- `product_name` - (Optional) Name of the Scaleway product in a hyphenated format.
65+
- `service_name` - (Optional) Name of the service of the API call performed.
66+
- `method_name` - (Optional) Name of the method of the API call performed.
67+
- `principal_id` - (Optional) ID of the User or IAM application at the origin of the event.
68+
- `source_ip` - (Optional) IP address at the origin of the event.
69+
- `status` - (Optional) HTTP status code of the request.
70+
- `recorded_after` - (Optional) The `recorded_after` parameter defines the earliest timestamp from which Audit Trail events are retrieved. Returns `one hour ago` by default (Format ISO 8601).
71+
- `recorded_before` - (Optional) The `recorded_before` parameter defines the latest timestamp up to which Audit Trail events are retrieved. Must be later than recorded_after. Returns `now` by default (Format ISO 8601).
72+
- `order_by` - (Optional) Defines the order in which events are returned. Possible values are `recorded_at_asc` and `recorded_at_desc`. Default value: `recorded_at_desc`.
73+
74+
75+
## Attributes Reference
76+
77+
In addition to all arguments above, the following attributes are exported:
78+
79+
- `events` - List of Audit Trail events matching the requested criteria.
80+
- `id` - ID of the event. (UUID format)
81+
- `recorded_at` - Timestamp of the event. (RFC 3339 format)
82+
- `locality` - Locality of the resource attached to the event.
83+
- `principal_id` - ID of the user or IAM application at the origin of the event.
84+
- `organization_id` - ID of the Organization containing the Audit Trail events. (UUID format)
85+
- `project_id` - Project of the resource attached to the event. (UUID format)
86+
- `source_ip` - IP address at the origin of the event. (IP address)
87+
- `user_agent` - User Agent at the origin of the event.
88+
- `product_name` - Scaleway product associated with the listed events in a hyphenated format. Possible values are: `secret-manager`, `key-manager`, `iam`, `kubernetes`, `account`, `apple-silicon`, `instance`, `baremetal`, `load-balancer`, or `edge-services`.
89+
- `service_name` - API name called to trigger the event. Possible values are: `scaleway.secret_manager.v1beta1.Api`, `scaleway.key_manager.v1alpha1.Api`, `scaleway.iam.v1alpha1.Api`, `scaleway.iam.v1alpha1.UnauthenticatedApi`, `scaleway.k8s.v1.Api`, `scaleway.account.v3.UserApi`, `scaleway.account.v3.OrganizationApi`, `scaleway.account.v2.GDPRApi`, `scaleway.apple_silicon.v1alpha1.Api`, `scaleway.instance.v1.Api`, `scaleway.baremetal.v1.Api`, or `scaleway.lb.v1.ZonedApi`.
90+
- `method_name` - API method called to trigger the event.
91+
- `resources` - List of resources attached to the event.
92+
- `id` - ID of the resource attached to the event. (UUID format)
93+
- `type` - Type of the Scaleway resource.
94+
- `name` - Name of the Scaleway resource.
95+
- `request_id` - Unique identifier of the request at the origin of the event. (UUID format)
96+
- `request_body` - Request at the origin of the event.
97+
- `status_code` - HTTP status code resulting of the API call.

internal/acctest/acctest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type TestTools struct {
3232
}
3333

3434
var foldersUsingVCRv4 = []string{
35+
"audittrail",
3536
"account",
3637
"container",
3738
"iam",

internal/meta/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ package meta
22

33
import "errors"
44

5-
// ErrProjectIDNotFound is returned when no region can be detected
5+
// ErrProjectIDNotFound is returned when no project ID can be detected
66
var ErrProjectIDNotFound = errors.New("could not detect project id")

0 commit comments

Comments
 (0)