Add group 4 VyOS imports
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
resource "aws_instance" "protected" {
|
||||
count = var.protect_from_destroy ? 1 : 0
|
||||
|
||||
region = var.region
|
||||
ami = var.instance.ami
|
||||
instance_type = var.instance.instance_type
|
||||
subnet_id = var.subnet_id
|
||||
private_ip = var.instance.private_ip
|
||||
vpc_security_group_ids = [local.security_group.id]
|
||||
key_name = var.key_name
|
||||
associate_public_ip_address = var.instance.associate_public_ip_address
|
||||
source_dest_check = var.instance.source_dest_check
|
||||
ebs_optimized = var.instance.ebs_optimized
|
||||
monitoring = var.instance.monitoring
|
||||
|
||||
metadata_options {
|
||||
http_endpoint = var.instance.metadata_options.http_endpoint
|
||||
http_tokens = var.instance.metadata_options.http_tokens
|
||||
http_put_response_hop_limit = var.instance.metadata_options.http_put_response_hop_limit
|
||||
http_protocol_ipv6 = var.instance.metadata_options.http_protocol_ipv6
|
||||
instance_metadata_tags = var.instance.metadata_options.instance_metadata_tags
|
||||
}
|
||||
|
||||
root_block_device {
|
||||
delete_on_termination = var.instance.root_block_device.delete_on_termination
|
||||
encrypted = var.instance.root_block_device.encrypted
|
||||
volume_size = var.instance.root_block_device.volume_size
|
||||
volume_type = var.instance.root_block_device.volume_type
|
||||
iops = var.instance.root_block_device.iops
|
||||
throughput = var.instance.root_block_device.throughput
|
||||
}
|
||||
|
||||
tags = merge(var.instance.tags, { Name = local.instance_name })
|
||||
|
||||
lifecycle {
|
||||
prevent_destroy = true
|
||||
# The deregistered AMI and user data remain externally managed. Import and
|
||||
# refresh still read user data into state; ignore_changes only hides drift.
|
||||
ignore_changes = [ami, user_data, user_data_base64]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_instance" "unprotected" {
|
||||
count = var.protect_from_destroy ? 0 : 1
|
||||
|
||||
region = var.region
|
||||
ami = var.instance.ami
|
||||
instance_type = var.instance.instance_type
|
||||
subnet_id = var.subnet_id
|
||||
private_ip = var.instance.private_ip
|
||||
vpc_security_group_ids = [local.security_group.id]
|
||||
key_name = var.key_name
|
||||
associate_public_ip_address = var.instance.associate_public_ip_address
|
||||
source_dest_check = var.instance.source_dest_check
|
||||
ebs_optimized = var.instance.ebs_optimized
|
||||
monitoring = var.instance.monitoring
|
||||
|
||||
metadata_options {
|
||||
http_endpoint = var.instance.metadata_options.http_endpoint
|
||||
http_tokens = var.instance.metadata_options.http_tokens
|
||||
http_put_response_hop_limit = var.instance.metadata_options.http_put_response_hop_limit
|
||||
http_protocol_ipv6 = var.instance.metadata_options.http_protocol_ipv6
|
||||
instance_metadata_tags = var.instance.metadata_options.instance_metadata_tags
|
||||
}
|
||||
|
||||
root_block_device {
|
||||
delete_on_termination = var.instance.root_block_device.delete_on_termination
|
||||
encrypted = var.instance.root_block_device.encrypted
|
||||
volume_size = var.instance.root_block_device.volume_size
|
||||
volume_type = var.instance.root_block_device.volume_type
|
||||
iops = var.instance.root_block_device.iops
|
||||
throughput = var.instance.root_block_device.throughput
|
||||
}
|
||||
|
||||
tags = merge(var.instance.tags, { Name = local.instance_name })
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [ami, user_data, user_data_base64]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
locals {
|
||||
security_group = var.protect_from_destroy ? aws_security_group.protected[0] : aws_security_group.unprotected[0]
|
||||
instance = var.protect_from_destroy ? aws_instance.protected[0] : aws_instance.unprotected[0]
|
||||
|
||||
security_group_name = coalesce(var.security_group.name, "${var.name_prefix}-vyos-router")
|
||||
instance_name = coalesce(var.instance.name, "${var.name_prefix}-vyos")
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
output "instance_id" {
|
||||
description = "Managed VyOS instance ID."
|
||||
value = local.instance.id
|
||||
}
|
||||
|
||||
output "primary_network_interface_id" {
|
||||
description = "Managed VyOS primary network interface ID for route targets."
|
||||
value = local.instance.primary_network_interface_id
|
||||
}
|
||||
|
||||
output "security_group_id" {
|
||||
description = "Managed VyOS security group ID for referenced ingress rules."
|
||||
value = local.security_group.id
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
resource "aws_security_group" "protected" {
|
||||
count = var.protect_from_destroy ? 1 : 0
|
||||
|
||||
region = var.region
|
||||
|
||||
name = local.security_group_name
|
||||
description = var.security_group.description
|
||||
vpc_id = var.vpc_id
|
||||
tags = var.security_group.tags
|
||||
|
||||
lifecycle {
|
||||
prevent_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "unprotected" {
|
||||
count = var.protect_from_destroy ? 0 : 1
|
||||
|
||||
region = var.region
|
||||
|
||||
name = local.security_group_name
|
||||
description = var.security_group.description
|
||||
vpc_id = var.vpc_id
|
||||
tags = var.security_group.tags
|
||||
}
|
||||
|
||||
resource "aws_vpc_security_group_ingress_rule" "this" {
|
||||
for_each = var.ingress_rules
|
||||
|
||||
region = var.region
|
||||
security_group_id = local.security_group.id
|
||||
description = each.value.description
|
||||
ip_protocol = each.value.ip_protocol
|
||||
from_port = each.value.from_port
|
||||
to_port = each.value.to_port
|
||||
cidr_ipv4 = each.value.cidr_ipv4
|
||||
}
|
||||
|
||||
resource "aws_vpc_security_group_egress_rule" "all_ipv4" {
|
||||
region = var.region
|
||||
|
||||
security_group_id = local.security_group.id
|
||||
ip_protocol = "-1"
|
||||
cidr_ipv4 = "0.0.0.0/0"
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
variable "region" {
|
||||
description = "AWS region for the managed VyOS network path."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "name_prefix" {
|
||||
description = "Prefix used for isolated copies when an explicit production name is omitted."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "protect_from_destroy" {
|
||||
description = "Protect the VyOS instance and security group from destroy. prod は true 固定。既存 workspace で true→false に反転しない。"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "vpc_id" {
|
||||
description = "Existing VPC ID containing the VyOS security group."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "subnet_id" {
|
||||
description = "Existing subnet ID containing the VyOS primary network interface."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "key_name" {
|
||||
description = "Existing EC2 key pair name used by VyOS."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "security_group" {
|
||||
description = "Existing VyOS security group configuration."
|
||||
type = object({
|
||||
name = optional(string)
|
||||
description = string
|
||||
tags = optional(map(string), {})
|
||||
})
|
||||
}
|
||||
|
||||
variable "ingress_rules" {
|
||||
description = "Existing VyOS ingress rules keyed by a stable logical name, one CIDR per resource."
|
||||
type = map(object({
|
||||
description = optional(string)
|
||||
ip_protocol = string
|
||||
from_port = optional(number)
|
||||
to_port = optional(number)
|
||||
cidr_ipv4 = string
|
||||
}))
|
||||
}
|
||||
|
||||
variable "instance" {
|
||||
description = "Existing VyOS EC2 instance. user_data is intentionally absent."
|
||||
type = object({
|
||||
name = optional(string)
|
||||
ami = string
|
||||
instance_type = string
|
||||
private_ip = string
|
||||
associate_public_ip_address = bool
|
||||
source_dest_check = bool
|
||||
ebs_optimized = bool
|
||||
monitoring = bool
|
||||
metadata_options = object({
|
||||
http_endpoint = string
|
||||
http_tokens = string
|
||||
http_put_response_hop_limit = number
|
||||
http_protocol_ipv6 = string
|
||||
instance_metadata_tags = string
|
||||
})
|
||||
root_block_device = object({
|
||||
delete_on_termination = bool
|
||||
encrypted = bool
|
||||
volume_size = number
|
||||
volume_type = string
|
||||
iops = optional(number)
|
||||
throughput = optional(number)
|
||||
})
|
||||
tags = optional(map(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