Skip to content

Commit 2fd94b7

Browse files
committed
feat: Add support for region argument on relevant resources
1 parent 73762df commit 2fd94b7

File tree

17 files changed

+208
-8
lines changed

17 files changed

+208
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ We are grateful to the community for contributing bugfixes and improvements! Ple
443443
| <a name="input_kms_key_service_users"></a> [kms\_key\_service\_users](#input\_kms\_key\_service\_users) | A list of IAM ARNs for [key service users](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-service-integration) | `list(string)` | `[]` | no |
444444
| <a name="input_kms_key_source_policy_documents"></a> [kms\_key\_source\_policy\_documents](#input\_kms\_key\_source\_policy\_documents) | List of IAM policy documents that are merged together into the exported document. Statements must have unique `sid`s | `list(string)` | `[]` | no |
445445
| <a name="input_kms_key_users"></a> [kms\_key\_users](#input\_kms\_key\_users) | A list of IAM ARNs for [key users](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-default-allow-users) | `list(string)` | `[]` | no |
446-
| <a name="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version) | Kubernetes `<major>.<minor>` version to use for the EKS cluster (i.e.: `1.27`) | `string` | `null` | no |
446+
| <a name="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version) | Kubernetes `<major>.<minor>` version to use for the EKS cluster (i.e.: `1.33`) | `string` | `null` | no |
447447
| <a name="input_name"></a> [name](#input\_name) | Name of the EKS cluster | `string` | `""` | no |
448448
| <a name="input_node_iam_role_additional_policies"></a> [node\_iam\_role\_additional\_policies](#input\_node\_iam\_role\_additional\_policies) | Additional policies to be added to the EKS Auto node IAM role | `map(string)` | `{}` | no |
449449
| <a name="input_node_iam_role_description"></a> [node\_iam\_role\_description](#input\_node\_iam\_role\_description) | Description of the EKS Auto node IAM role | `string` | `null` | no |
@@ -463,6 +463,7 @@ We are grateful to the community for contributing bugfixes and improvements! Ple
463463
| <a name="input_outpost_config"></a> [outpost\_config](#input\_outpost\_config) | Configuration for the AWS Outpost to provision the cluster on | <pre>object({<br/> control_plane_instance_type = optional(string)<br/> control_plane_placement = optional(object({<br/> group_name = string<br/> }))<br/> outpost_arns = list(string)<br/> })</pre> | `null` | no |
464464
| <a name="input_prefix_separator"></a> [prefix\_separator](#input\_prefix\_separator) | The separator to use between the prefix and the generated timestamp for resource names | `string` | `"-"` | no |
465465
| <a name="input_putin_khuylo"></a> [putin\_khuylo](#input\_putin\_khuylo) | Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! | `bool` | `true` | no |
466+
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
466467
| <a name="input_remote_network_config"></a> [remote\_network\_config](#input\_remote\_network\_config) | Configuration block for the cluster remote network configuration | <pre>object({<br/> remote_node_networks = object({<br/> cidrs = optional(list(string))<br/> })<br/> remote_pod_networks = optional(object({<br/> cidrs = optional(list(string))<br/> }))<br/> })</pre> | `null` | no |
467468
| <a name="input_security_group_additional_rules"></a> [security\_group\_additional\_rules](#input\_security\_group\_additional\_rules) | List of additional security group rules to add to the cluster security group created. Set `source_node_security_group = true` inside rules to set the `node_security_group` as source | <pre>map(object({<br/> protocol = optional(string, "tcp")<br/> from_port = number<br/> to_port = number<br/> type = optional(string, "ingress")<br/> description = optional(string)<br/> cidr_blocks = optional(list(string))<br/> ipv6_cidr_blocks = optional(list(string))<br/> prefix_list_ids = optional(list(string))<br/> self = optional(bool)<br/> source_node_security_group = optional(bool, false)<br/> source_security_group_id = optional(string)<br/> }))</pre> | `{}` | no |
468469
| <a name="input_security_group_description"></a> [security\_group\_description](#input\_security\_group\_description) | Description of the cluster security group created | `string` | `"EKS cluster security group"` | no |

docs/UPGRADE-21.0.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Upgrade from v20.x to v21.x
2+
3+
If you have any questions regarding this upgrade process, please consult the [`examples`](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples) directory:
4+
If you find a bug, please open an issue with supporting configuration to reproduce.
5+
6+
## List of backwards incompatible changes
7+
8+
- Terraform `v1.5.7` is now minimum supported version
9+
- AWS provider `v6.0.0` is now minimum supported version
10+
11+
## Additional changes
12+
13+
### Added
14+
15+
- Support for `region` parameter to specify the AWS region for the resources created if different from the provider region.
16+
17+
### Modified
18+
19+
- Variable definitions now contain detailed `object` types in place of the previously used any type.
20+
21+
### Variable and output changes
22+
23+
1. Removed variables:
24+
25+
-
26+
27+
2. Renamed variables:
28+
29+
-
30+
31+
3. Added variables:
32+
33+
-
34+
35+
4. Removed outputs:
36+
37+
-
38+
39+
5. Renamed outputs:
40+
41+
-
42+
43+
6. Added outputs:
44+
45+
-
46+
47+
## Upgrade Migrations
48+
49+
### Before 20.x Example
50+
51+
```hcl
52+
module "eks" {
53+
source = "terraform-aws-modules/eks/aws"
54+
version = "~> 20.0"
55+
56+
# Truncated for brevity ...
57+
58+
}
59+
```
60+
61+
### After 21.x Example
62+
63+
```hcl
64+
module "eks" {
65+
source = "terraform-aws-modules/eks/aws"
66+
version = "~> 21.0"
67+
68+
# Truncated for brevity ...
69+
70+
}
71+
```
72+
73+
### State Changes

main.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ locals {
3636
resource "aws_eks_cluster" "this" {
3737
count = local.create ? 1 : 0
3838

39+
region = var.region
40+
3941
name = var.name
4042
role_arn = local.role_arn
4143
version = var.kubernetes_version
@@ -210,6 +212,8 @@ resource "aws_ec2_tag" "cluster_primary_security_group" {
210212
k => v if local.create && k != "Name" && var.create_primary_security_group_tags
211213
}
212214

215+
region = var.region
216+
213217
resource_id = aws_eks_cluster.this[0].vpc_config[0].cluster_security_group_id
214218
key = each.key
215219
value = each.value
@@ -218,6 +222,8 @@ resource "aws_ec2_tag" "cluster_primary_security_group" {
218222
resource "aws_cloudwatch_log_group" "this" {
219223
count = local.create && var.create_cloudwatch_log_group ? 1 : 0
220224

225+
region = var.region
226+
221227
name = "/aws/eks/${var.name}/cluster"
222228
retention_in_days = var.cloudwatch_log_group_retention_in_days
223229
kms_key_id = var.cloudwatch_log_group_kms_key_id
@@ -283,6 +289,8 @@ locals {
283289
resource "aws_eks_access_entry" "this" {
284290
for_each = { for k, v in local.merged_access_entries : k => v if local.create }
285291

292+
region = var.region
293+
286294
cluster_name = aws_eks_cluster.this[0].id
287295
kubernetes_groups = try(each.value.kubernetes_groups, null)
288296
principal_arn = each.value.principal_arn
@@ -298,6 +306,8 @@ resource "aws_eks_access_entry" "this" {
298306
resource "aws_eks_access_policy_association" "this" {
299307
for_each = { for k, v in local.flattened_access_entries : "${v.entry_key}_${v.pol_key}" => v if local.create }
300308

309+
region = var.region
310+
301311
access_scope {
302312
namespaces = each.value.association_access_scope_namespaces
303313
type = each.value.association_access_scope_type
@@ -323,6 +333,8 @@ module "kms" {
323333

324334
create = local.create && var.create_kms_key && local.enable_encryption_config # not valid on Outposts
325335

336+
region = var.region
337+
326338
description = coalesce(var.kms_key_description, "${var.name} cluster encryption key")
327339
key_usage = "ENCRYPT_DECRYPT"
328340
deletion_window_in_days = var.kms_key_deletion_window_in_days
@@ -377,6 +389,8 @@ locals {
377389
resource "aws_security_group" "cluster" {
378390
count = local.create_security_group ? 1 : 0
379391

392+
region = var.region
393+
380394
name = var.security_group_use_name_prefix ? null : local.security_group_name
381395
name_prefix = var.security_group_use_name_prefix ? "${local.security_group_name}${var.prefix_separator}" : null
382396
description = var.security_group_description
@@ -399,6 +413,8 @@ resource "aws_security_group_rule" "cluster" {
399413
var.security_group_additional_rules
400414
) : k => v if local.create_security_group }
401415

416+
region = var.region
417+
402418
security_group_id = aws_security_group.cluster[0].id
403419
protocol = each.value.protocol
404420
from_port = each.value.from_port
@@ -734,6 +750,8 @@ resource "aws_iam_role_policy_attachment" "custom" {
734750
data "aws_eks_addon_version" "this" {
735751
for_each = var.addons != null && local.create && !local.create_outposts_local_cluster ? var.addons : {}
736752

753+
region = var.region
754+
737755
addon_name = coalesce(each.value.name, each.key)
738756
kubernetes_version = coalesce(var.kubernetes_version, aws_eks_cluster.this[0].version)
739757
most_recent = each.value.most_recent
@@ -743,6 +761,8 @@ resource "aws_eks_addon" "this" {
743761
# Not supported on outposts
744762
for_each = var.addons != null && local.create && !local.create_outposts_local_cluster ? { for k, v in var.addons : k => v if !v.before_compute } : {}
745763

764+
region = var.region
765+
746766
cluster_name = aws_eks_cluster.this[0].id
747767
addon_name = coalesce(each.value.name, each.key)
748768

@@ -786,6 +806,8 @@ resource "aws_eks_addon" "before_compute" {
786806
# Not supported on outposts
787807
for_each = var.addons != null && local.create && !local.create_outposts_local_cluster ? { for k, v in var.addons : k => v if v.before_compute } : {}
788808

809+
region = var.region
810+
789811
cluster_name = aws_eks_cluster.this[0].id
790812
addon_name = coalesce(each.value.name, each.key)
791813

@@ -826,6 +848,8 @@ resource "aws_eks_addon" "before_compute" {
826848
resource "aws_eks_identity_provider_config" "this" {
827849
for_each = var.identity_providers != null && local.create && !local.create_outposts_local_cluster ? var.identity_providers : {}
828850

851+
region = var.region
852+
829853
cluster_name = aws_eks_cluster.this[0].id
830854

831855
oidc {

modules/eks-managed-node-group/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ module "eks_managed_node_group" {
177177
| <a name="input_pre_bootstrap_user_data"></a> [pre\_bootstrap\_user\_data](#input\_pre\_bootstrap\_user\_data) | User data that is injected into the user data script ahead of the EKS bootstrap script. Not used when `ami_type` = `BOTTLEROCKET_*` | `string` | `""` | no |
178178
| <a name="input_private_dns_name_options"></a> [private\_dns\_name\_options](#input\_private\_dns\_name\_options) | The options for the instance hostname. The default values are inherited from the subnet | <pre>object({<br/> enable_resource_name_dns_aaaa_record = optional(bool)<br/> enable_resource_name_dns_a_record = optional(bool)<br/> hostname_type = optional(string)<br/> })</pre> | `null` | no |
179179
| <a name="input_ram_disk_id"></a> [ram\_disk\_id](#input\_ram\_disk\_id) | The ID of the ram disk | `string` | `null` | no |
180+
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
180181
| <a name="input_remote_access"></a> [remote\_access](#input\_remote\_access) | Configuration block with remote access settings. Only valid when `use_custom_launch_template` = `false` | <pre>object({<br/> ec2_ssh_key = optional(string)<br/> source_security_group_ids = optional(list(string))<br/> })</pre> | `null` | no |
181182
| <a name="input_security_group_description"></a> [security\_group\_description](#input\_security\_group\_description) | Description of the security group created | `string` | `null` | no |
182183
| <a name="input_security_group_egress_rules"></a> [security\_group\_egress\_rules](#input\_security\_group\_egress\_rules) | Security group egress rules to add to the security group created | <pre>map(object({<br/> name = optional(string)<br/><br/> cidr_ipv4 = optional(string)<br/> cidr_ipv6 = optional(string)<br/> description = optional(string)<br/> from_port = optional(string)<br/> ip_protocol = optional(string, "tcp")<br/> prefix_list_id = optional(string)<br/> referenced_security_group_id = optional(string)<br/> self = optional(bool, false)<br/> tags = optional(map(string), {})<br/> to_port = optional(string)<br/> }))</pre> | `{}` | no |

modules/eks-managed-node-group/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ module "user_data" {
4343
data "aws_ec2_instance_type" "this" {
4444
count = var.create && var.enable_efa_support ? 1 : 0
4545

46+
region = var.region
47+
4648
instance_type = local.efa_instance_type
4749
}
4850

@@ -78,6 +80,8 @@ locals {
7880
resource "aws_launch_template" "this" {
7981
count = var.create && var.create_launch_template && var.use_custom_launch_template ? 1 : 0
8082

83+
region = var.region
84+
8185
dynamic "block_device_mappings" {
8286
for_each = var.block_device_mappings != null ? var.block_device_mappings : {}
8387

@@ -364,6 +368,8 @@ resource "aws_launch_template" "this" {
364368
data "aws_eks_cluster_versions" "this" {
365369
count = var.create && var.kubernetes_version == null ? 1 : 0
366370

371+
region = var.region
372+
367373
cluster_type = "eks"
368374
version_status = "STANDARD_SUPPORT"
369375
}
@@ -405,6 +411,8 @@ locals {
405411
data "aws_ssm_parameter" "ami" {
406412
count = var.create && var.use_latest_ami_release_version ? 1 : 0
407413

414+
region = var.region
415+
408416
name = local.ssm_ami_type_to_ssm_param[var.ami_type]
409417
}
410418

@@ -421,6 +429,8 @@ locals {
421429
resource "aws_eks_node_group" "this" {
422430
count = var.create ? 1 : 0
423431

432+
region = var.region
433+
424434
# Required
425435
cluster_name = var.cluster_name
426436
node_role_arn = var.create_iam_role ? aws_iam_role.this[0].arn : var.iam_role_arn
@@ -658,6 +668,8 @@ locals {
658668
resource "aws_placement_group" "this" {
659669
count = local.create_placement_group ? 1 : 0
660670

671+
region = var.region
672+
661673
name = "${var.cluster_name}-${var.name}"
662674
strategy = "cluster"
663675

@@ -701,12 +713,16 @@ locals {
701713
data "aws_subnet" "this" {
702714
count = local.create_security_group ? 1 : 0
703715

716+
region = var.region
717+
704718
id = element(var.subnet_ids, 0)
705719
}
706720

707721
resource "aws_security_group" "this" {
708722
count = local.create_security_group ? 1 : 0
709723

724+
region = var.region
725+
710726
name = var.security_group_use_name_prefix ? null : local.security_group_name
711727
name_prefix = var.security_group_use_name_prefix ? "${local.security_group_name}-" : null
712728
description = var.security_group_description
@@ -726,6 +742,8 @@ resource "aws_security_group" "this" {
726742
resource "aws_vpc_security_group_ingress_rule" "this" {
727743
for_each = { for k, v in local.security_group_ingress_rules : k => v if length(local.security_group_ingress_rules) > 0 && local.create_security_group }
728744

745+
region = var.region
746+
729747
cidr_ipv4 = each.value.cidr_ipv4
730748
cidr_ipv6 = each.value.cidr_ipv6
731749
description = each.value.description
@@ -746,6 +764,8 @@ resource "aws_vpc_security_group_ingress_rule" "this" {
746764
resource "aws_vpc_security_group_egress_rule" "this" {
747765
for_each = { for k, v in local.security_group_egress_rules : k => v if length(local.security_group_egress_rules) > 0 && local.create_security_group }
748766

767+
region = var.region
768+
749769
cidr_ipv4 = each.value.cidr_ipv4
750770
cidr_ipv6 = each.value.cidr_ipv6
751771
description = each.value.description

modules/eks-managed-node-group/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ variable "tags" {
1111
default = {}
1212
}
1313

14+
variable "region" {
15+
description = "Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration"
16+
type = string
17+
default = null
18+
}
19+
1420
variable "partition" {
1521
description = "The AWS partition - pass through value to reduce number of GET requests from data sources"
1622
type = string

modules/fargate-profile/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ No modules.
7878
| <a name="input_iam_role_use_name_prefix"></a> [iam\_role\_use\_name\_prefix](#input\_iam\_role\_use\_name\_prefix) | Determines whether the IAM role name (`iam_role_name`) is used as a prefix | `bool` | `true` | no |
7979
| <a name="input_name"></a> [name](#input\_name) | Name of the EKS Fargate Profile | `string` | `""` | no |
8080
| <a name="input_partition"></a> [partition](#input\_partition) | The AWS partition - pass through value to reduce number of GET requests from data sources | `string` | `""` | no |
81+
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
8182
| <a name="input_selectors"></a> [selectors](#input\_selectors) | Configuration block(s) for selecting Kubernetes Pods to execute with this Fargate Profile | <pre>list(object({<br/> labels = optional(map(string))<br/> namespace = string<br/> }))</pre> | `null` | no |
8283
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | A list of subnet IDs for the EKS Fargate Profile | `list(string)` | `[]` | no |
8384
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |

modules/fargate-profile/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
data "aws_region" "current" {
22
count = var.create ? 1 : 0
3+
4+
region = var.region
35
}
46
data "aws_partition" "current" {
57
count = var.create && var.partition == "" ? 1 : 0
@@ -159,6 +161,8 @@ resource "aws_iam_role_policy" "this" {
159161
resource "aws_eks_fargate_profile" "this" {
160162
count = var.create ? 1 : 0
161163

164+
region = var.region
165+
162166
cluster_name = var.cluster_name
163167
fargate_profile_name = var.name
164168
pod_execution_role_arn = var.create_iam_role ? aws_iam_role.this[0].arn : var.iam_role_arn

modules/fargate-profile/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ variable "tags" {
1111
default = {}
1212
}
1313

14+
variable "region" {
15+
description = "Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration"
16+
type = string
17+
default = null
18+
}
19+
1420
variable "partition" {
1521
description = "The AWS partition - pass through value to reduce number of GET requests from data sources"
1622
type = string

modules/karpenter/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ No modules.
168168
| <a name="input_queue_kms_master_key_id"></a> [queue\_kms\_master\_key\_id](#input\_queue\_kms\_master\_key\_id) | The ID of an AWS-managed customer master key (CMK) for Amazon SQS or a custom CMK | `string` | `null` | no |
169169
| <a name="input_queue_managed_sse_enabled"></a> [queue\_managed\_sse\_enabled](#input\_queue\_managed\_sse\_enabled) | Boolean to enable server-side encryption (SSE) of message content with SQS-owned encryption keys | `bool` | `true` | no |
170170
| <a name="input_queue_name"></a> [queue\_name](#input\_queue\_name) | Name of the SQS queue | `string` | `null` | no |
171+
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
171172
| <a name="input_rule_name_prefix"></a> [rule\_name\_prefix](#input\_rule\_name\_prefix) | Prefix used for all event bridge rules | `string` | `"Karpenter"` | no |
172173
| <a name="input_service_account"></a> [service\_account](#input\_service\_account) | Service account to associate with the Karpenter Pod Identity | `string` | `"karpenter"` | no |
173174
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |

0 commit comments

Comments
 (0)