Skip to content

Commit bed2231

Browse files
committed
Clean up IAM roles and fix the ECS cluster name
1 parent 82a6287 commit bed2231

File tree

4 files changed

+20
-86
lines changed

4 files changed

+20
-86
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ terraform apply tf.plan
5757

5858
Once everything is running you can try to access the ApplicationLoadBalancer URL and it should show you a screen asking for an initial administrative password. To get this password create a temporary EC2 instance with the security group and IAM instance profile from the output of terraform and mount the EFS share. You will probalby first need to install the efs helper package via yum. Once you have the initial password you can destroy the instance.
5959

60+
When you are done you can destroy everything simply via
61+
```bash
62+
terraform plan -destroy -target=module.serverless_jenkins -out=tf.plan
63+
terraform apply tf.plan
64+
```
65+
6066
## Inputs
6167

6268
| Name | Description | Type | Default | Required |

ecs_cluster.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
#
66

77
resource "aws_ecs_cluster" "jenkins" {
8-
name = "Serverless Jenkins Cluster"
9-
tags = var.tags
8+
name = "ServerlessJenkinsCluster"
9+
tags = var.tags
1010
}

iam.tf

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,31 @@
44
# All rights reserved - Do Not Redistribute
55
#
66

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" {
89
statement {
910
effect = "Allow"
1011

1112
principals {
1213
type = "Service"
13-
identifiers = ["ec2.amazonaws.com"]
14+
identifiers = ["ecs-tasks.amazonaws.com", "ec2.amazonaws.com"]
1415
}
1516

1617
actions = ["sts:AssumeRole"]
1718
}
1819
}
1920

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
2324
}
2425

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"
2829
}
2930

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
7234
}

task_role.tf

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)