From 1b6cbe880c610a1cfd8254a472c2b5429dfce359 Mon Sep 17 00:00:00 2001
From: Matthew Baggett <matthew@baggett.me>
Date: Wed, 29 Jan 2025 19:20:47 +0100
Subject: [PATCH] add stubs for iperf and http2https

---
 products/http2https/http2https.tf | 10 ++++++
 products/http2https/inputs.tf     | 53 +++++++++++++++++++++++++++++++
 products/http2https/outputs.tf    | 12 +++++++
 products/http2https/terraform.tf  | 16 ++++++++++
 products/iperf/inputs.tf          | 53 +++++++++++++++++++++++++++++++
 products/iperf/iperf.tf           | 10 ++++++
 products/iperf/outputs.tf         | 12 +++++++
 products/iperf/terraform.tf       | 16 ++++++++++
 8 files changed, 182 insertions(+)
 create mode 100644 products/http2https/http2https.tf
 create mode 100644 products/http2https/inputs.tf
 create mode 100644 products/http2https/outputs.tf
 create mode 100644 products/http2https/terraform.tf
 create mode 100644 products/iperf/inputs.tf
 create mode 100644 products/iperf/iperf.tf
 create mode 100644 products/iperf/outputs.tf
 create mode 100644 products/iperf/terraform.tf

diff --git a/products/http2https/http2https.tf b/products/http2https/http2https.tf
new file mode 100644
index 0000000..eb8f0c4
--- /dev/null
+++ b/products/http2https/http2https.tf
@@ -0,0 +1,10 @@
+module "service" {
+  source                = "../../docker/service"
+  image                 = "${var.http2https_image}:${var.http2https_version}"
+  stack_name            = var.stack_name
+  service_name          = var.service_name
+  networks              = var.networks
+  converge_enable       = false # @todo MB: fix healthcheck and fix this.
+  ports                 = var.ports
+  placement_constraints = var.placement_constraints
+}
diff --git a/products/http2https/inputs.tf b/products/http2https/inputs.tf
new file mode 100644
index 0000000..0c2ca52
--- /dev/null
+++ b/products/http2https/inputs.tf
@@ -0,0 +1,53 @@
+variable "http2https_image" {
+  default     = "articulate/http-to-https"
+  type        = string
+  description = "The docker image to use for the MemcacheD service."
+}
+variable "http2https_version" {
+  default     = "latest"
+  type        = string
+  description = "The version of the docker image to use for the MemcacheD service."
+}
+# Pass-thru variables
+variable "stack_name" {
+  type = string
+}
+variable "service_name" {
+  default     = "iperf3"
+  type        = string
+  description = "The name of the service to create."
+}
+variable "networks" {
+  type = list(object({
+    name = string
+    id   = string
+  }))
+  default     = []
+  description = "A list of network names to attach the service to."
+}
+variable "ports" {
+  type = list(object({
+    host      = optional(number)
+    container = number
+    protocol  = optional(string, "tcp")
+  }))
+  default     = []
+  description = "A map of port mappings to expose on the host. The key is the host port, and the value is the container port."
+  validation {
+    error_message = "Host Ports must be between 1 and 65535 or null."
+    condition     = alltrue([for port in var.ports : port.host == null ? true : (port.host >= 1 && port.host <= 65535)])
+  }
+  validation {
+    error_message = "Container Ports must be between 1 and 65535."
+    condition     = alltrue([for port in var.ports : port.container >= 1 && port.container <= 65535])
+  }
+  validation {
+    error_message = "Protocol must be either 'tcp' or 'udp'."
+    condition     = alltrue([for port in var.ports : port.protocol == "tcp" || port.protocol == "udp"])
+  }
+}
+variable "placement_constraints" {
+  default     = []
+  type        = list(string)
+  description = "Docker Swarm placement constraints"
+}
diff --git a/products/http2https/outputs.tf b/products/http2https/outputs.tf
new file mode 100644
index 0000000..e80d24f
--- /dev/null
+++ b/products/http2https/outputs.tf
@@ -0,0 +1,12 @@
+output "service_name" {
+  value = module.service.service_name
+}
+output "ports" {
+  value = module.service.ports
+}
+output "docker_service" {
+  value = module.service.docker_service
+}
+output "endpoint" {
+  value = "tcp://${module.service.service_name}:5201/"
+}
\ No newline at end of file
diff --git a/products/http2https/terraform.tf b/products/http2https/terraform.tf
new file mode 100644
index 0000000..263a49f
--- /dev/null
+++ b/products/http2https/terraform.tf
@@ -0,0 +1,16 @@
+terraform {
+  required_version = "~> 1.6"
+
+  required_providers {
+    docker = {
+      source  = "kreuzwerker/docker"
+      version = "~>3.0"
+    }
+    random = {
+      source  = "hashicorp/random"
+      version = "~> 3.5"
+    }
+  }
+}
+
+
diff --git a/products/iperf/inputs.tf b/products/iperf/inputs.tf
new file mode 100644
index 0000000..f6f320f
--- /dev/null
+++ b/products/iperf/inputs.tf
@@ -0,0 +1,53 @@
+variable "iperf_image" {
+  default     = "loganmarchione/docker-iperf3"
+  type        = string
+  description = "The docker image to use for the MemcacheD service."
+}
+variable "iperf_version" {
+  default     = "latest"
+  type        = string
+  description = "The version of the docker image to use for the MemcacheD service."
+}
+# Pass-thru variables
+variable "stack_name" {
+  type = string
+}
+variable "service_name" {
+  default     = "http2https"
+  type        = string
+  description = "The name of the service to create."
+}
+variable "networks" {
+  type = list(object({
+    name = string
+    id   = string
+  }))
+  default     = []
+  description = "A list of network names to attach the service to."
+}
+variable "ports" {
+  type = list(object({
+    host      = optional(number)
+    container = number
+    protocol  = optional(string, "tcp")
+  }))
+  default     = []
+  description = "A map of port mappings to expose on the host. The key is the host port, and the value is the container port."
+  validation {
+    error_message = "Host Ports must be between 1 and 65535 or null."
+    condition     = alltrue([for port in var.ports : port.host == null ? true : (port.host >= 1 && port.host <= 65535)])
+  }
+  validation {
+    error_message = "Container Ports must be between 1 and 65535."
+    condition     = alltrue([for port in var.ports : port.container >= 1 && port.container <= 65535])
+  }
+  validation {
+    error_message = "Protocol must be either 'tcp' or 'udp'."
+    condition     = alltrue([for port in var.ports : port.protocol == "tcp" || port.protocol == "udp"])
+  }
+}
+variable "placement_constraints" {
+  default     = []
+  type        = list(string)
+  description = "Docker Swarm placement constraints"
+}
diff --git a/products/iperf/iperf.tf b/products/iperf/iperf.tf
new file mode 100644
index 0000000..1200cfc
--- /dev/null
+++ b/products/iperf/iperf.tf
@@ -0,0 +1,10 @@
+module "service" {
+  source                = "../../docker/service"
+  image                 = "${var.iperf_image}:${var.iperf_version}"
+  stack_name            = var.stack_name
+  service_name          = var.service_name
+  networks              = var.networks
+  converge_enable       = false # @todo MB: fix healthcheck and fix this.
+  ports                 = var.ports
+  placement_constraints = var.placement_constraints
+}
diff --git a/products/iperf/outputs.tf b/products/iperf/outputs.tf
new file mode 100644
index 0000000..e80d24f
--- /dev/null
+++ b/products/iperf/outputs.tf
@@ -0,0 +1,12 @@
+output "service_name" {
+  value = module.service.service_name
+}
+output "ports" {
+  value = module.service.ports
+}
+output "docker_service" {
+  value = module.service.docker_service
+}
+output "endpoint" {
+  value = "tcp://${module.service.service_name}:5201/"
+}
\ No newline at end of file
diff --git a/products/iperf/terraform.tf b/products/iperf/terraform.tf
new file mode 100644
index 0000000..263a49f
--- /dev/null
+++ b/products/iperf/terraform.tf
@@ -0,0 +1,16 @@
+terraform {
+  required_version = "~> 1.6"
+
+  required_providers {
+    docker = {
+      source  = "kreuzwerker/docker"
+      version = "~>3.0"
+    }
+    random = {
+      source  = "hashicorp/random"
+      version = "~> 3.5"
+    }
+  }
+}
+
+