Skip to content

Commit 5249afc

Browse files
authored
feat: Add support for specifying assume role conditions (#12)
1 parent ea4ae5e commit 5249afc

File tree

7 files changed

+44
-4
lines changed

7 files changed

+44
-4
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.88.2
3+
rev: v1.92.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each
@@ -22,10 +22,9 @@ repos:
2222
- '--args=--only=terraform_required_providers'
2323
- '--args=--only=terraform_standard_module_structure'
2424
- '--args=--only=terraform_workspace_remote'
25-
- '--args=--only=terraform_unused_required_providers'
2625
- id: terraform_validate
2726
- repo: https://github.com/pre-commit/pre-commit-hooks
28-
rev: v4.5.0
27+
rev: v4.6.0
2928
hooks:
3029
- id: check-merge-conflict
3130
- id: end-of-file-fixer

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ module "custom_pod_identity" {
1818
1919
name = "custom"
2020
21+
trust_policy_conditions = [
22+
{
23+
test = "StringEquals"
24+
variable = "aws:PrincipalOrgID"
25+
values = ["o-1234567890"]
26+
}
27+
]
28+
2129
trust_policy_statements = [
2230
{
2331
sid = "Test"
@@ -553,6 +561,7 @@ No modules.
553561
| <a name="input_policy_statements"></a> [policy\_statements](#input\_policy\_statements) | A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) for custom permission usage | `any` | `[]` | no |
554562
| <a name="input_source_policy_documents"></a> [source\_policy\_documents](#input\_source\_policy\_documents) | List of IAM policy documents that are merged together into the exported document | `list(string)` | `[]` | no |
555563
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
564+
| <a name="input_trust_policy_conditions"></a> [trust\_policy\_conditions](#input\_trust\_policy\_conditions) | A list of conditions to add to the role trust policy | `any` | `[]` | no |
556565
| <a name="input_trust_policy_statements"></a> [trust\_policy\_statements](#input\_trust\_policy\_statements) | A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) for the role trust policy | `any` | `[]` | no |
557566
| <a name="input_use_name_prefix"></a> [use\_name\_prefix](#input\_use\_name\_prefix) | Determines whether the role name and policy name(s) are used as a prefix | `string` | `true` | no |
558567
| <a name="input_velero_policy_name"></a> [velero\_policy\_name](#input\_velero\_policy\_name) | Custom name of the Velero IAM policy | `string` | `null` | no |

examples/complete/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ module "custom_pod_identity" {
3636
additional = aws_iam_policy.additional.arn
3737
}
3838

39+
trust_policy_conditions = [
40+
{
41+
test = "StringEquals"
42+
variable = "aws:PrincipalOrgID"
43+
values = ["o-1234567890"]
44+
}
45+
]
46+
3947
associations = {
4048
ex-one = {
4149
cluster_name = module.eks_one.cluster_name

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ data "aws_iam_policy_document" "assume" {
2222
type = "Service"
2323
identifiers = ["pods.eks.amazonaws.com"]
2424
}
25+
26+
dynamic "condition" {
27+
for_each = var.trust_policy_conditions
28+
29+
content {
30+
test = condition.value.test
31+
values = condition.value.values
32+
variable = condition.value.variable
33+
}
34+
}
2535
}
2636

2737
dynamic "statement" {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ variable "tags" {
1414
# IAM Role Trust Policy
1515
################################################################################
1616

17+
variable "trust_policy_conditions" {
18+
description = "A list of conditions to add to the role trust policy"
19+
type = any
20+
default = []
21+
}
22+
1723
variable "trust_policy_statements" {
1824
description = "A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) for the role trust policy"
1925
type = any

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ module "wrapper" {
7272
policy_statements = try(each.value.policy_statements, var.defaults.policy_statements, [])
7373
source_policy_documents = try(each.value.source_policy_documents, var.defaults.source_policy_documents, [])
7474
tags = try(each.value.tags, var.defaults.tags, {})
75+
trust_policy_conditions = try(each.value.trust_policy_conditions, var.defaults.trust_policy_conditions, [])
7576
trust_policy_statements = try(each.value.trust_policy_statements, var.defaults.trust_policy_statements, [])
7677
use_name_prefix = try(each.value.use_name_prefix, var.defaults.use_name_prefix, true)
7778
velero_policy_name = try(each.value.velero_policy_name, var.defaults.velero_policy_name, null)

wrappers/versions.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
terraform {
2-
required_version = ">= 0.13.1"
2+
required_version = ">= 1.3.2"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.30"
8+
}
9+
}
310
}

0 commit comments

Comments
 (0)