繁体   English   中英

在没有 ecs 服务的情况下使用 terraform 运行新任务

[英]Running a new task with terraform without a service in ecs

我想通过 terraform 在没有服务的情况下使用 ecs 运行任务。 但是当我执行以下操作时,需要在 terraform 中设置该服务 如何在没有服务的情况下设置任务?

resource "aws_ecs_task_set" "example" {
  cluster         = aws_ecs_cluster.foo.id
  task_definition = aws_ecs_task_definition.fromecr.arn

}

在此处输入图像描述

您必须使用local-exec来运行 AWS CLI 来调用run-task

如果任务定义已经存在,那么您可以使用带有本地执行程序供应器的空资源来运行任务。 (尽管如此,还是要授予必要的权限。下面是解释这一点的代码片段。

resource aws_ecs_task_definition "task_definition" {
      ....
      ....
     // your task definition code.
      ....
      ....
}

resource "null_resource" "migration_task_run" {
  depends_on = [
    aws_ecs_task_definition.task_definition    // to make sure that you run task only after creating the task definition
  ]

  provisioner "local-exec" {
    command = <<EOF
    aws ecs run-task \
      --cluster <<cluster_name>> \
      --task-definition <<task_definition_name>> \
      --count 1 --launch-type FARGATE \
      --network-configuration '{     // This is required if you have chosen awsvpc in network config for your task definition. Else, this can be ignored
      "awsvpcConfiguration": {
      "assignPublicIp":"DISABLED",
      "securityGroups": ["<<security_group>>"],
      "subnets": ["<<your subnets>>"]
      }
      }'
EOF
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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