Skip to content

Commit

Permalink
fix: ECS autoscale (#159)
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
iru authored Jan 30, 2023
1 parent 9ce1dd3 commit 0ce09a9
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 176 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/ci-integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,6 @@ jobs:
if: ${{ failure() }}
run: bundle exec kitchen destroy "organizational-aws"


- name: Run organizational-single test
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_QA_MANAGED_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_QA_MANAGED_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
TF_VAR_sysdig_secure_for_cloud_member_account_id: ${{ secrets.AWS_QA_CLOUDNATIVE_ACCOUNT_ID }}
run: bundle exec kitchen test "organizational-single-aws"

- name: Destroy organizational-single resources
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_QA_MANAGED_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_QA_MANAGED_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
TF_VAR_sysdig_secure_for_cloud_member_account_id: ${{ secrets.AWS_QA_CLOUDNATIVE_ACCOUNT_ID }}
if: ${{ failure() }}
run: bundle exec kitchen destroy "organizational-single-aws"
integration_test_app_runner:
needs: integration_test_ecs
concurrency: terraform-account
Expand Down
3 changes: 0 additions & 3 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ suites:
- name: organizational-k8s
driver:
root_module_directory: test/fixtures/organizational-k8s
- name: organizational-single
driver:
root_module_directory: test/fixtures/organizational-single
- name: single-account-apprunner
driver:
root_module_directory: test/fixtures/single-account-apprunner
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ Error: Not enough privileges to complete the action, Access is denied
│ 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:
│ * Account(***) Region(us - east - 1) Status(SUCCEEDED) Status Reason: No updates are to be performed.
│ * Account(***) Region(us - east - 1) Status(FAILED) Status Reason: Account *** should have
│ * Account(***) Region(us - east - 1) Status(FAILED) Status Reason: Account *** should have
'stacksets-exec-70e2f8a88d368a5d3df60f4eb8c247dc' role with trust relationship to Role 'aws-service-role/stacksets.cloudformation.amazonaws.com/AWSServiceRoleForCloudFormationStackSetsOrgAdmin
```
Expand Down
3 changes: 1 addition & 2 deletions examples/organizational/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ $ terraform apply
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand All @@ -204,8 +205,6 @@ $ terraform apply
| <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 |
| <a name="input_enable_autoscaling"></a> [enable\_autoscaling](#input\_enable\_autoscaling) | Whether to enable autoscaling or not | `bool` | `false` | no |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
8 changes: 6 additions & 2 deletions examples/organizational/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ module "cloud_connector" {
ecs_task_memory = var.ecs_task_memory

enable_autoscaling = var.enable_autoscaling
max_replicas = var.max_replicas
min_replicas = var.min_replicas
autoscaling_config = {
min_replicas = var.autoscaling_config.min_replicas
max_replicas = var.autoscaling_config.max_replicas
upscale_threshold = var.autoscaling_config.upscale_threshold
downscale_threshold = var.autoscaling_config.downscale_threshold
}

tags = var.tags
depends_on = [local.cloudtrail_sns_arn, module.ssm]
Expand Down
24 changes: 14 additions & 10 deletions examples/organizational/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,19 @@ variable "enable_autoscaling" {
default = false
}

variable "autoscaling_config" {
type = object({
min_replicas = number
max_replicas = number
upscale_threshold = number
downscale_threshold = number
})

variable "min_replicas" {
type = number
default = 1
description = "If autoscaling is enabled, this is the minimum number of replicas to run"
}

variable "max_replicas" {
type = number
default = 30
description = "If autoscaling is enabled, this is the maximum number of replicas to run"
default = {
min_replicas = 2
max_replicas = 15
upscale_threshold = 60
downscale_threshold = 30
}
description = "if enable_autoscaliing is enabled, ECS autoscaling configuration. for more insight check source code"
}
3 changes: 1 addition & 2 deletions examples/single-account-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ $ terraform apply

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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 |
| <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 |
| <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 |
| <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 |
Expand All @@ -114,8 +115,6 @@ $ terraform apply
| <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 |
| <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 |
| <a name="input_enable_autoscaling"></a> [enable\_autoscaling](#input\_enable\_autoscaling) | Whether to enable autoscaling or not | `bool` | `false` | no |
| <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 |
| <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 |
| <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 |
| <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 |

Expand Down
8 changes: 6 additions & 2 deletions examples/single-account-ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ module "cloud_connector" {
depends_on = [local.cloudtrail_sns_arn, module.ssm]

enable_autoscaling = var.enable_autoscaling
min_replicas = var.min_replicas
max_replicas = var.max_replicas
autoscaling_config = {
min_replicas = var.autoscaling_config.min_replicas
max_replicas = var.autoscaling_config.max_replicas
upscale_threshold = var.autoscaling_config.upscale_threshold
downscale_threshold = var.autoscaling_config.downscale_threshold
}
}
24 changes: 14 additions & 10 deletions examples/single-account-ecs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,19 @@ variable "enable_autoscaling" {
default = false
}

variable "autoscaling_config" {
type = object({
min_replicas = number
max_replicas = number
upscale_threshold = number
downscale_threshold = number
})

variable "min_replicas" {
type = number
default = 1
description = "If autoscaling is enabled, this is the minimum number of replicas to run"
}

variable "max_replicas" {
type = number
default = 10
description = "If autoscaling is enabled, this is the maximum number of replicas to run"
default = {
min_replicas = 1
max_replicas = 10
upscale_threshold = 60
downscale_threshold = 30
}
description = "if enable_autoscaliing is enabled, ECS autoscaling configuration. for more insight check source code"
}
Loading

0 comments on commit 0ce09a9

Please sign in to comment.