Skip to content

feat: Allow setting custom tags on aws_vpc_block_public_access_exclusion resource #1170

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

Merged
merged 3 commits into from
Apr 21, 2025
Merged
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.96.2
rev: v1.99.0
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand Down
8 changes: 4 additions & 4 deletions examples/block-public-access/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Currently only `internet_gateway_block_mode` is supported, for which valid value

VPC block public access exclusions can be applied at the VPC level e.g.:

```
vpc_block_public_access_exclusions = {
```hcl
vpc_block_public_access_exclusions = {
exclude_vpc = {
exclude_vpc = true
internet_gateway_exclusion_mode = "allow-bidirectional"
Expand All @@ -41,8 +41,8 @@ vpc_block_public_access_exclusions = {

or at the subnet level e.g.:

```
vpc_block_public_access_exclusions = {
```hcl
vpc_block_public_access_exclusions = {
exclude_subnet_private1 = {
exclude_subnet = true
subnet_type = "private"
Expand Down
18 changes: 0 additions & 18 deletions examples/block-public-access/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,16 @@ module "vpc" {
azs = local.azs
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]

### VPC Block Public Access Options
vpc_block_public_access_options = {
internet_gateway_block_mode = "block-bidirectional"
}

### VPC Block Public Access Exclusion at the VPC level
vpc_block_public_access_exclusions = {
exclude_vpc = {
exclude_vpc = true
internet_gateway_exclusion_mode = "allow-bidirectional"
}
}

### VPC Block Public Access Exclusion at the subnet level
# vpc_block_public_access_exclusions = {
# exclude_subnet_private1 = {
# exclude_subnet = true
# subnet_type = "private"
# subnet_index = 1
# internet_gateway_exclusion_mode = "allow-egress"
# }
# exclude_subnet_private2 = {
# exclude_subnet = true
# subnet_type = "private"
# subnet_index = 2
# internet_gateway_exclusion_mode = "allow-egress"
# }
# }

tags = local.tags
}
9 changes: 6 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ resource "aws_vpc_block_public_access_options" "this" {
resource "aws_vpc_block_public_access_exclusion" "this" {
for_each = { for k, v in var.vpc_block_public_access_exclusions : k => v if local.create_vpc }

vpc_id = lookup(each.value, "exclude_vpc", false) ? local.vpc_id : null
vpc_id = try(each.value.exclude_vpc, false) ? local.vpc_id : null

subnet_id = lookup(each.value, "exclude_subnet", false) ? lookup(
subnet_id = try(each.value.exclude_subnet, false) ? lookup(
{
private = aws_subnet.private[*].id,
public = aws_subnet.public[*].id,
Expand All @@ -86,7 +86,10 @@ resource "aws_vpc_block_public_access_exclusion" "this" {

internet_gateway_exclusion_mode = each.value.internet_gateway_exclusion_mode

tags = var.tags
tags = merge(
var.tags,
try(each.value.tags, {}),
)
}

################################################################################
Expand Down