fix: add address family and respond appropriately (#87)
Signed-off-by: matttrach <matt.trachier@suse.com>
This commit is contained in:
parent
5fe2ce0fcd
commit
3c4f97af0d
|
|
@ -20,11 +20,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1719931832,
|
||||
"narHash": "sha256-0LD+KePCKKEb4CcPsTBOwf019wDtZJanjoKm1S8q3Do=",
|
||||
"lastModified": 1720498663,
|
||||
"narHash": "sha256-juqJkkdAt44mOfA43q1qUHn7iWoK++81lR8Mh7N/EF8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "0aeab749216e4c073cece5d34bc01b79e717c3e0",
|
||||
"rev": "106e145e1d4583d1e2bb20e54947d15ad55e75e1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
|||
2
main.tf
2
main.tf
|
|
@ -27,6 +27,7 @@ locals {
|
|||
server_type = var.server_type
|
||||
# tflint-ignore: terraform_unused_declarations
|
||||
fail_server_type = ((local.server_use_strategy == "create" && local.server_type == "") ? one([local.server_type, "missing_server_type"]) : false)
|
||||
server_ip_family = var.server_ip_family
|
||||
|
||||
# internal access
|
||||
server_subnet_name = var.subnet_name
|
||||
|
|
@ -117,6 +118,7 @@ module "server" {
|
|||
id = local.server_id
|
||||
name = local.server_name
|
||||
type = local.server_type
|
||||
ip_family = local.server_ip_family
|
||||
image = module.image[0].image
|
||||
subnet = local.server_subnet_name
|
||||
security_group = local.server_security_group_name
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ locals {
|
|||
type = var.type # the designation from types.tf
|
||||
# tflint-ignore: terraform_unused_declarations
|
||||
fail_type = (local.create == 1 && local.server_type == null ? one([local.type, "type_not_found"]) : false)
|
||||
ip_family = var.ip_family
|
||||
server_type = lookup(local.types, local.type, null)
|
||||
security_group = var.security_group # the name of the security group to find and assign to the server
|
||||
subnet = var.subnet # the name of the subnet to find and assign to the server
|
||||
|
|
@ -18,8 +19,8 @@ locals {
|
|||
ssh_key_name = var.ssh_key_name
|
||||
|
||||
ip = var.ip # private ip to assign to the server
|
||||
ipv4 = (strcontains(local.ip, ":") ? "" : local.ip)
|
||||
ipv6 = (strcontains(local.ip, ":") ? local.ip : "")
|
||||
ipv4 = (local.ip_family == "ipv4" ? "" : local.ip)
|
||||
ipv6 = (local.ip_family == "ipv6" ? local.ip : "")
|
||||
}
|
||||
|
||||
# select
|
||||
|
|
|
|||
|
|
@ -36,15 +36,27 @@ output "private_ip" {
|
|||
description = "The private IP address assigned to the instance"
|
||||
}
|
||||
output "public_ip" {
|
||||
value = try(data.aws_instance.selected[0].public_ip, aws_instance.created[0].public_ip, "")
|
||||
description = "The public IP address assigned to the instance"
|
||||
value = (
|
||||
local.create == 1 ? (
|
||||
local.ip_family == "ipv4" ? aws_instance.created[0].public_ip :
|
||||
local.ip_family == "ipv6" ? tolist(aws_instance.created[0].ipv6_addresses)[0] :
|
||||
null
|
||||
) :
|
||||
local.select == 1 ? (
|
||||
local.ip_family == "ipv4" ? data.aws_instance.selected[0].public_ip :
|
||||
local.ip_family == "ipv6" ? tolist(data.aws_instance.selected[0].ipv6_addresses)[0] :
|
||||
null
|
||||
) :
|
||||
null
|
||||
)
|
||||
description = "The primary public IP address assigned to the instance"
|
||||
}
|
||||
output "public_dns" {
|
||||
value = try(data.aws_instance.selected[0].public_dns, aws_instance.created[0].public_dns, "")
|
||||
description = "The public DNS name assigned to the instance"
|
||||
}
|
||||
output "ipv6_addresses" {
|
||||
value = try(data.aws_instance.selected[0].ipv6_addresses, aws_instance.created[0].ipv6_addresses, tolist([]))
|
||||
value = try(tolist(data.aws_instance.selected[0].ipv6_addresses), tolist(aws_instance.created[0].ipv6_addresses), tolist([]))
|
||||
description = "The IPv6 addresses for the instance"
|
||||
}
|
||||
output "network_interface_id" {
|
||||
|
|
|
|||
|
|
@ -71,6 +71,13 @@ variable "ip" {
|
|||
EOT
|
||||
default = ""
|
||||
}
|
||||
variable "ip_family" {
|
||||
type = string
|
||||
description = <<-EOT
|
||||
The IP family to use for the server.
|
||||
Must be either "ipv4" or "ipv6".
|
||||
EOT
|
||||
}
|
||||
variable "cloudinit" {
|
||||
type = string
|
||||
description = <<-EOT
|
||||
|
|
|
|||
15
variables.tf
15
variables.tf
|
|
@ -1,7 +1,7 @@
|
|||
# this server module must be aware of the system requirements of the application that will run on it
|
||||
# this is fundamental to generating servers, you need to know the size and how many servers you need
|
||||
# with that in mind we also need to know what ports to expose and how to route traffic
|
||||
# this module is generalized so that it can be used for any application
|
||||
# this module is generalized so that it can be used for any application, but tested with rke2 and Rancher in mind
|
||||
|
||||
#####
|
||||
# Feature: image
|
||||
|
|
@ -151,6 +151,19 @@ variable "server_type" {
|
|||
error_message = "If specified, this must be one of 'small', 'medium', 'large', 'xl', or 'xxl'."
|
||||
}
|
||||
}
|
||||
variable "server_ip_family" {
|
||||
type = string
|
||||
description = <<-EOT
|
||||
The ip family to use for the server, must be one of "ipv4" or "ipv6".
|
||||
Use ipv4 for dualstack, ipv6 should only be used for ipv6 only deployments.
|
||||
When adding an EIP, this should be 'ipv4'.
|
||||
EOT
|
||||
default = "ipv4"
|
||||
validation {
|
||||
condition = contains(["ipv4", "ipv6"], var.server_ip_family)
|
||||
error_message = "This must be one of 'ipv4' or 'ipv6'."
|
||||
}
|
||||
}
|
||||
variable "cloudinit_use_strategy" {
|
||||
type = string
|
||||
description = <<-EOT
|
||||
|
|
|
|||
Loading…
Reference in New Issue