Skip to content

Commit feadc0c

Browse files
k3nz0urseberry
andauthored
[AUTOSCALING] Add Agentless Scanners autoscaling module (#195)
* Add Agentless Scanners autoscaling module * Add resources pattern + set max asg * Update terraform docs * Update modules/agentless-scanners-autoscaling/README.md Co-authored-by: Ursula Chen <[email protected]> * Set max asg size to 50 * Split DescribeAutoScaling to its own statement and refresh readme --------- Co-authored-by: Ursula Chen <[email protected]>
1 parent f384392 commit feadc0c

File tree

10 files changed

+111
-6
lines changed

10 files changed

+111
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ No resources.
170170
| <a name="input_api_key_secret_arn"></a> [api\_key\_secret\_arn](#input\_api\_key\_secret\_arn) | ARN of the secret holding the Datadog API key. Takes precedence over api\_key variable - Make sure the API key is Remote Configuration enabled. | `string` | `null` | no |
171171
| <a name="input_enable_ssm"></a> [enable\_ssm](#input\_enable\_ssm) | Whether to enable AWS SSM to facilitate executing troubleshooting commands on the instance | `bool` | `false` | no |
172172
| <a name="input_enable_ssm_vpc_endpoint"></a> [enable\_ssm\_vpc\_endpoint](#input\_enable\_ssm\_vpc\_endpoint) | Whether to enable AWS SSM VPC endpoint (only applicable if enable\_ssm is true) | `bool` | `true` | no |
173-
| <a name="input_instance_count"></a> [instance\_count](#input\_instance\_count) | Size of the autoscaling group the instance is in (i.e. number of instances with scanners to run) | `number` | `1` | no |
173+
| <a name="input_instance_count"></a> [instance\_count](#input\_instance\_count) | Default size of the autoscaling group the instance is in (i.e. number of instances with scanners to run) | `number` | `1` | no |
174174
| <a name="input_instance_profile_name"></a> [instance\_profile\_name](#input\_instance\_profile\_name) | Name of the instance profile to attach to the instance | `string` | n/a | yes |
175175
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The type of instance running the scanner | `string` | `"t4g.large"` | no |
176176
| <a name="input_scanner_channel"></a> [scanner\_channel](#input\_scanner\_channel) | Channel of the scanner to install from (stable or beta). | `string` | `"stable"` | no |
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## Requirements
2+
3+
| Name | Version |
4+
|------|---------|
5+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
6+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
7+
8+
## Providers
9+
10+
| Name | Version |
11+
|------|---------|
12+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
13+
14+
## Modules
15+
16+
No modules.
17+
18+
## Resources
19+
20+
| Name | Type |
21+
|------|------|
22+
| [aws_iam_role_policy.agentless_autoscaling_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource |
23+
| [aws_iam_policy_document.agentless_autoscaling_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
24+
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
25+
26+
## Inputs
27+
28+
| Name | Description | Type | Default | Required |
29+
|------|-------------|------|---------|:--------:|
30+
| <a name="input_datadog_integration_role"></a> [datadog\_integration\_role](#input\_datadog\_integration\_role) | Role name of the Datadog integration that was used to integrate the scanners' AWS account to Datadog | `string` | `null` | no |
31+
32+
## Outputs
33+
34+
No outputs.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
data "aws_partition" "current" {}
2+
3+
resource "aws_iam_role_policy" "agentless_autoscaling_policy" {
4+
name = "DatadogAgentlessScannerAutoscalingPolicy"
5+
role = var.datadog_integration_role
6+
policy = data.aws_iam_policy_document.agentless_autoscaling_policy_document.json
7+
8+
}
9+
10+
data "aws_iam_policy_document" "agentless_autoscaling_policy_document" {
11+
statement {
12+
effect = "Allow"
13+
actions = [
14+
"autoscaling:StartInstanceRefresh",
15+
"autoscaling:SetDesiredCapacity",
16+
"ec2:GetConsoleOutput",
17+
]
18+
resources = [
19+
"arn:${data.aws_partition.current.partition}:autoscaling:*:*:autoScalingGroup:*",
20+
"arn:${data.aws_partition.current.partition}:ec2:*:*:instance/*",
21+
]
22+
// Enforce that any of these actions can be performed on resources
23+
// that have the DatadogAgentlessScanner tag.
24+
condition {
25+
test = "StringEquals"
26+
variable = "aws:ResourceTag/DatadogAgentlessScanner"
27+
values = ["true"]
28+
}
29+
}
30+
31+
statement {
32+
effect = "Allow"
33+
actions = [
34+
"autoscaling:DescribeAutoScalingGroups",
35+
]
36+
resources = ["*"]
37+
}
38+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# No outputs for now
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.0"
8+
}
9+
}
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
variable "datadog_integration_role" {
2+
description = "Role name of the Datadog integration that was used to integrate the scanners' AWS account to Datadog"
3+
type = string
4+
default = null
5+
}
6+

modules/instance/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ No modules.
3434

3535
| Name | Description | Type | Default | Required |
3636
|------|-------------|------|---------|:--------:|
37-
| <a name="input_asg_size"></a> [asg\_size](#input\_asg\_size) | Size of the autoscaling group the instance is in (i.e. number of instances to run) | `number` | `1` | no |
37+
| <a name="input_asg_size"></a> [asg\_size](#input\_asg\_size) | Default size of the autoscaling group the instance is in (i.e. default number of instances to run) | `number` | `1` | no |
3838
| <a name="input_iam_instance_profile"></a> [iam\_instance\_profile](#input\_iam\_instance\_profile) | IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile | `string` | n/a | yes |
3939
| <a name="input_instance_image_id"></a> [instance\_image\_id](#input\_instance\_image\_id) | The Image ID (aka. AMI) used as baseline for the instance - SSM parameter path is allowed | `string` | `"resolve:ssm:/aws/service/canonical/ubuntu/server-minimal/24.04/stable/current/arm64/hvm/ebs-gp3/ami-id"` | no |
4040
| <a name="input_instance_root_volume_size"></a> [instance\_root\_volume\_size](#input\_instance\_root\_volume\_size) | The instance root volume size in GiB | `number` | `30` | no |
4141
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The type of instance | `string` | `"t4g.large"` | no |
4242
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | Key name of the Key Pair to use for the instance; which can be managed using the `aws_key_pair` resource | `string` | `null` | no |
43+
| <a name="input_max_asg_size"></a> [max\_asg\_size](#input\_max\_asg\_size) | Maximum size of the autoscaling group the instance is in (i.e. maximum number of instances to run) | `number` | `50` | no |
44+
| <a name="input_min_asg_size"></a> [min\_asg\_size](#input\_min\_asg\_size) | Minimum size of the autoscaling group the instance is in (i.e. minimum number of instances to run) | `number` | `0` | no |
4345
| <a name="input_monitoring"></a> [monitoring](#input\_monitoring) | If true, the launched EC2 instance will have detailed monitoring enabled | `bool` | `false` | no |
4446
| <a name="input_name"></a> [name](#input\_name) | Name prefix to be used on EC2 instance created | `string` | `"DatadogAgentlessScanner"` | no |
4547
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | The VPC Subnet IDs to launch in | `list(string)` | n/a | yes |

modules/instance/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ resource "aws_security_group" "default_scanner_security_group" {
7474

7575
resource "aws_autoscaling_group" "asg" {
7676
name_prefix = "datadog-agentless-scanner-asg"
77-
min_size = var.asg_size
78-
max_size = var.asg_size
77+
min_size = var.min_asg_size
78+
max_size = var.max_asg_size
7979
desired_capacity = var.asg_size
8080

8181
# references:

modules/instance/variables.tf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,26 @@ variable "monitoring" {
6161
default = false
6262
}
6363

64+
variable "min_asg_size" {
65+
description = "Minimum size of the autoscaling group the instance is in (i.e. minimum number of instances to run)"
66+
type = number
67+
default = 0
68+
}
69+
70+
variable "max_asg_size" {
71+
description = "Maximum size of the autoscaling group the instance is in (i.e. maximum number of instances to run)"
72+
type = number
73+
default = 50
74+
}
75+
6476
variable "asg_size" {
65-
description = "Size of the autoscaling group the instance is in (i.e. number of instances to run)"
77+
description = "Default size of the autoscaling group the instance is in (i.e. default number of instances to run)"
6678
type = number
6779
default = 1
6880
}
6981

82+
83+
7084
variable "tags" {
7185
description = "A map of additional tags to add to the instance/volume created"
7286
type = map(string)

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ variable "instance_type" {
8989
}
9090

9191
variable "instance_count" {
92-
description = "Size of the autoscaling group the instance is in (i.e. number of instances with scanners to run)"
92+
description = "Default size of the autoscaling group the instance is in (i.e. number of instances with scanners to run)"
9393
type = number
9494
default = 1
9595
}

0 commit comments

Comments
 (0)