![](/img/trans.png)
[英]How to add Tags to ECS existing Service, Task definition using Terraform
[英]Running a new task with terraform without a service in ecs
您必须使用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.