|
4 | 4 | # All rights reserved - Do Not Redistribute
|
5 | 5 | #
|
6 | 6 |
|
7 |
| -data "aws_iam_policy_document" "container_instance_ec2_assume_role" { |
| 7 | +# Attach this role to any ECS container or EC2 instance to allow full access to the AWS APIs and mounting of the shared EFS |
| 8 | +data "aws_iam_policy_document" "ecs_task_jenkins" { |
8 | 9 | statement {
|
9 | 10 | effect = "Allow"
|
10 | 11 |
|
11 | 12 | principals {
|
12 | 13 | type = "Service"
|
13 |
| - identifiers = ["ec2.amazonaws.com"] |
| 14 | + identifiers = ["ecs-tasks.amazonaws.com", "ec2.amazonaws.com"] |
14 | 15 | }
|
15 | 16 |
|
16 | 17 | actions = ["sts:AssumeRole"]
|
17 | 18 | }
|
18 | 19 | }
|
19 | 20 |
|
20 |
| -resource "aws_iam_role" "container_instance_ec2" { |
21 |
| - name = "ServerlessJenkinsEC2InstanceRole" |
22 |
| - assume_role_policy = data.aws_iam_policy_document.container_instance_ec2_assume_role.json |
| 21 | +resource "aws_iam_role" "ecs_task_jenkins" { |
| 22 | + name = "ServerlessJenkinsECSTaskContainerRole" |
| 23 | + assume_role_policy = data.aws_iam_policy_document.ecs_task_jenkins.json |
23 | 24 | }
|
24 | 25 |
|
25 |
| -resource "aws_iam_role_policy_attachment" "ec2_service_role" { |
26 |
| - role = aws_iam_role.container_instance_ec2.name |
27 |
| - policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role" |
| 26 | +resource "aws_iam_role_policy_attachment" "ecs_task_jenkins" { |
| 27 | + role = aws_iam_role.ecs_task_jenkins.name |
| 28 | + policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess" |
28 | 29 | }
|
29 | 30 |
|
30 |
| -resource "aws_iam_instance_profile" "container_instance" { |
31 |
| - name = "ServerlessJenkinsEC2InstanceProfile" |
32 |
| - role = aws_iam_role.container_instance_ec2.name |
33 |
| -} |
34 |
| - |
35 |
| -# |
36 |
| -# ECS Service IAM permissions |
37 |
| -# |
38 |
| -data "aws_iam_policy_document" "ecs_assume_role" { |
39 |
| - statement { |
40 |
| - effect = "Allow" |
41 |
| - |
42 |
| - principals { |
43 |
| - type = "Service" |
44 |
| - identifiers = ["ecs.amazonaws.com"] |
45 |
| - } |
46 |
| - |
47 |
| - actions = ["sts:AssumeRole"] |
48 |
| - } |
49 |
| -} |
50 |
| - |
51 |
| -resource "aws_iam_role" "ecs_service_role" { |
52 |
| - name = "ServerlessJenkinsECSServiceRole" |
53 |
| - assume_role_policy = data.aws_iam_policy_document.ecs_assume_role.json |
54 |
| -} |
55 |
| - |
56 |
| -resource "aws_iam_role_policy_attachment" "ecs_service_role" { |
57 |
| - role = aws_iam_role.ecs_service_role.name |
58 |
| - policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole" |
59 |
| -} |
60 |
| - |
61 |
| -data "aws_iam_policy_document" "ecs_autoscale_assume_role" { |
62 |
| - statement { |
63 |
| - effect = "Allow" |
64 |
| - |
65 |
| - principals { |
66 |
| - type = "Service" |
67 |
| - identifiers = ["application-autoscaling.amazonaws.com"] |
68 |
| - } |
69 |
| - |
70 |
| - actions = ["sts:AssumeRole"] |
71 |
| - } |
| 31 | +resource "aws_iam_instance_profile" "ec2_jenkins" { |
| 32 | + name = "ServerlessJenkinsEC2AndEFS" |
| 33 | + role = aws_iam_role.ecs_task_jenkins.name |
72 | 34 | }
|
0 commit comments