π Resource Documentation: portainer_docker_network
The portainer_docker_network resource allows you to manage Docker networks on a specific environment (endpoint) in Portainer.
You can define bridge or overlay networks, including driver-specific options, labels, and IPAM settings.
Create a basic bridge network
resource "portainer_docker_network" "bridge_network" {
endpoint_id = 1
name = " new-bridge-network"
}
Create an attachable bridge network with options and labels
resource "portainer_docker_network" "bridge_network_with_configuration" {
endpoint_id = 1
name = " new-bridge-network-with-configuration"
attachable = true
options = {
" com.docker.network.bridge.enable_icc" = " true"
" com.docker.network.bridge.enable_ip_masquerade" = " true"
}
labels = {
" env" = " test"
" project" = " terraform"
}
}
Create a network with custom IPAM config
resource "portainer_docker_network" "network_with_ipam" {
endpoint_id = 1
name = " new-ipam-network"
driver = " bridge"
attachable = true
ipam_driver = " default"
ipam_config {
subnet = " 192.168.100.0/24"
gateway = " 192.168.100.1"
ip_range = " 192.168.100.0/25"
}
ipam_options = {
foo = " bar"
}
}
To delete a docker netowrk created via Terraform, simply run:
Docker networks are immutable in Portainer. To update, you must destroy and recreate them.
To modify a name (e.g., make it dynamic), update the attributes and re-apply:
Name
Type
Required
Description
endpoint_id
int
β
yes
ID of the environment where the network will be created
name
string
β
yes
Name of the Docker network
driver
string
π« optional
Network driver (bridge, overlay, macvlan, etc.), default: bridge
scope
string
π« optional
Network scope (local, swarm), default: local
internal
bool
π« optional
Whether the network is internal (default: false)
attachable
bool
π« optional
Whether containers can be attached manually (default: false)
ingress
bool
π« optional
Whether it's an ingress network (default: false)
config_only
bool
π« optional
If this network is only configuration (default: false)
config_from
string
π« optional
Name of another config-only network to inherit from
enable_ipv4
bool
π« optional
Enable IPv4 networking (default: true)
enable_ipv6
bool
π« optional
Enable IPv6 networking (default: false)
options
map(string)
π« optional
Driver-specific options
labels
map(string)
π« optional
Labels to apply to the network
swarm_node_id
string
π« optional
Name of the swarm node to target when creating config-only networks
ipam_driver
string
π« optional
IPAM driver name (default: default)
ipam_options
map(string)
π« optional
IPAM driver-specific options
ipam_config
block
π« optional
IPAM configuration block (can be repeated)
Name
Type
Required
Description
subnet
string
β
yes
The subnet in CIDR format (e.g. 192.168.0.0/24)
ip_range
string
π« no
Optional IP range within the subnet
gateway
string
π« no
Gateway IP for the subnet
auxiliary_addresses
map(string)
π« no
Optional key-value pairs of reserved addresses
Name
Description
id
ID of the created Docker network (as returned by Portainer)
resource_control_id
ID of the automatically generated Portainer ResourceControl for this network