Skip to content

feat: Enhanced region support #1225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.99.0
rev: v1.99.5
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ No modules.
| <a name="input_redshift_subnet_suffix"></a> [redshift\_subnet\_suffix](#input\_redshift\_subnet\_suffix) | Suffix to append to redshift subnets name | `string` | `"redshift"` | no |
| <a name="input_redshift_subnet_tags"></a> [redshift\_subnet\_tags](#input\_redshift\_subnet\_tags) | Additional tags for the redshift subnets | `map(string)` | `{}` | no |
| <a name="input_redshift_subnets"></a> [redshift\_subnets](#input\_redshift\_subnets) | A list of redshift subnets inside the VPC | `list(string)` | `[]` | no |
| <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 |
| <a name="input_reuse_nat_ips"></a> [reuse\_nat\_ips](#input\_reuse\_nat\_ips) | Should be true if you don't want EIPs to be created for your NAT Gateways and will instead pass them in via the 'external\_nat\_ip\_ids' variable | `bool` | `false` | no |
| <a name="input_secondary_cidr_blocks"></a> [secondary\_cidr\_blocks](#input\_secondary\_cidr\_blocks) | List of secondary CIDR blocks to associate with the VPC to extend the IP Address pool | `list(string)` | `[]` | no |
| <a name="input_single_nat_gateway"></a> [single\_nat\_gateway](#input\_single\_nat\_gateway) | Should be true if you want to provision a single shared NAT Gateway across all of your private networks | `bool` | `false` | no |
Expand Down
148 changes: 148 additions & 0 deletions main.tf

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions modules/vpc-endpoints/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ No modules.
|------|-------------|------|---------|:--------:|
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created | `bool` | `true` | no |
| <a name="input_create_security_group"></a> [create\_security\_group](#input\_create\_security\_group) | Determines if a security group is created | `bool` | `false` | no |
| <a name="input_enable_service_endpoint_lookup"></a> [enable\_service\_endpoint\_lookup](#input\_enable\_service\_endpoint\_lookup) | Determines whether to look up the service endpoint in the AWS API. If set to false, the `service_endpoint` attribute (usually in the form of `com.amazonaws.<region>.<service>`) must be provided in the `endpoints` map | `bool` | `true` | no |
| <a name="input_endpoints"></a> [endpoints](#input\_endpoints) | A map of interface and/or gateway endpoints containing their properties and configurations | `any` | `{}` | no |
| <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 |
| <a name="input_security_group_description"></a> [security\_group\_description](#input\_security\_group\_description) | Description of the security group created | `string` | `null` | no |
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | Default security group IDs to associate with the VPC endpoints | `list(string)` | `[]` | no |
| <a name="input_security_group_name"></a> [security\_group\_name](#input\_security\_group\_name) | Name to use on security group created. Conflicts with `security_group_name_prefix` | `string` | `null` | no |
Expand Down
10 changes: 8 additions & 2 deletions modules/vpc-endpoints/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ locals {
}

data "aws_vpc_endpoint_service" "this" {
for_each = local.endpoints
for_each = { for k, v in local.endpoints : k => v if var.enable_service_endpoint_lookup }

service = try(each.value.service, null)
service_name = try(each.value.service_name, null)
Expand All @@ -24,8 +24,10 @@ data "aws_vpc_endpoint_service" "this" {
resource "aws_vpc_endpoint" "this" {
for_each = local.endpoints

region = var.region

vpc_id = var.vpc_id
service_name = try(each.value.service_endpoint, data.aws_vpc_endpoint_service.this[each.key].service_name)
service_name = try(data.aws_vpc_endpoint_service.this[each.key].service_name, each.value.service_endpoint)
service_region = try(each.value.service_region, null)
vpc_endpoint_type = try(each.value.service_type, "Interface")
auto_accept = try(each.value.auto_accept, null)
Expand Down Expand Up @@ -76,6 +78,8 @@ resource "aws_vpc_endpoint" "this" {
resource "aws_security_group" "this" {
count = var.create && var.create_security_group ? 1 : 0

region = var.region

name = var.security_group_name
name_prefix = var.security_group_name_prefix
description = var.security_group_description
Expand All @@ -95,6 +99,8 @@ resource "aws_security_group" "this" {
resource "aws_security_group_rule" "this" {
for_each = { for k, v in var.security_group_rules : k => v if var.create && var.create_security_group }

region = var.region

# Required
security_group_id = aws_security_group.this[0].id
protocol = try(each.value.protocol, "tcp")
Expand Down
12 changes: 12 additions & 0 deletions modules/vpc-endpoints/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ variable "create" {
default = true
}

variable "region" {
description = "Region where the resource(s) will be managed. Defaults to the region set in the provider configuration"
type = string
default = null
}

variable "vpc_id" {
description = "The ID of the VPC in which the endpoint will be used"
type = string
Expand All @@ -16,6 +22,12 @@ variable "endpoints" {
default = {}
}

variable "enable_service_endpoint_lookup" {
description = "Determines whether to look up the service endpoint in the AWS API. If set to false, the `service_endpoint` attribute (usually in the form of `com.amazonaws.<region>.<service>`) must be provided in the `endpoints` map"
type = bool
default = true
}

variable "security_group_ids" {
description = "Default security group IDs to associate with the VPC endpoints"
type = list(string)
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ variable "create_vpc" {
default = true
}

variable "region" {
description = "Region where the resource(s) will be managed. Defaults to the region set in the provider configuration"
type = string
default = null
}

variable "name" {
description = "Name to be used on all the resources as identifier"
type = string
Expand Down
6 changes: 6 additions & 0 deletions vpc-flow-logs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
data "aws_region" "current" {
# Call this API only if create_vpc and enable_flow_log are true
count = var.create_vpc && var.enable_flow_log ? 1 : 0

region = var.region
}

data "aws_caller_identity" "current" {
Expand Down Expand Up @@ -36,6 +38,8 @@ locals {
resource "aws_flow_log" "this" {
count = local.enable_flow_log ? 1 : 0

region = var.region

log_destination_type = var.flow_log_destination_type
log_destination = local.flow_log_destination_arn
log_format = var.flow_log_log_format
Expand Down Expand Up @@ -65,6 +69,8 @@ resource "aws_flow_log" "this" {
resource "aws_cloudwatch_log_group" "flow_log" {
count = local.create_flow_log_cloudwatch_log_group ? 1 : 0

region = var.region

name = "${var.flow_log_cloudwatch_log_group_name_prefix}${local.flow_log_cloudwatch_log_group_name_suffix}"
retention_in_days = var.flow_log_cloudwatch_log_group_retention_in_days
kms_key_id = var.flow_log_cloudwatch_log_group_kms_key_id
Expand Down