Skip to content

Commit a0fe977

Browse files
committed
fix: Use generic tags to set Name or other tag values
1 parent 060e1dd commit a0fe977

File tree

4 files changed

+10
-32
lines changed

4 files changed

+10
-32
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 7 deletions
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,18 +41,16 @@ 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
48-
exclude_name = "private-subnet-1"
4948
subnet_type = "private"
5049
subnet_index = 1
5150
internet_gateway_exclusion_mode = "allow-egress"
5251
}
5352
exclude_subnet_private2 = {
5453
exclude_subnet = true
55-
exclude_name = "private-subnet-2"
5654
subnet_type = "private"
5755
subnet_index = 2
5856
internet_gateway_exclusion_mode = "allow-egress"
@@ -64,7 +62,6 @@ One of `exclude_vpc` or `exclude_subnet` must be set to true.
6462
Value of `subnet_type` can be `public`, `private`, `database`, `redshift`, `elasticache`, `intra` or `custom`.
6563
Value of `subnet_index` is the index of the subnet in the corresponding subnet list.
6664
Value of `internet_gateway_exclusion_mode` can be `allow-egress` and `allow-bidirectional`.
67-
Value of `exclude_name` is string value of the Name tag for the resource. If omitted, the default name of VPC Name-bpa-exclusion is applied.
6865

6966
After deployment, VPC block public access options can be verified with the following command:
7067

examples/block-public-access/main.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +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-
# exclude_name = "private-subnet-1"
52-
# subnet_type = "private"
53-
# subnet_index = 1
54-
# internet_gateway_exclusion_mode = "allow-egress"
55-
# }
56-
# exclude_subnet_private2 = {
57-
# exclude_subnet = true
58-
# exclude_name = "private-subnet-2"
59-
# subnet_type = "private"
60-
# subnet_index = 2
61-
# internet_gateway_exclusion_mode = "allow-egress"
62-
# }
63-
# }
64-
6545
tags = local.tags
6646
}

main.tf

Lines changed: 5 additions & 4 deletions
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,
@@ -87,8 +87,9 @@ resource "aws_vpc_block_public_access_exclusion" "this" {
8787
internet_gateway_exclusion_mode = each.value.internet_gateway_exclusion_mode
8888

8989
tags = merge(
90-
{ "Name" = try(coalesce(each.value.exclude_name), "${var.name}-bpa-exclusion") },
91-
var.tags, )
90+
var.tags,
91+
try(each.value.tags, {}),
92+
)
9293
}
9394

9495
################################################################################

0 commit comments

Comments
 (0)