1

I have an AWS Batch compute environment defined in my Terraform files. The creation of the compute environment creates an ECS Cluster, where the containers are being run.

The issue I have with Terraform, is that while the aws_batch_compute_environment resource is managed by Terraform, then the aws_ecs_cluster which is created from it is not.

I want to enable ContainerInsights on this cluster, but because it is not managed I am struggling to understand how to do it.

This is how my Batch compute environment is currently defined:

resource "aws_batch_compute_environment" "fargate-batch-compute" {
  compute_environment_name = "fargate-batch-compute"

  compute_resources {
    max_vcpus          = 100
    security_group_ids = [...]
    subnets            = [...]
    type               = "FARGATE"
  }

  type = "MANAGED"
}

This is how to easily enable ContainerInsights on an ECS cluster using Terraform:

resource "aws_ecs_cluster" "foo" {
  name = ""

  setting {
    name  = "containerInsights"
    value = "enabled"
  }
}

Notes:

  • I checked and it seems that it's not possible to pass an existing ECS cluster to the creation of the compute environment - Reference

2 Answers 2

0

The only solution I found is to import the created resource in AWS to a new configured resource in your Terraform configuration.

If the newly created ECS Cluster is named AWSBatch-foo-123456 than append to your Terraform configuration the following resource:

resource "aws_ecs_cluster" "foo-cluster" {
  name = "AWSBatch-foo-123456"
  
  setting {
    name  = "containerInsights"
    value = "enabled"
  }
}

and then execute terraform import aws_ecs_cluster.foo-cluster AWSBatch-foo-123456.

Now, the ECS cluster will be managed by Terraform and you can apply any setting on it.

0

You can also enable container insights in the account settings of Amazon Elastic Container Service.

resource "aws_ecs_account_setting_default" "container_insights" {
  name  = "containerInsights"
  value = "enabled"
}

When you opt in to the containerInsights account setting, all new clusters have Container Insights enabled by default. As far as I see, you must enable it manually for existing clusters.

See also this docs page if you want to enable it via the AWS Console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.