简体   繁体   中英

Uploading file to ECS task

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?

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"}
  ]

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"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM