How to enable ContainerInsigets (setting) on a Batch compute environment ECS cluster?

Hey, when creating a Batch compute environment in AWS, an ECS cluster is being created as well. But, while the compute environment resource will be managed by Terraform, that ECS cluster won’t be.

That was leading me to an issue, regarding how can I control the settings of this ECS cluster, when this resource is not managed by Terraform.

The only solution I found was to import this resource and link it to a new resource in my Terraform configuration. I had to follow this steps:

  1. Add the Cluster resource in my Terraform configuration
resource "aws_ecs_cluster" "batch-cluster" {
  name = "AWSBatch-cluster..."

  setting {
    name  = "containerInsights"
    value = true
  }
}
  1. Import the actual AWS cluster resource and link it to the resource which was just configured
    terraform import aws_ecs_cluster.batch-cluster AWSBatch-cluster...

  2. Apply and let the new setting take place.
    terraform apply

This solution definitely worked, and I know this might be the only solution, but asking here just in case I missed a simpler or an easier solution.

Thanks

@ohaval I’m having the same issue where I’d like to enable container insights on ECS clusters provisioned by Batch compute environments. Thanks for posting this. Did you find a better solution than above in the end? Thanks!

@theoplatt1
No. Seems like it’s the only solution AMAIK.
A link to a more elaborated answer:

Thanks @ohaval ! I’ve posted another possible solution to that SO link. Setting container insights on at the account level. I’m going to try that.

@theoplatt1
Thanks for adding that answer!
Unfortunately I had to move this question to DevOps StackExchange, because Stackoverflow was not the right place for it.

You are welcome to move your answer to that thread, I will have to delete this question in Stackoverflow in the next couple of days.

Thanks