Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run ECS tasks using terraform?

I recently started getting into the devops side of things and am currently working with Terraform and AWS ECS to setup a simple web server host my web applications.

Using my current Terraform config I can see my cluster being created with a service that has my task definition. I can't figure out how to run the tasks required to launch the webserver from Terraform. I can only see the capability to create the task definitions and services, but not run them. I am very new to both these technologies so I fear I might be missing something simple.

The setup I used is from an example I found online that I tried to follow.

TL;DR: I can create services using Terraform but can't seem to figure out how to run them.

like image 823
bos570 Avatar asked Sep 26 '19 20:09

bos570


2 Answers

You need define an "aws_ecs_service" resource in Terraform and in there define how many instances of your task you want running. In the example you link, that is done in the main.tf file here.

like image 178
Mark B Avatar answered Sep 20 '22 07:09

Mark B


There is no way you can run the task from terraform except running the external script or aws-cli from the local-exec provisioner.

like image 27
mohit Avatar answered Sep 21 '22 07:09

mohit