0

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

1 Answer 1

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.

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.