Skip to content

Commit 0ba06c8

Browse files
authored
feat: Add Support for Alternative Partitions in ARNs (like govcloud) (#1815)
* arn partition is not always aws * correct typo * missed a variable handoff * missing CR at the end * updates to formatting and docs from tflint and terraform-docs
1 parent d3e6950 commit 0ba06c8

18 files changed

+53
-20
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ In case the setup does not work as intended follow the trace of events:
395395
|------|-------------|------|---------|:--------:|
396396
| <a name="input_ami_filter"></a> [ami\_filter](#input\_ami\_filter) | List of maps used to create the AMI filter for the action runner AMI. By default amazon linux 2 is used. | `map(list(string))` | `null` | no |
397397
| <a name="input_ami_owners"></a> [ami\_owners](#input\_ami\_owners) | The list of owners used to select the AMI of action runner instances. | `list(string)` | <pre>[<br> "amazon"<br>]</pre> | no |
398+
| <a name="input_aws_partition"></a> [aws\_partition](#input\_aws\_partition) | (optiona) partition in the arn namespace to use if not 'aws' | `string` | `"aws"` | no |
398399
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region. | `string` | n/a | yes |
399400
| <a name="input_block_device_mappings"></a> [block\_device\_mappings](#input\_block\_device\_mappings) | The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops` | `map(string)` | `{}` | no |
400401
| <a name="input_cloudwatch_config"></a> [cloudwatch\_config](#input\_cloudwatch\_config) | (optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details. | `string` | `null` | no |

main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ module "webhook" {
8383
module "runners" {
8484
source = "./modules/runners"
8585

86-
aws_region = var.aws_region
87-
vpc_id = var.vpc_id
88-
subnet_ids = var.subnet_ids
89-
environment = var.environment
90-
tags = local.tags
86+
aws_region = var.aws_region
87+
aws_partition = var.aws_partition
88+
vpc_id = var.vpc_id
89+
subnet_ids = var.subnet_ids
90+
environment = var.environment
91+
tags = local.tags
9192

9293
s3_bucket_runner_binaries = module.runner_binaries.bucket
9394
s3_location_runner_binaries = local.s3_action_runner_url

modules/runners/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ yarn run dist
115115
|------|-------------|------|---------|:--------:|
116116
| <a name="input_ami_filter"></a> [ami\_filter](#input\_ami\_filter) | Map of lists used to create the AMI filter for the action runner AMI. | `map(list(string))` | `null` | no |
117117
| <a name="input_ami_owners"></a> [ami\_owners](#input\_ami\_owners) | The list of owners used to select the AMI of action runner instances. | `list(string)` | <pre>[<br> "amazon"<br>]</pre> | no |
118+
| <a name="input_aws_partition"></a> [aws\_partition](#input\_aws\_partition) | (optional) partition for the base arn if not 'aws' | `string` | `"aws"` | no |
118119
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region. | `string` | n/a | yes |
119120
| <a name="input_block_device_mappings"></a> [block\_device\_mappings](#input\_block\_device\_mappings) | The EC2 instance block device configuration. Takes the following keys: `device_name`, `delete_on_termination`, `volume_type`, `volume_size`, `encrypted`, `iops` | `map(string)` | `{}` | no |
120121
| <a name="input_cloudwatch_config"></a> [cloudwatch\_config](#input\_cloudwatch\_config) | (optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details. | `string` | `null` | no |

modules/runners/policies-runner.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ resource "aws_iam_role_policy" "ssm_parameters" {
2626
role = aws_iam_role.runner.name
2727
policy = templatefile("${path.module}/policies/instance-ssm-parameters-policy.json",
2828
{
29-
arn_ssm_parameters_prefix = "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${var.environment}-*"
30-
arn_ssm_parameters_path = "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${var.environment}/*"
29+
arn_ssm_parameters_prefix = "arn:${var.aws_partition}:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${var.environment}-*"
30+
arn_ssm_parameters_path = "arn:${var.aws_partition}:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${var.environment}/*"
3131
}
3232
)
3333
}

modules/runners/policies/service-linked-role-create-policy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"Effect": "Allow",
66
"Action": "iam:CreateServiceLinkedRole",
7-
"Resource": "arn:aws:iam::*:role/aws-service-role/*"
7+
"Resource": "arn:${aws_partition}:iam::*:role/aws-service-role/*"
88
}
99
]
1010
}

modules/runners/pool.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ module "pool" {
4444
tags = local.tags
4545
}
4646

47+
aws_partition = var.aws_partition
48+
4749
}

modules/runners/pool/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ resource "aws_iam_role_policy" "pool_logging" {
8282
resource "aws_iam_role_policy_attachment" "pool_vpc_execution_role" {
8383
count = length(var.config.lambda.subnet_ids) > 0 ? 1 : 0
8484
role = aws_iam_role.pool.name
85-
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
85+
policy_arn = "arn:${var.aws_partition}:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
8686
}
8787

8888
data "aws_iam_policy_document" "lambda_assume_role_policy" {

modules/runners/pool/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ variable "config" {
5050
role_path = string
5151
})
5252
}
53+
54+
variable "aws_partition" {
55+
description = "(optional) partition for the arn if not 'aws'"
56+
type = string
57+
default = "aws"
58+
}

modules/runners/scale-down.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,5 @@ resource "aws_iam_role_policy" "scale_down_logging" {
9797
resource "aws_iam_role_policy_attachment" "scale_down_vpc_execution_role" {
9898
count = length(var.lambda_subnet_ids) > 0 ? 1 : 0
9999
role = aws_iam_role.scale_down.name
100-
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
100+
policy_arn = "arn:${var.aws_partition}:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
101101
}

modules/runners/scale-up.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ resource "aws_iam_role_policy" "service_linked_role" {
9999
count = var.create_service_linked_role_spot ? 1 : 0
100100
name = "${var.environment}-service_linked_role"
101101
role = aws_iam_role.scale_up.name
102-
policy = templatefile("${path.module}/policies/service-linked-role-create-policy.json", {})
102+
policy = templatefile("${path.module}/policies/service-linked-role-create-policy.json", { aws_partition = var.aws_partition })
103103
}
104104

105105
resource "aws_iam_role_policy_attachment" "scale_up_vpc_execution_role" {
106106
count = length(var.lambda_subnet_ids) > 0 ? 1 : 0
107107
role = aws_iam_role.scale_up.name
108-
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
108+
policy_arn = "arn:${var.aws_partition}:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
109109
}

0 commit comments

Comments
 (0)