PaloAltoNetworks / pcs-sizing-scripts

Prisma Cloud sizing scripts
ISC License
46 stars 49 forks source link

ECS Task is not counted correctly. #49

Open hiroinfinity opened 1 year ago

hiroinfinity commented 1 year ago

Describe the bug

In cwp mode, ECS Task is not counted correctly. The number of ECS Fargate Tasks cannot be obtained correctly in aws-resource-count.sh with cwp option.

Expected behavior

To obtain the correct ECS cluster name and count the number of individual Fargate tasks.

Current behavior

FargateTask per cluster is not get correctly.

Possible solution

Modify the script function "get_ecs_fargate_task_count()". For example, how about modifying the following?

https://github.com/PaloAltoNetworks/pcs-sizing-scripts/blob/main/aws/resource-count-aws.sh#L241-L253

  **ECS_FARGATE_CLUSTERS=($(aws_ecs_list_clusters "${REGION}" | jq -r '.clusterArns[]' 2>/dev/null))**

  XIFS=$IFS
  # shellcheck disable=SC2206
  **IFS=$'\n' ECS_FARGATE_CLUSTERS_LIST=(${ECS_FARGATE_CLUSTERS[@]})**
  IFS=$XIFS

  ECS_FARGATE_TASK_LIST_COUNT=0
  RESULT=0

  for CLUSTER in "${ECS_FARGATE_CLUSTERS_LIST[@]}"
  do
    **ECS_FARGATE_TASK_LIST_COUNT=($(aws_ecs_list_tasks "${REGION}" "${CLUSTER}" | jq -r '[.taskArns[]] | length' 2>/dev/null))**

Steps to reproduce

./resource-count-aws.sh cwp