Skip to content

Commit

Permalink
fix: get availability zone from data source (#137)
Browse files Browse the repository at this point in the history
* fix: get availability zone from data source

* terraform-docs: automated action

* refactor: fix data source quoting

Co-authored-by: Martin Gerlach <[email protected]>
Signed-off-by: ugmuka <[email protected]>

* refactor: fix data source quoting

Co-authored-by: Martin Gerlach <[email protected]>
Signed-off-by: ugmuka <[email protected]>

* fix: sort az name

Co-authored-by: Martin Gerlach <[email protected]>
Signed-off-by: ugmuka <[email protected]>

* fix: use local variable

Co-authored-by: Martin Gerlach <[email protected]>
Signed-off-by: ugmuka <[email protected]>

* fix: use local variables

Co-authored-by: Martin Gerlach <[email protected]>
Signed-off-by: ugmuka <[email protected]>

---------

Signed-off-by: ugmuka <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Martin Gerlach <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2023
1 parent ef7aafc commit 687bb9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ No modules.
| [aws_security_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
| [aws_subnet.private](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet) | resource |
| [aws_subnet.public](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet) | resource |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
| [aws_iam_policy_document.assume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.base](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
Expand Down
15 changes: 13 additions & 2 deletions vpc.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
data "aws_availability_zones" "available" {
filter {
name = "group-name"
values = [var.region]
}
}

locals {
az_names = sort(data.aws_availability_zones.available.names)
}

resource "aws_subnet" "public" {
count = var.create_networking_config ? length(var.public_subnet_cidrs) : 0
cidr_block = var.public_subnet_cidrs[count.index]
vpc_id = var.vpc_id
map_public_ip_on_launch = true
availability_zone = count.index % 2 == 0 ? "${var.region}a" : "${var.region}b"
availability_zone = count.index % 2 == 0 ? local.az_names[0] : local.az_names[1]
tags = merge({
Name = "mwaa-${var.environment_name}-public-subnet-${count.index}"
}, var.tags)
Expand All @@ -14,7 +25,7 @@ resource "aws_subnet" "private" {
cidr_block = var.private_subnet_cidrs[count.index]
vpc_id = var.vpc_id
map_public_ip_on_launch = false
availability_zone = count.index % 2 == 0 ? "${var.region}a" : "${var.region}b"
availability_zone = count.index % 2 == 0 ? local.az_names[0] : local.az_names[1]
tags = merge({
Name = "mwaa-${var.environment_name}-private-subnet-${count.index}"
}, var.tags)
Expand Down

0 comments on commit 687bb9a

Please sign in to comment.