-
Notifications
You must be signed in to change notification settings - Fork 13
/
ecs.tf
57 lines (48 loc) · 1.38 KB
/
ecs.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Determine most recent ECS optimized AMI
*/
data "aws_ami" "ecs_ami" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = var.use_amazon_linux2 ? ["amzn2-ami-ecs-hvm-2.0.*-x86_64-ebs"] : ["amzn-ami-*-amazon-ecs-optimized"]
}
}
/*
* Create ECS cluster
*/
resource "aws_ecs_cluster" "ecs_cluster" {
name = var.cluster_name
}
/*
* Create ECS IAM Instance Role and Policy
*/
resource "random_id" "code" {
byte_length = 4
}
resource "aws_iam_role" "ecsInstanceRole" {
name = "ecsInstanceRole-${random_id.code.hex}"
assume_role_policy = var.ecsInstanceRoleAssumeRolePolicy
}
resource "aws_iam_role_policy" "ecsInstanceRolePolicy" {
name = "ecsInstanceRolePolicy-${random_id.code.hex}"
role = aws_iam_role.ecsInstanceRole.id
policy = var.ecsInstancerolePolicy
}
/*
* Create ECS IAM Service Role and Policy
*/
resource "aws_iam_role" "ecsServiceRole" {
name = "ecsServiceRole-${random_id.code.hex}"
assume_role_policy = var.ecsServiceRoleAssumeRolePolicy
}
resource "aws_iam_role_policy" "ecsServiceRolePolicy" {
name = "ecsServiceRolePolicy-${random_id.code.hex}"
role = aws_iam_role.ecsServiceRole.id
policy = var.ecsServiceRolePolicy
}
resource "aws_iam_instance_profile" "ecsInstanceProfile" {
name = "ecsInstanceProfile-${random_id.code.hex}"
role = aws_iam_role.ecsInstanceRole.name
}