Skip to content

Commit 0d11295

Browse files
feat: Allow setting custom tags on aws_vpc_block_public_access_exclusion resource (#1170)
* Updated to allow Name tag creation of the BPA Resource * fix: Use generic `tags` to set `Name` or other tag values --------- Co-authored-by: Bryant Biggs <[email protected]>
1 parent e31b161 commit 0d11295

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.96.2
3+
rev: v1.99.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs

examples/block-public-access/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Currently only `internet_gateway_block_mode` is supported, for which valid value
3030

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

33-
```
34-
vpc_block_public_access_exclusions = {
33+
```hcl
34+
vpc_block_public_access_exclusions = {
3535
exclude_vpc = {
3636
exclude_vpc = true
3737
internet_gateway_exclusion_mode = "allow-bidirectional"
@@ -41,8 +41,8 @@ vpc_block_public_access_exclusions = {
4141

4242
or at the subnet level e.g.:
4343

44-
```
45-
vpc_block_public_access_exclusions = {
44+
```hcl
45+
vpc_block_public_access_exclusions = {
4646
exclude_subnet_private1 = {
4747
exclude_subnet = true
4848
subnet_type = "private"

examples/block-public-access/main.tf

-18
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,16 @@ module "vpc" {
3131
azs = local.azs
3232
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
3333

34-
### VPC Block Public Access Options
3534
vpc_block_public_access_options = {
3635
internet_gateway_block_mode = "block-bidirectional"
3736
}
3837

39-
### VPC Block Public Access Exclusion at the VPC level
4038
vpc_block_public_access_exclusions = {
4139
exclude_vpc = {
4240
exclude_vpc = true
4341
internet_gateway_exclusion_mode = "allow-bidirectional"
4442
}
4543
}
4644

47-
### VPC Block Public Access Exclusion at the subnet level
48-
# vpc_block_public_access_exclusions = {
49-
# exclude_subnet_private1 = {
50-
# exclude_subnet = true
51-
# subnet_type = "private"
52-
# subnet_index = 1
53-
# internet_gateway_exclusion_mode = "allow-egress"
54-
# }
55-
# exclude_subnet_private2 = {
56-
# exclude_subnet = true
57-
# subnet_type = "private"
58-
# subnet_index = 2
59-
# internet_gateway_exclusion_mode = "allow-egress"
60-
# }
61-
# }
62-
6345
tags = local.tags
6446
}

main.tf

+6-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ resource "aws_vpc_block_public_access_options" "this" {
6868
resource "aws_vpc_block_public_access_exclusion" "this" {
6969
for_each = { for k, v in var.vpc_block_public_access_exclusions : k => v if local.create_vpc }
7070

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

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

8787
internet_gateway_exclusion_mode = each.value.internet_gateway_exclusion_mode
8888

89-
tags = var.tags
89+
tags = merge(
90+
var.tags,
91+
try(each.value.tags, {}),
92+
)
9093
}
9194

9295
################################################################################

0 commit comments

Comments
 (0)