Skip to content

Commit 59be93b

Browse files
Explicit AZ control to prevent breaking changes in infra
1 parent de7daf8 commit 59be93b

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ No modules.
7171
| [local_file.red_private_key_file](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
7272
| [tls_private_key.red_private_key](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
7373
| [aws_ami.red_ami](https://registry.terraform.io/providers/hashicorp/aws/6.0.0/docs/data-sources/ami) | data source |
74-
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/6.0.0/docs/data-sources/availability_zones) | data source |
7574
| [aws_route53_zone.zone](https://registry.terraform.io/providers/hashicorp/aws/6.0.0/docs/data-sources/route53_zone) | data source |
7675

7776
## Inputs
@@ -83,6 +82,7 @@ No modules.
8382
| <a name="input_ami_name"></a> [ami\_name](#input\_ami\_name) | The name of the AMI to use for the instance | `string` | `"ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-arm64-server-20250610"` | no |
8483
| <a name="input_ami_owner"></a> [ami\_owner](#input\_ami\_owner) | The owner of the AMI to use for the instance | `string` | `"099720109477"` | no |
8584
| <a name="input_apex_domain"></a> [apex\_domain](#input\_apex\_domain) | The apex domain to use for the public DNS record | `string` | `""` | no |
85+
| <a name="input_availability_zone"></a> [availability\_zone](#input\_availability\_zone) | The availability zone to use for the subnet. Leave empty to use the default behavior. | `string` | `""` | no |
8686
| <a name="input_create_ec2_key_pair"></a> [create\_ec2\_key\_pair](#input\_create\_ec2\_key\_pair) | Controls whether an EC2 key pair should be created | `bool` | `false` | no |
8787
| <a name="input_create_vpc"></a> [create\_vpc](#input\_create\_vpc) | Controls whether networking resources should be created for public exposed server | `bool` | `true` | no |
8888
| <a name="input_disable_api_stop"></a> [disable\_api\_stop](#input\_disable\_api\_stop) | Controls whether API stop is disabled | `bool` | `false` | no |

red-instance/public_vpc.tf

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
# This file creates a VPC, a public subnet, an internet gateway, a route table, and associates the route table with the subnet.
2-
3-
# Data source to get available AZs that support the instance type
4-
data "aws_availability_zones" "available" {
5-
count = var.create_vpc ? 1 : 0
6-
state = "available"
7-
8-
# Filter to exclude AZs that typically don't support ARM instances
9-
exclude_names = ["us-east-1e"] # Add other problematic AZs as needed
10-
}
11-
121
# The resources are created conditionally based on the value of the create_vpc variable.
132
# Justification: This is for development purposes, Flow Logs and other features are not required for a red instance.
143
# trivy:ignore:AVD-AWS-0178
@@ -27,7 +16,7 @@ resource "aws_vpc" "main" {
2716
)
2817
}
2918

30-
# Create a public subnet with explicit AZ
19+
# Create a public subnet with smart AZ selection
3120
# Justification: This is a public subnet for the red instance
3221
# trivy:ignore:AVD-AWS-0164
3322
resource "aws_subnet" "public" {
@@ -36,8 +25,8 @@ resource "aws_subnet" "public" {
3625
cidr_block = "10.0.1.0/24"
3726
map_public_ip_on_launch = true
3827

39-
# Use the first available AZ that supports ARM instances
40-
availability_zone = data.aws_availability_zones.available[0].names[0]
28+
# Only specify AZ if explicitly provided
29+
availability_zone = var.availability_zone != "" ? var.availability_zone : null
4130

4231
tags = merge(
4332
{

red-instance/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ variable "user_data_script_path" {
8282
default = ""
8383
}
8484

85+
variable "availability_zone" {
86+
description = "The availability zone to use for the subnet. Leave empty to use the default behavior."
87+
type = string
88+
default = ""
89+
}
90+
8591
####################################################################################################
8692
# Optional Variables for Red Instance Features
8793
variable "create_vpc" {

tests/dns-only/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ module "red-instance" {
2525
volume_size = 16
2626

2727
# Basic networking setup
28-
create_vpc = true
29-
allocate_eip = true
28+
create_vpc = true
29+
availability_zone = "us-east-1a"
30+
allocate_eip = true
3031

3132
# Enable DNS but no other optional features
3233
enable_public_dns = true

tests/full-force/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module "red-instance" {
2626

2727
# Enable all optional features
2828
create_vpc = true
29+
availability_zone = "us-east-1a"
2930
allocate_eip = true
3031
create_ec2_key_pair = true
3132
enable_public_dns = true

tests/manual/enabled/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module "red-instance" {
2727
dns_name = "red-instance.rag-space.com"
2828
create_ec2_key_pair = true
2929
create_vpc = true
30+
availability_zone = "us-east-1a"
3031

3132
additional_tags = {
3233
Environment = "Has-VPC"

0 commit comments

Comments
 (0)