Limit Osaka test to public network
This commit is contained in:
Generated
+26
@@ -0,0 +1,26 @@
|
||||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/hashicorp/aws" {
|
||||
version = "6.73.0"
|
||||
constraints = "~> 6.73"
|
||||
hashes = [
|
||||
"h1:87t8o/A0y2RE3PtCLx/BiASSrDrKSETYTF9jRvKc7aw=",
|
||||
"zh:0f7403264fbfbcad526a5ddb9553be6ab12dba14e5901d0c2ccabc38d9ccf9a0",
|
||||
"zh:26be4e8afc94ef29c98b8219dc49b19ce21a04d3f2b4e5be6116e9526ece0355",
|
||||
"zh:2ba661a4a782fba053c411ce4d828dc148d7ed3998d073a28370a559400b1578",
|
||||
"zh:2c422d0edd37bf7470c84f1d1f76487f30948768878204a65a18189bf878467a",
|
||||
"zh:49f9d1486d48033d298977f7c288f8bbb22bb246f00926d1cb8b0bb98985451c",
|
||||
"zh:4f946cf11667e1f3bce53fd5ad92eccf47fafaa1bbaa68c742173db61773a1da",
|
||||
"zh:70beb5e13ddcdbeecb2a78be2b75d09a0fc6ce7e69b574c84a90924fd4262406",
|
||||
"zh:8c5b974104ff9a887b29fdb2700cdbb5e6fd2eceef1cc3b28f523beda4fd8dfb",
|
||||
"zh:9252068667bc6528ee6e83e837f3c2f901756136a33442455d61c6fa34e1160a",
|
||||
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
|
||||
"zh:9d086b792598b43e87502d47c4a3f388465b3a21a6a6b2783e48c89dee1f0543",
|
||||
"zh:b5e6e77a43c1655285d99145b2cf0cc2da7a6c6ea3531d000cf8cca2c717693b",
|
||||
"zh:b7ebe893e5ec76b362b61ffb28c67b40d890e0f59f5f2f8829765b16ee3e53b0",
|
||||
"zh:c8c1e186839ad3cba37b427181af1e62eaf06c6daa5dca29105e1981dfaeb4c2",
|
||||
"zh:e988377e7aea51e1fefe0b52c78bc725a11327051e20a71f81069191ee077d2d",
|
||||
"zh:ee9188027919459a48bf9bac8f8f1dd172f5be198b88c2c47789b6daa8bb8bcb",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
# This file is intentionally outside the default tests/ directory.
|
||||
# Do not run it without confirmation of the standing B4 approval conditions.
|
||||
|
||||
provider "aws" {
|
||||
region = var.region
|
||||
}
|
||||
|
||||
override_resource {
|
||||
target = module.network_public.aws_flow_log.s3
|
||||
values = { id = "fl-test-s3" }
|
||||
}
|
||||
|
||||
override_resource {
|
||||
target = module.network_public.aws_flow_log.cloudwatch
|
||||
values = { id = "fl-test-cloudwatch" }
|
||||
}
|
||||
|
||||
variables {
|
||||
region = "ap-northeast-3"
|
||||
name_prefix = "tftest-g3-8c2f"
|
||||
web_ami_id = "ami-0d82c759aab529d2d"
|
||||
test_public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHSftYPnELJxLgR9G8ftBeCIYo57KmlEc8A8BmqAHSLP tftest-g3-8c2f"
|
||||
}
|
||||
|
||||
run "apply_network_group3_osaka" {
|
||||
command = apply
|
||||
|
||||
assert {
|
||||
condition = length(output.vyos_route_network_interface_ids) == 5 && alltrue([
|
||||
for id in values(output.vyos_route_network_interface_ids) : id == output.route_target_network_interface_id
|
||||
])
|
||||
error_message = "All five VyOS routes must target the created substitute network interface."
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = length(output.vyos_source_security_group_ids) == 6 && alltrue([
|
||||
for id in values(output.vyos_source_security_group_ids) : id == output.vyos_source_security_group_id
|
||||
])
|
||||
error_message = "All six public ingress rules must reference the created substitute security group."
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = alltrue([
|
||||
for name in values(output.named_resources) : startswith(name, var.name_prefix)
|
||||
])
|
||||
error_message = "Every named Osaka test resource must use the dedicated prefix."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
module "network_public" {
|
||||
source = "../../modules/network_public"
|
||||
|
||||
region = var.region
|
||||
name_prefix = var.name_prefix
|
||||
protect_from_destroy = false
|
||||
|
||||
vpc = {
|
||||
cidr_block = "10.254.0.0/16"
|
||||
tags = { Name = "${var.name_prefix}-vpc" }
|
||||
}
|
||||
|
||||
subnets = {
|
||||
intra_a = {
|
||||
cidr_block = "10.254.110.0/24"
|
||||
availability_zone = "ap-northeast-3a"
|
||||
tags = { Name = "${var.name_prefix}-intra-a" }
|
||||
}
|
||||
dmz = {
|
||||
cidr_block = "10.254.1.0/24"
|
||||
availability_zone = "ap-northeast-3b"
|
||||
tags = { Name = "${var.name_prefix}-dmz" }
|
||||
}
|
||||
intra_d = {
|
||||
cidr_block = "10.254.120.0/24"
|
||||
availability_zone = "ap-northeast-3c"
|
||||
tags = { Name = "${var.name_prefix}-intra-c" }
|
||||
}
|
||||
}
|
||||
|
||||
route_table_tags = {
|
||||
dmz = { Name = "${var.name_prefix}-dmz-routes" }
|
||||
intra = { Name = "${var.name_prefix}-intra-routes" }
|
||||
}
|
||||
|
||||
internet_gateway_tags = { Name = "${var.name_prefix}-igw" }
|
||||
|
||||
route_destinations = {
|
||||
private_network_a = "192.0.2.0/24"
|
||||
private_network_b = "198.51.100.0/24"
|
||||
}
|
||||
|
||||
vyos_network_interface_id = aws_network_interface.route_target.id
|
||||
vyos_security_group_id = aws_security_group.vyos_source.id
|
||||
|
||||
dhcp_options = {
|
||||
domain_name = "${var.region}.compute.internal"
|
||||
domain_name_servers = ["AmazonProvidedDNS"]
|
||||
tags = { Name = "${var.name_prefix}-dhcp" }
|
||||
}
|
||||
|
||||
ssh_security_group = {
|
||||
description = "${var.name_prefix} public test security group"
|
||||
}
|
||||
|
||||
ssh_ingress_rules = {
|
||||
icmp_private = {
|
||||
description = "ICMP test network"
|
||||
ip_protocol = "icmp"
|
||||
cidr_ipv4 = "203.0.113.0/24"
|
||||
}
|
||||
icmp_vyos = {
|
||||
description = "ICMP from VyOS"
|
||||
ip_protocol = "icmp"
|
||||
use_vyos_security_group = true
|
||||
}
|
||||
ssh_vyos = {
|
||||
description = "SSH from VyOS"
|
||||
ip_protocol = "tcp"
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
use_vyos_security_group = true
|
||||
}
|
||||
http = {
|
||||
description = "HTTP"
|
||||
ip_protocol = "tcp"
|
||||
from_port = 80
|
||||
to_port = 80
|
||||
cidr_ipv4 = "0.0.0.0/0"
|
||||
}
|
||||
https = {
|
||||
description = "HTTPS"
|
||||
ip_protocol = "tcp"
|
||||
from_port = 443
|
||||
to_port = 443
|
||||
cidr_ipv4 = "0.0.0.0/0"
|
||||
}
|
||||
http3 = {
|
||||
description = "HTTP/3"
|
||||
ip_protocol = "udp"
|
||||
from_port = 443
|
||||
to_port = 443
|
||||
cidr_ipv4 = "0.0.0.0/0"
|
||||
}
|
||||
consul_server = {
|
||||
description = "Consul server from VyOS"
|
||||
ip_protocol = "tcp"
|
||||
from_port = 8300
|
||||
to_port = 8300
|
||||
use_vyos_security_group = true
|
||||
}
|
||||
consul_lan_tcp = {
|
||||
description = "Consul LAN TCP from VyOS"
|
||||
ip_protocol = "tcp"
|
||||
from_port = 8301
|
||||
to_port = 8301
|
||||
use_vyos_security_group = true
|
||||
}
|
||||
consul_lan_udp = {
|
||||
description = "Consul LAN UDP from VyOS"
|
||||
ip_protocol = "udp"
|
||||
from_port = 8301
|
||||
to_port = 8301
|
||||
use_vyos_security_group = true
|
||||
}
|
||||
ssh_admin = {
|
||||
description = "SSH test network"
|
||||
ip_protocol = "tcp"
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
cidr_ipv4 = "203.0.113.0/24"
|
||||
}
|
||||
ssh_git = {
|
||||
description = "SSH alternate port test network"
|
||||
ip_protocol = "tcp"
|
||||
from_port = 3843
|
||||
to_port = 3843
|
||||
cidr_ipv4 = "203.0.113.0/24"
|
||||
}
|
||||
wireguard = {
|
||||
description = "WireGuard"
|
||||
ip_protocol = "udp"
|
||||
from_port = 51820
|
||||
to_port = 51820
|
||||
cidr_ipv4 = "0.0.0.0/0"
|
||||
}
|
||||
prometheus = {
|
||||
description = "Prometheus from VyOS"
|
||||
ip_protocol = "tcp"
|
||||
from_port = 60000
|
||||
to_port = 60000
|
||||
use_vyos_security_group = true
|
||||
}
|
||||
}
|
||||
|
||||
web_instance = {
|
||||
ami = var.web_ami_id
|
||||
instance_type = "t3.small"
|
||||
subnet_key = "dmz"
|
||||
associate_public_ip_address = true
|
||||
source_dest_check = true
|
||||
ebs_optimized = true
|
||||
monitoring = false
|
||||
|
||||
metadata_options = {
|
||||
http_endpoint = "enabled"
|
||||
http_tokens = "required"
|
||||
http_put_response_hop_limit = 2
|
||||
http_protocol_ipv6 = "disabled"
|
||||
instance_metadata_tags = "disabled"
|
||||
}
|
||||
|
||||
root_block_device = {
|
||||
delete_on_termination = true
|
||||
encrypted = true
|
||||
volume_size = 8
|
||||
volume_type = "gp3"
|
||||
iops = 3000
|
||||
throughput = 125
|
||||
}
|
||||
|
||||
tags = { Purpose = "${var.name_prefix}-web-test" }
|
||||
}
|
||||
|
||||
key_pair = {
|
||||
public_key = var.test_public_key
|
||||
}
|
||||
|
||||
# These syntactically valid, isolated ARNs are never used by AWS in tests:
|
||||
# both Flow Log resources are explicitly overridden in each test file.
|
||||
flow_logs = {
|
||||
s3 = {
|
||||
destination_arn = "arn:aws:s3:::${var.name_prefix}-flow-logs"
|
||||
tags = { Name = "${var.name_prefix}-s3-flow-log" }
|
||||
}
|
||||
cloudwatch = {
|
||||
log_group_arn = "arn:aws:logs:${var.region}:${var.account_id}:log-group:/${var.name_prefix}/flowlogs"
|
||||
iam_role_arn = "arn:aws:iam::${var.account_id}:role/${var.name_prefix}-flow-logs"
|
||||
tags = { Name = "${var.name_prefix}-cloudwatch-flow-log" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "vyos_source" {
|
||||
region = var.region
|
||||
|
||||
name = "${var.name_prefix}-vyos-source"
|
||||
description = "Empty substitute for VyOS source references"
|
||||
vpc_id = module.network_public.vpc_id
|
||||
|
||||
tags = { Name = "${var.name_prefix}-vyos-source" }
|
||||
}
|
||||
|
||||
resource "aws_network_interface" "route_target" {
|
||||
region = var.region
|
||||
|
||||
subnet_id = module.network_public.subnet_ids["dmz"]
|
||||
security_groups = [aws_security_group.vyos_source.id]
|
||||
|
||||
tags = { Name = "${var.name_prefix}-route-target" }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
output "route_target_network_interface_id" {
|
||||
value = aws_network_interface.route_target.id
|
||||
}
|
||||
|
||||
output "vyos_source_security_group_id" {
|
||||
value = aws_security_group.vyos_source.id
|
||||
}
|
||||
|
||||
output "vyos_route_network_interface_ids" {
|
||||
value = module.network_public.vyos_route_network_interface_ids
|
||||
}
|
||||
|
||||
output "vyos_source_security_group_ids" {
|
||||
value = module.network_public.vyos_source_security_group_ids
|
||||
}
|
||||
|
||||
output "named_resources" {
|
||||
value = merge(
|
||||
module.network_public.named_resource_names,
|
||||
{
|
||||
route_target_network_interface = aws_network_interface.route_target.tags["Name"]
|
||||
vyos_source_security_group = aws_security_group.vyos_source.name
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
provider "aws" {
|
||||
region = var.region
|
||||
}
|
||||
|
||||
# Flow Logs need pre-existing destinations, including a global IAM role for
|
||||
# CloudWatch. Override only these two resources so the isolated test creates no
|
||||
# global resource and never refers to production destinations.
|
||||
override_resource {
|
||||
target = module.network_public.aws_flow_log.s3
|
||||
values = { id = "fl-test-s3" }
|
||||
}
|
||||
|
||||
override_resource {
|
||||
target = module.network_public.aws_flow_log.cloudwatch
|
||||
values = { id = "fl-test-cloudwatch" }
|
||||
}
|
||||
|
||||
# Stable computed IDs let plan-mode assertions verify the eleven links without
|
||||
# creating resources. The apply-mode file intentionally does not override these.
|
||||
override_resource {
|
||||
target = aws_security_group.vyos_source
|
||||
override_during = plan
|
||||
values = {
|
||||
id = "sg-00000000000000000"
|
||||
name = "tftest-g3-8c2f-vyos-source"
|
||||
}
|
||||
}
|
||||
|
||||
override_resource {
|
||||
target = aws_network_interface.route_target
|
||||
override_during = plan
|
||||
values = {
|
||||
id = "eni-00000000000000000"
|
||||
}
|
||||
}
|
||||
|
||||
variables {
|
||||
region = "ap-northeast-3"
|
||||
name_prefix = "tftest-g3-8c2f"
|
||||
web_ami_id = "ami-0d82c759aab529d2d"
|
||||
test_public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHSftYPnELJxLgR9G8ftBeCIYo57KmlEc8A8BmqAHSLP tftest-g3-8c2f"
|
||||
}
|
||||
|
||||
run "plan_network_group3_osaka" {
|
||||
command = plan
|
||||
|
||||
assert {
|
||||
condition = length(output.vyos_route_network_interface_ids) == 5 && alltrue([
|
||||
for id in values(output.vyos_route_network_interface_ids) : id == output.route_target_network_interface_id
|
||||
])
|
||||
error_message = "All five VyOS routes must target the substitute network interface."
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = length(output.vyos_source_security_group_ids) == 6 && alltrue([
|
||||
for id in values(output.vyos_source_security_group_ids) : id == output.vyos_source_security_group_id
|
||||
])
|
||||
error_message = "All six public ingress rules must reference the substitute security group."
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = alltrue([
|
||||
for name in values(output.named_resources) : startswith(name, var.name_prefix)
|
||||
])
|
||||
error_message = "Every named Osaka test resource must use the dedicated prefix."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
variable "account_id" {
|
||||
description = "AWS account ID used only to form syntactically valid test ARNs."
|
||||
type = string
|
||||
|
||||
validation {
|
||||
condition = can(regex("^[0-9]{12}$", var.account_id))
|
||||
error_message = "account_id must contain exactly 12 digits."
|
||||
}
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "Isolated test region."
|
||||
type = string
|
||||
default = "ap-northeast-3"
|
||||
}
|
||||
|
||||
variable "name_prefix" {
|
||||
description = "Dedicated prefix for every named test resource."
|
||||
type = string
|
||||
default = "tftest-g3-8c2f"
|
||||
}
|
||||
|
||||
variable "web_ami_id" {
|
||||
description = "Public Ubuntu 24.04 AMI available in the test region."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "test_public_key" {
|
||||
description = "Public-only test key. No private key is committed or used for a connection."
|
||||
type = string
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
required_version = "= 1.17.2"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "~> 6.73"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user