Skip to content

Commit

Permalink
Support AWS Provider V5 (#48)
Browse files Browse the repository at this point in the history
* Support AWS Provider V5

* updates
  • Loading branch information
max-lobur authored Jun 21, 2023
1 parent b537234 commit 196fdf7
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'docs/**'
- 'examples/**'
- 'test/**'
- 'README.*'

permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ permissions:

jobs:
terraform-module:
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release.yml@main
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release-published.yml@main
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ Available targets:

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.3 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |

## Modules

Expand Down
6 changes: 3 additions & 3 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.3 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |

## Modules

Expand Down
10 changes: 5 additions & 5 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provider "aws" {

module "requestor_vpc" {
source = "cloudposse/vpc/aws"
version = "1.2.0"
version = "2.1.0"
attributes = ["requestor"]
ipv4_primary_cidr_block = var.requestor_vpc_cidr
ipv4_additional_cidr_block_associations = {
Expand All @@ -20,7 +20,7 @@ module "requestor_vpc" {

module "requestor_subnets" {
source = "cloudposse/dynamic-subnets/aws"
version = "2.0.4"
version = "2.3.0"
availability_zones = var.availability_zones
attributes = ["requestor"]
vpc_id = module.requestor_vpc.vpc_id
Expand All @@ -34,7 +34,7 @@ module "requestor_subnets" {

module "requestor_subnets_additional" {
source = "cloudposse/dynamic-subnets/aws"
version = "2.0.4"
version = "2.3.0"
availability_zones = var.availability_zones
attributes = ["requestor"]
vpc_id = module.requestor_vpc.vpc_id
Expand All @@ -52,7 +52,7 @@ module "requestor_subnets_additional" {

module "acceptor_vpc" {
source = "cloudposse/vpc/aws"
version = "1.2.0"
version = "2.1.0"
attributes = ["acceptor"]
ipv4_primary_cidr_block = var.acceptor_vpc_cidr

Expand All @@ -61,7 +61,7 @@ module "acceptor_vpc" {

module "acceptor_subnets" {
source = "cloudposse/dynamic-subnets/aws"
version = "2.0.4"
version = "2.1.0"
availability_zones = var.availability_zones
attributes = ["acceptor"]
vpc_id = module.acceptor_vpc.vpc_id
Expand Down
4 changes: 2 additions & 2 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 0.13.0"
required_version = ">= 1.3"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.0"
version = ">= 5.0"
}
local = {
source = "hashicorp/local"
Expand Down
24 changes: 12 additions & 12 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "aws_vpc_peering_connection" "default" {
count = module.this.enabled ? 1 : 0
vpc_id = join("", data.aws_vpc.requestor.*.id)
peer_vpc_id = join("", data.aws_vpc.acceptor.*.id)
vpc_id = join("", data.aws_vpc.requestor[*].id)
peer_vpc_id = join("", data.aws_vpc.acceptor[*].id)

auto_accept = var.auto_accept

Expand Down Expand Up @@ -38,39 +38,39 @@ data "aws_vpc" "acceptor" {

data "aws_route_tables" "requestor" {
count = module.this.enabled ? 1 : 0
vpc_id = join("", data.aws_vpc.requestor.*.id)
vpc_id = join("", data.aws_vpc.requestor[*].id)
tags = var.requestor_route_table_tags
}

data "aws_route_tables" "acceptor" {
count = module.this.enabled ? 1 : 0
vpc_id = join("", data.aws_vpc.acceptor.*.id)
vpc_id = join("", data.aws_vpc.acceptor[*].id)
tags = var.acceptor_route_table_tags
}

locals {
requestor_cidr_blocks = module.this.enabled ? tolist(setsubtract([
for k, v in data.aws_vpc.requestor.0.cidr_block_associations : v.cidr_block
for k, v in data.aws_vpc.requestor[0].cidr_block_associations : v.cidr_block
], var.requestor_ignore_cidrs)) : []
acceptor_cidr_blocks = module.this.enabled ? tolist(setsubtract([
for k, v in data.aws_vpc.acceptor.0.cidr_block_associations : v.cidr_block
for k, v in data.aws_vpc.acceptor[0].cidr_block_associations : v.cidr_block
], var.acceptor_ignore_cidrs)) : []
}

# Create routes from requestor to acceptor
resource "aws_route" "requestor" {
count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor.0.ids))) * length(local.acceptor_cidr_blocks) : 0
route_table_id = element(distinct(sort(data.aws_route_tables.requestor.0.ids)), ceil(count.index / length(local.acceptor_cidr_blocks)))
count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor[0].ids))) * length(local.acceptor_cidr_blocks) : 0
route_table_id = element(distinct(sort(data.aws_route_tables.requestor[0].ids)), ceil(count.index / length(local.acceptor_cidr_blocks)))
destination_cidr_block = local.acceptor_cidr_blocks[count.index % length(local.acceptor_cidr_blocks)]
vpc_peering_connection_id = join("", aws_vpc_peering_connection.default.*.id)
vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id)
depends_on = [data.aws_route_tables.requestor, aws_vpc_peering_connection.default]
}

# Create routes from acceptor to requestor
resource "aws_route" "acceptor" {
count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor.0.ids))) * length(local.requestor_cidr_blocks) : 0
route_table_id = element(distinct(sort(data.aws_route_tables.acceptor.0.ids)), ceil(count.index / length(local.requestor_cidr_blocks)))
count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor[0].ids))) * length(local.requestor_cidr_blocks) : 0
route_table_id = element(distinct(sort(data.aws_route_tables.acceptor[0].ids)), ceil(count.index / length(local.requestor_cidr_blocks)))
destination_cidr_block = local.requestor_cidr_blocks[count.index % length(local.requestor_cidr_blocks)]
vpc_peering_connection_id = join("", aws_vpc_peering_connection.default.*.id)
vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id)
depends_on = [data.aws_route_tables.acceptor, aws_vpc_peering_connection.default]
}
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
output "connection_id" {
value = join("", aws_vpc_peering_connection.default.*.id)
value = join("", aws_vpc_peering_connection.default[*].id)
description = "VPC peering connection ID"
}

output "accept_status" {
value = join("", aws_vpc_peering_connection.default.*.accept_status)
value = join("", aws_vpc_peering_connection.default[*].accept_status)
description = "The status of the VPC peering connection request"
}
4 changes: 2 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 0.13.0"
required_version = ">= 1.3"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.0"
version = ">= 5.0"
}
local = {
source = "hashicorp/local"
Expand Down

0 comments on commit 196fdf7

Please sign in to comment.