skip to Main Content

I’m trying to upload a simple .yml file when creating an ECS task via Terraform, here is the code ./main.tf:

resource "aws_ecs_task_definition" "grafana" {
  family                   = "grafana"
  cpu                      = "256"
  memory                   = "512"
  network_mode             = "awsvpc"
  requires_compatibilities = ["FARGATE"]
  container_definitions = jsonencode([
    {
      name  = "grafana"
      image = "grafana/grafana:latest"
      portMappings = [
        {
          containerPort = 3000,
          hostPort      = 3000,
          protocol      = "tcp"
        }
      ]
    }
  ])
}

How do I go about adding ./datasource.yml (located on my host machine) to the container within the task definition so that when the task runs it can use it? I wasn’t sure if volume { } could be used?

2

Answers


  1. I wasn’t sure if volume { } could be used?

    As a matter of fact you can, check the docs https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#example-usage

    volume {
      name      = "grafana-volume"
      host_path = "./datasource.yml"
    }
    
    Login or Signup to reply.
  2. I think you have two alternatives here:

    • rebuild the docker image including your modified datasource.yaml.

    COPY datasource.yaml /usr/share/grafana/conf/provisioning/datasource.yaml

    or

    • mount a volume that you can easily mount and push files programmatically (EFS turns out to be a bit complicated to do this)
    mount_points = [ {
          sourceVolume  = "grafana"
          containerPath = "/var/lib/grafana/conf/provisioning"
          readOnly      = false
        }
      ]
      volumes = [
        {    
         name      = "grafana"
         host_path = "/ecs/grafana-provisioning"}
      ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search