Skip to content

Commit 0ce09a9

Browse files
author
iru
authored
fix: ECS autoscale (#159)
- fix autoscale since previous composition was not working as expected - fix scaledown and bypass hashicorp/terraform-provider-aws#10376 side-quest - expose as inputs `autoscaling_confing`
1 parent 9ce1dd3 commit 0ce09a9

File tree

23 files changed

+153
-176
lines changed

23 files changed

+153
-176
lines changed

Diff for: .github/workflows/ci-integration-tests.yaml

-17
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,6 @@ jobs:
160160
if: ${{ failure() }}
161161
run: bundle exec kitchen destroy "organizational-aws"
162162

163-
164-
- name: Run organizational-single test
165-
env:
166-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_QA_MANAGED_ACCESS_KEY_ID }}
167-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_QA_MANAGED_SECRET_ACCESS_KEY }}
168-
AWS_REGION: ${{ secrets.AWS_REGION }}
169-
TF_VAR_sysdig_secure_for_cloud_member_account_id: ${{ secrets.AWS_QA_CLOUDNATIVE_ACCOUNT_ID }}
170-
run: bundle exec kitchen test "organizational-single-aws"
171-
172-
- name: Destroy organizational-single resources
173-
env:
174-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_QA_MANAGED_ACCESS_KEY_ID }}
175-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_QA_MANAGED_SECRET_ACCESS_KEY }}
176-
AWS_REGION: ${{ secrets.AWS_REGION }}
177-
TF_VAR_sysdig_secure_for_cloud_member_account_id: ${{ secrets.AWS_QA_CLOUDNATIVE_ACCOUNT_ID }}
178-
if: ${{ failure() }}
179-
run: bundle exec kitchen destroy "organizational-single-aws"
180163
integration_test_app_runner:
181164
needs: integration_test_ecs
182165
concurrency: terraform-account

Diff for: .kitchen.yml

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ suites:
1919
- name: organizational-k8s
2020
driver:
2121
root_module_directory: test/fixtures/organizational-k8s
22-
- name: organizational-single
23-
driver:
24-
root_module_directory: test/fixtures/organizational-single
2522
- name: single-account-apprunner
2623
driver:
2724
root_module_directory: test/fixtures/single-account-apprunner

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ Error: Not enough privileges to complete the action, Access is denied
333333
334334
│ Error: error waiting for CloudFormation StackSet(sysdig - secure - cloudbench) update: unexpected state 'FAILED', wanted target 'SUCCEEDED'.last error: Operation(terraform - 20221130212414336200000001) Results: 6 errors occurred:
335335
│ * Account(***) Region(us - east - 1) Status(SUCCEEDED) Status Reason: No updates are to be performed.
336-
│ * Account(***) Region(us - east - 1) Status(FAILED) Status Reason: Account *** should have
336+
│ * Account(***) Region(us - east - 1) Status(FAILED) Status Reason: Account *** should have
337337
'stacksets-exec-70e2f8a88d368a5d3df60f4eb8c247dc' role with trust relationship to Role 'aws-service-role/stacksets.cloudformation.amazonaws.com/AWSServiceRoleForCloudFormationStackSetsOrgAdmin
338338
```
339339

Diff for: examples/organizational/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ $ terraform apply
186186
| Name | Description | Type | Default | Required |
187187
|------|-------------|------|---------|:--------:|
188188
| <a name="input_sysdig_secure_for_cloud_member_account_id"></a> [sysdig\_secure\_for\_cloud\_member\_account\_id](#input\_sysdig\_secure\_for\_cloud\_member\_account\_id) | organizational member account where the secure-for-cloud workload is going to be deployed | `string` | n/a | yes |
189+
| <a name="input_autoscaling_config"></a> [autoscaling\_config](#input\_autoscaling\_config) | if enable\_autoscaliing is enabled, ECS autoscaling configuration. for more insight check source code | <pre>object({<br> min_replicas = number<br> max_replicas = number<br> upscale_threshold = number<br> downscale_threshold = number<br> })</pre> | <pre>{<br> "downscale_threshold": 30,<br> "max_replicas": 15,<br> "min_replicas": 2,<br> "upscale_threshold": 60<br>}</pre> | no |
189190
| <a name="input_benchmark_regions"></a> [benchmark\_regions](#input\_benchmark\_regions) | List of regions in which to run the benchmark. If empty, the task will contain all aws regions by default. | `list(string)` | `[]` | no |
190191
| <a name="input_cloudtrail_is_multi_region_trail"></a> [cloudtrail\_is\_multi\_region\_trail](#input\_cloudtrail\_is\_multi\_region\_trail) | true/false whether the created cloudtrail will ingest multi-regional events. testing/economization purpose. | `bool` | `true` | no |
191192
| <a name="input_cloudtrail_kms_enable"></a> [cloudtrail\_kms\_enable](#input\_cloudtrail\_kms\_enable) | true/false whether the created cloudtrail should deliver encrypted events to s3 | `bool` | `true` | no |
@@ -204,8 +205,6 @@ $ terraform apply
204205
| <a name="input_ecs_vpc_subnets_private_ids"></a> [ecs\_vpc\_subnets\_private\_ids](#input\_ecs\_vpc\_subnets\_private\_ids) | List of VPC subnets where workload is to be deployed. If defaulted new subnets will be created within the VPC. A minimum of two subnets is suggested. If specified all three parameters `ecs_cluster_name`, `ecs_vpc_id` and `ecs_vpc_subnets_private_ids` are required. | `list(string)` | `[]` | no |
205206
| <a name="input_enable_autoscaling"></a> [enable\_autoscaling](#input\_enable\_autoscaling) | Whether to enable autoscaling or not | `bool` | `false` | no |
206207
| <a name="input_existing_cloudtrail_config"></a> [existing\_cloudtrail\_config](#input\_existing\_cloudtrail\_config) | Optional block. If not set, a new cloudtrail, sns and sqs resources will be created in the **management account**.<br>If provided through Option 1, resources (cloudtrail,cloudtrail-s3) must exist in the management account.<br>Option 2, is mandatory to be used when the cloudtrail-s3 is in a different account than where SFC worklaod is installed.<br>Option 3, is an alterntive to Option1, to be able to ingest events through cloudtrail-s3-sns subscribed SQS, instead of just cloudtrail-sns<br>Check [use-cases](https://github.com/sysdiglabs/terraform-aws-secure-for-cloud/tree/master/use-cases) for proper permission setup.<br><ul><br> <li>cloudtrail\_s3\_arn: Optional 1. ARN of a pre-existing cloudtrail\_sns s3 bucket. Used together with `cloudtrail_sns_arn`, `cloudtrail_s3_arn`. If it does not exist, it will be inferred from create cloudtrail"</li><br> <li>cloudtrail\_sns\_arn: Optional 1. ARN of a pre-existing cloudtrail\_sns. Used together with `cloudtrail_sns_arn`, `cloudtrail_s3_arn`. If it does not exist, it will be inferred from created cloudtrail. Providing an ARN requires permission to SNS:Subscribe, check ./modules/infrastructure/cloudtrail/sns\_permissions.tf block</li><br> <li>cloudtrail\_s3\_role\_arn: Optional 2. ARN of the role to be assumed for S3 access. This role must be in the same account of the S3 bucket. Currently this setup is not compatible with organizational scanning feature</li><br> <li>cloudtrail\_s3\_sns\_sqs\_arn: Optional 3. ARN of the queue that will ingest events forwarded from an existing cloudtrail\_s3\_sns</li><br> <li>cloudtrail\_s3\_sns\_sqs\_url: Optional 3. URL of the queue that will ingest events forwarded from an existing cloudtrail\_s3\_sns<</li><br></ul> | <pre>object({<br> cloudtrail_s3_arn = optional(string)<br> cloudtrail_sns_arn = optional(string)<br> cloudtrail_s3_role_arn = optional(string)<br> cloudtrail_s3_sns_sqs_arn = optional(string)<br> cloudtrail_s3_sns_sqs_url = optional(string)<br> })</pre> | <pre>{<br> "cloudtrail_s3_arn": "create",<br> "cloudtrail_s3_role_arn": null,<br> "cloudtrail_s3_sns_sqs_arn": null,<br> "cloudtrail_s3_sns_sqs_url": null,<br> "cloudtrail_sns_arn": "create"<br>}</pre> | no |
207-
| <a name="input_max_replicas"></a> [max\_replicas](#input\_max\_replicas) | If autoscaling is enabled, this is the maximum number of replicas to run | `number` | `30` | no |
208-
| <a name="input_min_replicas"></a> [min\_replicas](#input\_min\_replicas) | If autoscaling is enabled, this is the minimum number of replicas to run | `number` | `1` | no |
209208
| <a name="input_name"></a> [name](#input\_name) | Name to be assigned to all child resources. A suffix may be added internally when required. Use default value unless you need to install multiple instances | `string` | `"sfc"` | no |
210209
| <a name="input_organizational_member_default_admin_role"></a> [organizational\_member\_default\_admin\_role](#input\_organizational\_member\_default\_admin\_role) | Default role created by AWS for management-account users to be able to admin member accounts.<br/>https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_accounts_access.html | `string` | `"OrganizationAccountAccessRole"` | no |
211210
| <a name="input_tags"></a> [tags](#input\_tags) | customization of tags to be assigned to all resources. <br/>always include 'product' default tag for resource-group proper functioning.<br/>can also make use of the [provider-level `default-tags`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags) | `map(string)` | <pre>{<br> "product": "sysdig-secure-for-cloud"<br>}</pre> | no |

Diff for: examples/organizational/main.tf

+6-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ module "cloud_connector" {
104104
ecs_task_memory = var.ecs_task_memory
105105

106106
enable_autoscaling = var.enable_autoscaling
107-
max_replicas = var.max_replicas
108-
min_replicas = var.min_replicas
107+
autoscaling_config = {
108+
min_replicas = var.autoscaling_config.min_replicas
109+
max_replicas = var.autoscaling_config.max_replicas
110+
upscale_threshold = var.autoscaling_config.upscale_threshold
111+
downscale_threshold = var.autoscaling_config.downscale_threshold
112+
}
109113

110114
tags = var.tags
111115
depends_on = [local.cloudtrail_sns_arn, module.ssm]

Diff for: examples/organizational/variables.tf

+14-10
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,19 @@ variable "enable_autoscaling" {
198198
default = false
199199
}
200200

201+
variable "autoscaling_config" {
202+
type = object({
203+
min_replicas = number
204+
max_replicas = number
205+
upscale_threshold = number
206+
downscale_threshold = number
207+
})
201208

202-
variable "min_replicas" {
203-
type = number
204-
default = 1
205-
description = "If autoscaling is enabled, this is the minimum number of replicas to run"
206-
}
207-
208-
variable "max_replicas" {
209-
type = number
210-
default = 30
211-
description = "If autoscaling is enabled, this is the maximum number of replicas to run"
209+
default = {
210+
min_replicas = 2
211+
max_replicas = 15
212+
upscale_threshold = 60
213+
downscale_threshold = 30
214+
}
215+
description = "if enable_autoscaliing is enabled, ECS autoscaling configuration. for more insight check source code"
212216
}

Diff for: examples/single-account-ecs/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ $ terraform apply
9797

9898
| Name | Description | Type | Default | Required |
9999
|------|-------------|------|---------|:--------:|
100+
| <a name="input_autoscaling_config"></a> [autoscaling\_config](#input\_autoscaling\_config) | if enable\_autoscaliing is enabled, ECS autoscaling configuration. for more insight check source code | <pre>object({<br> min_replicas = number<br> max_replicas = number<br> upscale_threshold = number<br> downscale_threshold = number<br> })</pre> | <pre>{<br> "downscale_threshold": 30,<br> "max_replicas": 10,<br> "min_replicas": 1,<br> "upscale_threshold": 60<br>}</pre> | no |
100101
| <a name="input_benchmark_regions"></a> [benchmark\_regions](#input\_benchmark\_regions) | List of regions in which to run the benchmark. If empty, the task will contain all aws regions by default. | `list(string)` | `[]` | no |
101102
| <a name="input_cloud_connector_image"></a> [cloud\_connector\_image](#input\_cloud\_connector\_image) | Image to use for the cloud connector. If empty, the default image will be used. | `string` | `"quay.io/sysdig/cloud-connector:latest"` | no |
102103
| <a name="input_cloudtrail_is_multi_region_trail"></a> [cloudtrail\_is\_multi\_region\_trail](#input\_cloudtrail\_is\_multi\_region\_trail) | true/false whether cloudtrail will ingest multiregional events | `bool` | `true` | no |
@@ -114,8 +115,6 @@ $ terraform apply
114115
| <a name="input_ecs_vpc_region_azs"></a> [ecs\_vpc\_region\_azs](#input\_ecs\_vpc\_region\_azs) | List of Availability Zones for ECS VPC creation. e.g.: ["apne1-az1", "apne1-az2"]. If defaulted, two of the default 'aws\_availability\_zones' datasource will be taken | `list(string)` | `[]` | no |
115116
| <a name="input_ecs_vpc_subnets_private_ids"></a> [ecs\_vpc\_subnets\_private\_ids](#input\_ecs\_vpc\_subnets\_private\_ids) | List of VPC subnets where workload is to be deployed. If defaulted new subnets will be created within the VPC. A minimum of two subnets is suggested. If specified all three parameters `ecs_cluster_name`, `ecs_vpc_id` and `ecs_vpc_subnets_private_ids` are required. | `list(string)` | `[]` | no |
116117
| <a name="input_enable_autoscaling"></a> [enable\_autoscaling](#input\_enable\_autoscaling) | Whether to enable autoscaling or not | `bool` | `false` | no |
117-
| <a name="input_max_replicas"></a> [max\_replicas](#input\_max\_replicas) | If autoscaling is enabled, this is the maximum number of replicas to run | `number` | `10` | no |
118-
| <a name="input_min_replicas"></a> [min\_replicas](#input\_min\_replicas) | If autoscaling is enabled, this is the minimum number of replicas to run | `number` | `1` | no |
119118
| <a name="input_name"></a> [name](#input\_name) | Name to be assigned to all child resources. A suffix may be added internally when required. Use default value unless you need to install multiple instances | `string` | `"sfc"` | no |
120119
| <a name="input_tags"></a> [tags](#input\_tags) | customization of tags to be assigned to all resources. <br/>always include 'product' default tag for resource-group proper functioning.<br/>can also make use of the [provider-level `default-tags`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags) | `map(string)` | <pre>{<br> "product": "sysdig-secure-for-cloud"<br>}</pre> | no |
121120

Diff for: examples/single-account-ecs/main.tf

+6-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ module "cloud_connector" {
6868
depends_on = [local.cloudtrail_sns_arn, module.ssm]
6969

7070
enable_autoscaling = var.enable_autoscaling
71-
min_replicas = var.min_replicas
72-
max_replicas = var.max_replicas
71+
autoscaling_config = {
72+
min_replicas = var.autoscaling_config.min_replicas
73+
max_replicas = var.autoscaling_config.max_replicas
74+
upscale_threshold = var.autoscaling_config.upscale_threshold
75+
downscale_threshold = var.autoscaling_config.downscale_threshold
76+
}
7377
}

Diff for: examples/single-account-ecs/variables.tf

+14-10
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,19 @@ variable "enable_autoscaling" {
146146
default = false
147147
}
148148

149+
variable "autoscaling_config" {
150+
type = object({
151+
min_replicas = number
152+
max_replicas = number
153+
upscale_threshold = number
154+
downscale_threshold = number
155+
})
149156

150-
variable "min_replicas" {
151-
type = number
152-
default = 1
153-
description = "If autoscaling is enabled, this is the minimum number of replicas to run"
154-
}
155-
156-
variable "max_replicas" {
157-
type = number
158-
default = 10
159-
description = "If autoscaling is enabled, this is the maximum number of replicas to run"
157+
default = {
158+
min_replicas = 1
159+
max_replicas = 10
160+
upscale_threshold = 60
161+
downscale_threshold = 30
162+
}
163+
description = "if enable_autoscaliing is enabled, ECS autoscaling configuration. for more insight check source code"
160164
}

0 commit comments

Comments
 (0)