Skip to content

Commit 93d3a0b

Browse files
aknyshnitrocode
andauthored
Add accepter_enabled variable (#52)
Co-authored-by: nitrocode <nitrocode@users.noreply.github.com>
1 parent c5b6506 commit 93d3a0b

File tree

12 files changed

+55
-27
lines changed

12 files changed

+55
-27
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
# Cloud Posse must review any changes to standard context definition,
1717
# but some changes can be rubber-stamped.
18-
**/*.tf @cloudposse/engineering @cloudposse/approvers
19-
README.yaml @cloudposse/engineering @cloudposse/approvers
18+
**/*.tf @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers
19+
README.yaml @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers
2020
README.md @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers
2121
docs/*.md @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers
2222

.github/auto-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ template: |
4646
4747
replacers:
4848
# Remove irrelevant information from Renovate bot
49-
- search: '/---\s+^#.*Renovate configuration(?:.|\n)*?This PR has been generated .*/gm'
49+
- search: '/(?<=---\s+)+^#.*(Renovate configuration|Configuration)(?:.|\n)*?This PR has been generated .*/gm'
5050
replace: ''
5151
# Remove Renovate bot banner image
5252
- search: '/\[!\[[^\]]*Renovate\][^\]]*\](\([^)]*\))?\s*\n+/gm'

.github/workflows/auto-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ name: auto-release
33
on:
44
push:
55
branches:
6+
- main
67
- master
8+
- production
79

810
jobs:
911
publish:
@@ -14,7 +16,7 @@ jobs:
1416
id: get-merged-pull-request
1517
with:
1618
github_token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
17-
# Drafts your next Release notes as Pull Requests are merged into "master"
19+
# Drafts your next Release notes as Pull Requests are merged into "main"
1820
- uses: release-drafter/release-drafter@v5
1921
if: "!contains(steps.get-merged-pull-request.outputs.labels, 'no-release')"
2022
with:

.github/workflows/validate-codeowners.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Validate Codeowners
22
on:
3+
workflow_dispatch:
4+
35
pull_request:
46

57
jobs:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,11 @@ Available targets:
371371
|------|-------------|------|---------|:--------:|
372372
| <a name="input_accepter_allow_remote_vpc_dns_resolution"></a> [accepter\_allow\_remote\_vpc\_dns\_resolution](#input\_accepter\_allow\_remote\_vpc\_dns\_resolution) | Allow accepter VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requester VPC | `bool` | `true` | no |
373373
| <a name="input_accepter_aws_access_key"></a> [accepter\_aws\_access\_key](#input\_accepter\_aws\_access\_key) | Access key id to use in accepter account | `string` | `null` | no |
374-
| <a name="input_accepter_aws_assume_role_arn"></a> [accepter\_aws\_assume\_role\_arn](#input\_accepter\_aws\_assume\_role\_arn) | Accepter AWS Assume Role ARN | `string` | n/a | yes |
374+
| <a name="input_accepter_aws_assume_role_arn"></a> [accepter\_aws\_assume\_role\_arn](#input\_accepter\_aws\_assume\_role\_arn) | Accepter AWS Assume Role ARN | `string` | `null` | no |
375375
| <a name="input_accepter_aws_profile"></a> [accepter\_aws\_profile](#input\_accepter\_aws\_profile) | Profile used to assume accepter\_aws\_assume\_role\_arn | `string` | `""` | no |
376376
| <a name="input_accepter_aws_secret_key"></a> [accepter\_aws\_secret\_key](#input\_accepter\_aws\_secret\_key) | Secret access key to use in accepter account | `string` | `null` | no |
377377
| <a name="input_accepter_aws_token"></a> [accepter\_aws\_token](#input\_accepter\_aws\_token) | Session token for validating temporary credentials | `string` | `null` | no |
378+
| <a name="input_accepter_enabled"></a> [accepter\_enabled](#input\_accepter\_enabled) | Flag to enable/disable the accepter side of the peering connection | `bool` | `true` | no |
378379
| <a name="input_accepter_region"></a> [accepter\_region](#input\_accepter\_region) | Accepter AWS region | `string` | n/a | yes |
379380
| <a name="input_accepter_subnet_tags"></a> [accepter\_subnet\_tags](#input\_accepter\_subnet\_tags) | Only add peer routes to accepter VPC route tables of subnets matching these tags | `map(string)` | `{}` | no |
380381
| <a name="input_accepter_vpc_id"></a> [accepter\_vpc\_id](#input\_accepter\_vpc\_id) | Accepter VPC ID filter | `string` | `""` | no |

accepter.tf

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,38 @@ provider "aws" {
1818
}
1919

2020
module "accepter" {
21-
source = "cloudposse/label/null"
22-
version = "0.25.0"
21+
source = "cloudposse/label/null"
22+
version = "0.25.0"
23+
24+
enabled = local.accepter_enabled
25+
2326
attributes = var.add_attribute_tag ? ["accepter"] : []
24-
tags = var.add_attribute_tag ? { "Side" = "accepter" } : {}
27+
tags = var.add_attribute_tag ? { Side = "accepter" } : {}
2528

2629
context = module.this.context
2730
}
2831

2932
data "aws_caller_identity" "accepter" {
30-
count = local.count
33+
count = local.accepter_count
3134
provider = aws.accepter
3235
}
3336

3437
data "aws_region" "accepter" {
35-
count = local.count
38+
count = local.accepter_count
3639
provider = aws.accepter
3740
}
3841

3942
# Lookup accepter's VPC so that we can reference the CIDR
4043
data "aws_vpc" "accepter" {
41-
count = local.count
44+
count = local.accepter_count
4245
provider = aws.accepter
4346
id = var.accepter_vpc_id
4447
tags = var.accepter_vpc_tags
4548
}
4649

4750
# Lookup accepter subnets
4851
data "aws_subnet_ids" "accepter" {
49-
count = local.count
52+
count = local.accepter_count
5053
provider = aws.accepter
5154
vpc_id = local.accepter_vpc_id
5255
tags = var.accepter_subnet_tags
@@ -62,43 +65,43 @@ locals {
6265

6366
# Lookup accepter route tables
6467
data "aws_route_table" "accepter" {
65-
count = module.this.enabled ? local.accepter_subnet_ids_count : 0
68+
count = local.accepter_enabled ? local.accepter_subnet_ids_count : 0
6669
provider = aws.accepter
6770
subnet_id = element(local.accepter_subnet_ids, count.index)
6871
}
6972

7073
locals {
7174
accepter_aws_route_table_ids = try(distinct(sort(data.aws_route_table.accepter.*.route_table_id)), [])
7275
accepter_aws_route_table_ids_count = length(local.accepter_aws_route_table_ids)
73-
accepter_cidr_block_associations = flatten(data.aws_vpc.accepter.*.cidr_block_associations)
76+
accepter_cidr_block_associations = try(flatten(data.aws_vpc.accepter.*.cidr_block_associations), [])
7477
accepter_cidr_block_associations_count = length(local.accepter_cidr_block_associations)
7578
}
7679

7780
# Create routes from accepter to requester
7881
resource "aws_route" "accepter" {
79-
count = module.this.enabled ? local.accepter_aws_route_table_ids_count * local.requester_cidr_block_associations_count : 0
82+
count = local.accepter_enabled ? local.accepter_aws_route_table_ids_count * local.requester_cidr_block_associations_count : 0
8083
provider = aws.accepter
8184
route_table_id = local.accepter_aws_route_table_ids[floor(count.index / local.requester_cidr_block_associations_count)]
8285
destination_cidr_block = local.requester_cidr_block_associations[count.index % local.requester_cidr_block_associations_count]["cidr_block"]
8386
vpc_peering_connection_id = join("", aws_vpc_peering_connection.requester.*.id)
8487
depends_on = [
8588
data.aws_route_table.accepter,
8689
aws_vpc_peering_connection_accepter.accepter,
87-
aws_vpc_peering_connection.requester,
90+
aws_vpc_peering_connection.requester
8891
]
8992
}
9093

9194
# Accepter's side of the connection.
9295
resource "aws_vpc_peering_connection_accepter" "accepter" {
93-
count = local.count
96+
count = local.accepter_count
9497
provider = aws.accepter
9598
vpc_peering_connection_id = join("", aws_vpc_peering_connection.requester.*.id)
9699
auto_accept = var.auto_accept
97100
tags = module.accepter.tags
98101
}
99102

100103
resource "aws_vpc_peering_connection_options" "accepter" {
101-
count = local.count
104+
count = local.accepter_count
102105
provider = aws.accepter
103106
vpc_peering_connection_id = local.active_vpc_peering_connection_id
104107

docs/terraform.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@
4949
|------|-------------|------|---------|:--------:|
5050
| <a name="input_accepter_allow_remote_vpc_dns_resolution"></a> [accepter\_allow\_remote\_vpc\_dns\_resolution](#input\_accepter\_allow\_remote\_vpc\_dns\_resolution) | Allow accepter VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requester VPC | `bool` | `true` | no |
5151
| <a name="input_accepter_aws_access_key"></a> [accepter\_aws\_access\_key](#input\_accepter\_aws\_access\_key) | Access key id to use in accepter account | `string` | `null` | no |
52-
| <a name="input_accepter_aws_assume_role_arn"></a> [accepter\_aws\_assume\_role\_arn](#input\_accepter\_aws\_assume\_role\_arn) | Accepter AWS Assume Role ARN | `string` | n/a | yes |
52+
| <a name="input_accepter_aws_assume_role_arn"></a> [accepter\_aws\_assume\_role\_arn](#input\_accepter\_aws\_assume\_role\_arn) | Accepter AWS Assume Role ARN | `string` | `null` | no |
5353
| <a name="input_accepter_aws_profile"></a> [accepter\_aws\_profile](#input\_accepter\_aws\_profile) | Profile used to assume accepter\_aws\_assume\_role\_arn | `string` | `""` | no |
5454
| <a name="input_accepter_aws_secret_key"></a> [accepter\_aws\_secret\_key](#input\_accepter\_aws\_secret\_key) | Secret access key to use in accepter account | `string` | `null` | no |
5555
| <a name="input_accepter_aws_token"></a> [accepter\_aws\_token](#input\_accepter\_aws\_token) | Session token for validating temporary credentials | `string` | `null` | no |
56+
| <a name="input_accepter_enabled"></a> [accepter\_enabled](#input\_accepter\_enabled) | Flag to enable/disable the accepter side of the peering connection | `bool` | `true` | no |
5657
| <a name="input_accepter_region"></a> [accepter\_region](#input\_accepter\_region) | Accepter AWS region | `string` | n/a | yes |
5758
| <a name="input_accepter_subnet_tags"></a> [accepter\_subnet\_tags](#input\_accepter\_subnet\_tags) | Only add peer routes to accepter VPC route tables of subnets matching these tags | `map(string)` | `{}` | no |
5859
| <a name="input_accepter_vpc_id"></a> [accepter\_vpc\_id](#input\_accepter\_vpc\_id) | Accepter VPC ID filter | `string` | `""` | no |

examples/complete/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module "vpc_peering_cross_account" {
1010
requester_vpc_id = var.requester_vpc_id
1111
requester_allow_remote_vpc_dns_resolution = var.requester_allow_remote_vpc_dns_resolution
1212

13+
accepter_enabled = var.accepter_enabled
1314
accepter_aws_assume_role_arn = var.accepter_aws_assume_role_arn
1415
accepter_region = var.accepter_region
1516
accepter_vpc_id = var.accepter_vpc_id

examples/complete/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ variable "requester_allow_remote_vpc_dns_resolution" {
2626
default = true
2727
}
2828

29+
variable "accepter_enabled" {
30+
description = "Flag to enable/disable the accepter side of the peering connection"
31+
type = bool
32+
default = true
33+
}
34+
2935
variable "accepter_aws_assume_role_arn" {
3036
type = string
3137
description = "Accepter AWS Assume Role ARN"
38+
default = null
3239
}
3340

3441
variable "accepter_region" {

main.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
locals {
2-
count = module.this.enabled ? 1 : 0
3-
}
2+
enabled = module.this.enabled
3+
count = local.enabled ? 1 : 0
44

5+
accepter_enabled = local.enabled && var.accepter_enabled
6+
accepter_count = local.enabled && var.accepter_enabled ? 1 : 0
7+
}

0 commit comments

Comments
 (0)