Skip to content

Commit b793f88

Browse files
nkraemer-sysdigiru
andauthored
feat(bench): Automatically create benchmark task (#17)
* cloud-bench: Automatically create benchmark task * cleanup var file * use aws regions datasource * chore(doc): fix pre-commit Co-authored-by: iru <irune.prado@sysdig.com>
1 parent 02036e7 commit b793f88

File tree

8 files changed

+40
-9
lines changed

8 files changed

+40
-9
lines changed

examples-internal/single-account-benchmark/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
}
77
sysdig = {
88
source = "sysdiglabs/sysdig"
9-
version = ">= 0.5.18"
9+
version = ">= 0.5.19"
1010
}
1111
}
1212
}

examples/organizational/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Notice that:
6363
|------|---------|
6464
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.15.0 |
6565
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.50.0 |
66-
| <a name="requirement_sysdig"></a> [sysdig](#requirement\_sysdig) | >= 0.5.17 |
66+
| <a name="requirement_sysdig"></a> [sysdig](#requirement\_sysdig) | >= 0.5.19 |
6767

6868
## Providers
6969

examples/organizational/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
}
77
sysdig = {
88
source = "sysdiglabs/sysdig"
9-
version = ">= 0.5.17"
9+
version = ">= 0.5.19"
1010
}
1111
}
1212
}

examples/single-account/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Notice that:
4747
|------|---------|
4848
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.15.0 |
4949
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.50.0 |
50-
| <a name="requirement_sysdig"></a> [sysdig](#requirement\_sysdig) | >= 0.5.17 |
50+
| <a name="requirement_sysdig"></a> [sysdig](#requirement\_sysdig) | >= 0.5.19 |
5151

5252
## Providers
5353

examples/single-account/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
}
77
sysdig = {
88
source = "sysdiglabs/sysdig"
9-
version = ">= 0.5.17"
9+
version = ">= 0.5.19"
1010
}
1111
}
1212
}

modules/services/cloud-bench/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Cloud Bench deploy in AWS Module
22

3-
Deploys the required IAM Role and IAM Policies to allow Sysdig to run AWS Benchmarks on your behalf.
3+
Deploys
4+
5+
- the required IAM Role and IAM Policies to allow Sysdig to run AWS Benchmarks on your behalf
6+
- An `aws_foundations_bench-1.3.0` benchmak task schedule on `0 6 * * *`
7+
48

59

610
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
@@ -29,16 +33,19 @@ No modules.
2933
|------|------|
3034
| [aws_iam_role.cloudbench_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
3135
| [aws_iam_role_policy_attachment.cloudbench_security_audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
36+
| [sysdig_secure_benchmark_task.benchmark_task](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/resources/secure_benchmark_task) | resource |
3237
| [sysdig_secure_cloud_account.cloud_account](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/resources/secure_cloud_account) | resource |
3338
| [aws_iam_policy.security_audit](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy) | data source |
3439
| [aws_iam_policy_document.trust_relationship](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
35-
| [sysdig_secure_trusted_cloud_identity.trusted_sysdig_role](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/data-sources/secure_trusted_cloud_identity) | data source |
40+
| [aws_regions.regions](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/regions) | data source |
41+
| [sysdig_secure_trusted_cloud_identity.trusted_identity](https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs/data-sources/secure_trusted_cloud_identity) | data source |
3642

3743
## Inputs
3844

3945
| Name | Description | Type | Default | Required |
4046
|------|-------------|------|---------|:--------:|
4147
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | the account\_id in which to provision the cloud-bench IAM role | `string` | n/a | yes |
48+
| <a name="input_regions"></a> [regions](#input\_regions) | List of regions in which to run the benchmark. If empty, the task will contain all aws regions by default. | `list(string)` | `[]` | no |
4249
| <a name="input_tags"></a> [tags](#input\_tags) | sysdig secure-for-cloud tags | `map(string)` | <pre>{<br> "product": "sysdig-secure-for-cloud"<br>}</pre> | no |
4350

4451
## Outputs

modules/services/cloud-bench/main.tf

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,27 @@ resource "sysdig_secure_cloud_account" "cloud_account" {
77
role_enabled = "true"
88
}
99

10-
data "sysdig_secure_trusted_cloud_identity" "trusted_sysdig_role" {
10+
data "sysdig_secure_trusted_cloud_identity" "trusted_identity" {
1111
cloud_provider = "aws"
1212
}
1313

14+
data "aws_regions" "regions" {
15+
all_regions = true
16+
}
17+
18+
locals {
19+
regions = length(var.regions) == 0 ? data.aws_regions.regions.all_regions : var.regions
20+
}
21+
22+
resource "sysdig_secure_benchmark_task" "benchmark_task" {
23+
name = "Sysdig Secure for Cloud (AWS) - ${var.account_id}"
24+
schedule = "0 6 * * *"
25+
schema = "aws_foundations_bench-1.3.0"
26+
scope = "aws.accountId = \"${var.account_id}\" and aws.region in (\"${join("\", \"", local.regions)}}\")"
27+
28+
# Creation of a task requires that the Cloud Account already exists in the backend, and has `role_enabled = true`
29+
depends_on = [sysdig_secure_cloud_account.cloud_account]
30+
}
1431

1532
#
1633
# aws role provisioning
@@ -28,7 +45,7 @@ data "aws_iam_policy_document" "trust_relationship" {
2845
actions = ["sts:AssumeRole"]
2946
principals {
3047
type = "AWS"
31-
identifiers = [data.sysdig_secure_trusted_cloud_identity.trusted_sysdig_role.identity]
48+
identifiers = [data.sysdig_secure_trusted_cloud_identity.trusted_identity.identity]
3249
}
3350
condition {
3451
test = "StringEquals"

modules/services/cloud-bench/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ variable "account_id" {
77
# optionals - with default
88
#---------------------------------
99

10+
variable "regions" {
11+
type = list(string)
12+
description = "List of regions in which to run the benchmark. If empty, the task will contain all aws regions by default."
13+
default = []
14+
}
15+
1016
variable "tags" {
1117
type = map(string)
1218
description = "sysdig secure-for-cloud tags"
19+
1320
default = {
1421
"product" = "sysdig-secure-for-cloud"
1522
}

0 commit comments

Comments
 (0)