diff --git a/README.md b/README.md
index 200a1df..e46d9a0 100644
--- a/README.md
+++ b/README.md
@@ -215,6 +215,7 @@ module "github_runner" {
| [environment\_type](#input\_environment\_type) | Type of build environment to use for related builds. Valid values: `LINUX_CONTAINER`, `LINUX_GPU_CONTAINER`, `WINDOWS_CONTAINER` (deprecated), `WINDOWS_SERVER_2019_CONTAINER`, `ARM_CONTAINER`, `LINUX_LAMBDA_CONTAINER`, `ARM_LAMBDA_CONTAINER` | `string` | `"LINUX_CONTAINER"` | no |
| [github\_personal\_access\_token](#input\_github\_personal\_access\_token) | The GitHub personal access token to use for accessing the repository. If not specified then GitHub auth must be configured separately. | `string` | `null` | no |
| [github\_personal\_access\_token\_ssm\_parameter](#input\_github\_personal\_access\_token\_ssm\_parameter) | The GitHub personal access token to use for accessing the repository. If not specified then GitHub auth must be configured separately. | `string` | `null` | no |
+| [iam\_role\_assume\_role\_policy](#input\_iam\_role\_assume\_role\_policy) | The IAM role assume role policy document to use. If not specified then a default is used. | `string` | `null` | no |
| [iam\_role\_name](#input\_iam\_role\_name) | Name of the IAM role to be used. If not specified then a role will be created | `string` | `null` | no |
| [iam\_role\_permissions\_boundary](#input\_iam\_role\_permissions\_boundary) | ARN of the policy that is used to set the permissions boundary for the IAM service role | `string` | `null` | no |
| [iam\_role\_policies](#input\_iam\_role\_policies) | Map of IAM role policy ARNs to attach to the IAM role | `map(string)` | `{}` | no |
diff --git a/iam.tf b/iam.tf
index 03d7a97..32b5914 100644
--- a/iam.tf
+++ b/iam.tf
@@ -135,26 +135,32 @@ resource "aws_iam_role_policy" "ecr_required" {
}
data "aws_iam_policy_document" "assume_role" {
- count = local.create_iam_role ? 1 : 0
statement {
effect = "Allow"
-
principals {
type = "Service"
identifiers = ["codebuild.amazonaws.com"]
}
-
actions = ["sts:AssumeRole"]
+ condition {
+ test = "StringEquals"
+ variable = "aws:SourceAccount"
+ values = [data.aws_caller_identity.current.account_id]
+ }
}
}
+locals {
+ assume_role_policy = var.iam_role_assume_role_policy == null ? data.aws_iam_policy_document.assume_role.json : var.iam_role_assume_role_policy
+}
+
################################################################################
# Create role
################################################################################
resource "aws_iam_role" "this" {
count = local.create_iam_role ? 1 : 0
name = var.name
- assume_role_policy = data.aws_iam_policy_document.assume_role[0].json
+ assume_role_policy = local.assume_role_policy
permissions_boundary = var.iam_role_permissions_boundary == null ? null : var.iam_role_permissions_boundary
}
diff --git a/variables.tf b/variables.tf
index 1fbf0c6..c909153 100644
--- a/variables.tf
+++ b/variables.tf
@@ -120,6 +120,12 @@ variable "iam_role_name" {
default = null
}
+variable "iam_role_assume_role_policy" {
+ description = "The IAM role assume role policy document to use. If not specified then a default is used."
+ type = string
+ default = null
+}
+
variable "iam_role_policies" {
description = "Map of IAM role policy ARNs to attach to the IAM role"
type = map(string)