first commit
This commit is contained in:
47
modules/01-networking/docker-network/README.md
Normal file
47
modules/01-networking/docker-network/README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Docker Network Module
|
||||
|
||||
This module creates a Docker network that allows containers to communicate with each other using container names as hostnames.
|
||||
|
||||
## Purpose
|
||||
|
||||
The module is designed to create a consistent Docker network for all homelab services, enabling direct container-to-container communication using container names instead of IP addresses.
|
||||
|
||||
## Usage
|
||||
|
||||
```hcl
|
||||
module "homelab_network" {
|
||||
source = "../modules/01-networking/docker-network"
|
||||
|
||||
network_name = "homelab-network"
|
||||
driver = "bridge"
|
||||
|
||||
# Optional: Configure specific subnet (uncomment if needed)
|
||||
# subnet = "172.20.0.0/16"
|
||||
# gateway = "172.20.0.1"
|
||||
}
|
||||
```
|
||||
|
||||
## Input Variables
|
||||
|
||||
| Name | Description | Type | Default | Required |
|
||||
|------|-------------|------|---------|----------|
|
||||
| `network_name` | Name of the Docker network | `string` | N/A | Yes |
|
||||
| `driver` | Network driver to use | `string` | `"bridge"` | No |
|
||||
| `internal` | Restrict external access if true | `bool` | `false` | No |
|
||||
| `attachable` | Enable manual container attachment | `bool` | `true` | No |
|
||||
| `ipam_driver` | IP address management driver | `string` | `"default"` | No |
|
||||
| `subnet` | Subnet in CIDR format | `string` | `""` | No |
|
||||
| `gateway` | Gateway IP for the subnet | `string` | `""` | No |
|
||||
| `ip_range` | Range for container IP allocation | `string` | `""` | No |
|
||||
| `aux_address` | Auxiliary addresses for driver | `map(string)` | `{}` | No |
|
||||
| `labels` | Docker labels to add to the network | `map(string)` | `{}` | No |
|
||||
| `options` | Driver-specific options | `map(string)` | `{}` | No |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| `network_id` | The ID of the created Docker network |
|
||||
| `network_name` | The name of the Docker network |
|
||||
| `network_driver` | The driver of the Docker network |
|
||||
| `ipam_config` | The IPAM configuration of the network |
|
||||
31
modules/01-networking/docker-network/main.tf
Normal file
31
modules/01-networking/docker-network/main.tf
Normal file
@@ -0,0 +1,31 @@
|
||||
// Docker Network Module
|
||||
// This module creates a Docker network for container communication
|
||||
|
||||
terraform {
|
||||
required_providers {
|
||||
docker = {
|
||||
source = "kreuzwerker/docker"
|
||||
version = "~> 3.6.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "docker_network" "this" {
|
||||
name = var.name
|
||||
driver = var.driver
|
||||
internal = var.internal
|
||||
attachable = var.attachable
|
||||
ipam_driver = var.ipam_driver
|
||||
|
||||
dynamic "ipam_config" {
|
||||
for_each = var.subnet != "" ? [1] : []
|
||||
content {
|
||||
subnet = var.subnet
|
||||
gateway = var.gateway
|
||||
ip_range = var.ip_range
|
||||
aux_address = var.aux_address
|
||||
}
|
||||
}
|
||||
|
||||
options = var.options
|
||||
}
|
||||
21
modules/01-networking/docker-network/outputs.tf
Normal file
21
modules/01-networking/docker-network/outputs.tf
Normal file
@@ -0,0 +1,21 @@
|
||||
// Outputs for Docker Network module
|
||||
|
||||
output "network_id" {
|
||||
description = "The ID of the Docker network"
|
||||
value = docker_network.this.id
|
||||
}
|
||||
|
||||
output "name" {
|
||||
description = "The name of the Docker network"
|
||||
value = docker_network.this.name
|
||||
}
|
||||
|
||||
output "network_driver" {
|
||||
description = "The driver of the Docker network"
|
||||
value = docker_network.this.driver
|
||||
}
|
||||
|
||||
output "ipam_config" {
|
||||
description = "The IPAM configuration of the Docker network"
|
||||
value = docker_network.this.ipam_config
|
||||
}
|
||||
64
modules/01-networking/docker-network/variables.tf
Normal file
64
modules/01-networking/docker-network/variables.tf
Normal file
@@ -0,0 +1,64 @@
|
||||
variable "name" {
|
||||
description = "Name of the Docker network"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "driver" {
|
||||
description = "Name of the network driver to use"
|
||||
type = string
|
||||
default = "bridge"
|
||||
}
|
||||
|
||||
variable "internal" {
|
||||
description = "Restrict external access to the network if true"
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "attachable" {
|
||||
description = "Enable manual container attachment if true"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "ipam_driver" {
|
||||
description = "Driver used for IP address management"
|
||||
type = string
|
||||
default = "default"
|
||||
}
|
||||
|
||||
variable "subnet" {
|
||||
description = "Subnet in CIDR format that represents a network segment"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "gateway" {
|
||||
description = "IPv4 or IPv6 gateway for the subnet"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "ip_range" {
|
||||
description = "Range of IPs from which to allocate container IPs"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "aux_address" {
|
||||
description = "Auxiliary IPv4 or IPv6 addresses used by the driver"
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "labels" {
|
||||
description = "Labels to add to the network"
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "options" {
|
||||
description = "Network driver specific options"
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
Reference in New Issue
Block a user