Skip to content

Commit dde5ba9

Browse files
authored
feat: allow adding more trusted principals to task role (#193)
1 parent 6affcb3 commit dde5ba9

File tree

7 files changed

+43
-19
lines changed

7 files changed

+43
-19
lines changed

.github/workflows/pre-commit.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ on:
77
- master
88

99
jobs:
10-
# Min Terraform version(s)
10+
# Min Terraform version(s)
1111
getDirectories:
12-
name: Get root directories
13-
runs-on: ubuntu-latest
14-
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v2
17-
- name: Install Python
18-
uses: actions/setup-python@v2
19-
- name: Build matrix
20-
id: matrix
21-
run: |
22-
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
23-
echo "::set-output name=directories::$DIRS"
24-
outputs:
25-
directories: ${{ steps.matrix.outputs.directories }}
12+
name: Get root directories
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
- name: Install Python
18+
uses: actions/setup-python@v2
19+
- name: Build matrix
20+
id: matrix
21+
run: |
22+
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
23+
echo "::set-output name=directories::$DIRS"
24+
outputs:
25+
directories: ${{ steps.matrix.outputs.directories }}
2626

2727
preCommitMinVersions:
2828
name: Min TF validate
2929
needs: getDirectories
3030
runs-on: ubuntu-latest
3131
strategy:
32-
matrix:
33-
directory: ${{ fromJson(needs.getDirectories.outputs.directories) }}
32+
matrix:
33+
directory: ${{ fromJson(needs.getDirectories.outputs.directories) }}
3434
steps:
3535
- name: Checkout
3636
uses: actions/checkout@v2
@@ -59,7 +59,7 @@ jobs:
5959
pre-commit run terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)
6060

6161

62-
# Max Terraform version
62+
# Max Terraform version
6363
getBaseVersion:
6464
name: Module max TF version
6565
runs-on: ubuntu-latest
@@ -94,7 +94,7 @@ jobs:
9494
- name: Install pre-commit dependencies
9595
run: |
9696
pip install pre-commit
97-
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v0.12.0-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
97+
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v0.12\..+?-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
9898
curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
9999
- name: Execute pre-commit
100100
# Run all pre-commit checks on max version supported

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ allow_github_webhooks = true
314314
| <a name="input_start_timeout"></a> [start\_timeout](#input\_start\_timeout) | Time duration (in seconds) to wait before giving up on resolving dependencies for a container | `number` | `30` | no |
315315
| <a name="input_stop_timeout"></a> [stop\_timeout](#input\_stop\_timeout) | Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own | `number` | `30` | no |
316316
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to use on all resources | `map(string)` | `{}` | no |
317+
| <a name="input_trusted_entities"></a> [trusted\_entities](#input\_trusted\_entities) | A list of users or roles, that can assume the task role | `list(string)` | `[]` | no |
317318
| <a name="input_trusted_principals"></a> [trusted\_principals](#input\_trusted\_principals) | A list of principals, in addition to ecs-tasks.amazonaws.com, that can assume the task role | `list(string)` | `[]` | no |
318319
| <a name="input_ulimits"></a> [ulimits](#input\_ulimits) | Container ulimit settings. This is a list of maps, where each map should contain "name", "hardLimit" and "softLimit" | <pre>list(object({<br> name = string<br> hardLimit = number<br> softLimit = number<br> }))</pre> | `null` | no |
319320
| <a name="input_user"></a> [user](#input\_user) | The user to run as inside the container. Can be any of these formats: user, user:group, uid, uid:gid, user:gid, uid:group. The default (null) will use the container's configured `USER` directive or root if not set. | `string` | `null` | no |

examples/github-complete/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Go to https://eu-west-1.console.aws.amazon.com/ecs/home?region=eu-west-1#/settin
6767
| <a name="input_github_token"></a> [github\_token](#input\_github\_token) | Github token | `string` | n/a | yes |
6868
| <a name="input_github_user"></a> [github\_user](#input\_github\_user) | Github user for Atlantis to utilize when performing Github activities | `string` | n/a | yes |
6969
| <a name="input_region"></a> [region](#input\_region) | AWS region where resources will be created | `string` | `"us-east-1"` | no |
70+
| <a name="input_trusted_entities"></a> [trusted\_entities](#input\_trusted\_entities) | A list of users or roles, that can assume the task role | `list(string)` | `[]` | no |
7071
| <a name="input_trusted_principals"></a> [trusted\_principals](#input\_trusted\_principals) | A list of principals, in addition to ecs-tasks.amazonaws.com, that can assume the task role | `list(string)` | n/a | yes |
7172

7273
## Outputs

examples/github-complete/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module "atlantis" {
6464

6565
# Security
6666
trusted_principals = var.trusted_principals
67+
trusted_entities = var.trusted_entities
6768

6869
# DNS
6970
route53_zone_name = var.domain

examples/github-complete/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ variable "trusted_principals" {
3838
description = "A list of principals, in addition to ecs-tasks.amazonaws.com, that can assume the task role"
3939
type = list(string)
4040
}
41+
42+
variable "trusted_entities" {
43+
description = "A list of users or roles, that can assume the task role"
44+
type = list(string)
45+
default = []
46+
}

main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,15 @@ data "aws_iam_policy_document" "ecs_tasks" {
378378
type = "Service"
379379
identifiers = compact(distinct(concat(["ecs-tasks.amazonaws.com"], var.trusted_principals)))
380380
}
381+
382+
dynamic "principals" {
383+
for_each = length(var.trusted_entities) > 0 ? [true] : []
384+
385+
content {
386+
type = "AWS"
387+
identifiers = var.trusted_entities
388+
}
389+
}
381390
}
382391
}
383392

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ variable "trusted_principals" {
251251
default = []
252252
}
253253

254+
variable "trusted_entities" {
255+
description = "A list of users or roles, that can assume the task role"
256+
type = list(string)
257+
default = []
258+
}
259+
254260
variable "ecs_fargate_spot" {
255261
description = "Whether to run ECS Fargate Spot or not"
256262
type = bool

0 commit comments

Comments
 (0)