linyinli / terraform-docker-containerservice

Deploy containerized Service on Docker.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker Container Service

Terraform module which deploys container service on Docker.

Usage

module "example" {
  source = "..."

  infrastructure = {
    network_id = "..."
  }

  containers = [
    {
      image     = "nginx:alpine"
      resources = {
        cpu    = 0.1
        memory = 100                 # in megabyte
      }
      ports = [
        {
          internal = 80
          external = 80
        }
      ]
      checks = [
        {
          delay = 10
          type  = "http"
          http = {
            port = 80
          }
        }
      ]
    }
  ]
}

Examples

Contributing

Please read our contributing guide if you're interested in contributing to Walrus template.

Requirements

Name Version
terraform >= 1.0
docker >= 3.0.2
local >= 2.4.0
random >= 3.5.1

Providers

Name Version
docker >= 3.0.2
local >= 2.4.0
random >= 3.5.1
terraform n/a

Modules

No modules.

Resources

Name Type
docker_container.inits resource
docker_container.pause resource
docker_container.runs resource
docker_container.unhealthy_restart resource
docker_image.inits resource
docker_image.pause resource
docker_image.runs resource
docker_image.unhealthy_restart resource
docker_volume.ephemeral_volumes resource
local_file.ephemeral_files resource
random_string.name_suffix resource
terraform_data.run_checks resource
terraform_data.run_executes resource
terraform_data.run_resources resource
docker_network.network data source
docker_registry_image.inits data source
docker_registry_image.pause data source
docker_registry_image.runs data source
docker_registry_image.unhealthy_restart data source

Inputs

Name Description Type Default Required
containers Specify the container items to deploy.

Examples:
containers:
- profile: init/run
image: string
execute:
working_dir: string, optional
command: list(string), optional
args: list(string), optional
readonly_rootfs: bool, optional
as_user: number, optional
as_group: number, optional
privileged: bool, optional
resources:
cpu: number, optional # in oneCPU, i.e. 0.25, 0.5, 1, 2, 4
memory: number, optional # in megabyte
gpu: number, optional # in oneGPU, i.e. 1, 2, 4
envs:
- name: string
value: string, optional
value_refer:
schema: string
params: map(any)
files:
- path: string
mode: string, optional
accept_changed: bool, optional # accpet changed
content: string, optional
content_refer:
schema: string
params: map(any)
mounts:
- path: string
readonly: bool, optional
subpath: string, optional
volume: string, optional # shared between containers if named, otherwise exclusively by this container
volume_refer:
schema: string
params: map(any)
ports:
- internal: number
external: number, optional
protocol: tcp/udp
schema: string, optional
checks: # maximum 1 check
- type: execute/tcp/http/https
delay: number, optional
interval: number, optional
timeout: number, optional
retries: number, optional
teardown: bool, optional
execute:
command: list(string)
tcp:
port: number
http:
port: number
headers: map(string), optional
path: string, optional
https:
port: number
headers: map(string), optional
path: string, optional
list(object({
profile = optional(string, "run")
image = string
execute = optional(object({
working_dir = optional(string)
command = optional(list(string))
args = optional(list(string))
readonly_rootfs = optional(bool, false)
as_user = optional(number)
as_group = optional(number)
privileged = optional(bool, false)
}))
resources = optional(object({
cpu = optional(number, 0.25)
memory = optional(number, 256)
gpu = optional(number, 0)
}))
envs = optional(list(object({
name = string
value = optional(string)
value_refer = optional(object({
schema = string
params = map(any)
}))
})))
files = optional(list(object({
path = string
mode = optional(string, "0644")
accept_changed = optional(bool, false)
content = optional(string)
content_refer = optional(object({
schema = string
params = map(any)
}))
})))
mounts = optional(list(object({
path = string
readonly = optional(bool, false)
subpath = optional(string)
volume = optional(string)
volume_refer = optional(object({
schema = string
params = map(any)
}))
})))
ports = optional(list(object({
internal = number
external = optional(number)
protocol = optional(string, "tcp")
schema = optional(string)
})))
checks = optional(list(object({
type = string
delay = optional(number, 0)
interval = optional(number, 10)
timeout = optional(number, 1)
retries = optional(number, 1)
teardown = optional(bool, false)
execute = optional(object({
command = list(string)
}))
tcp = optional(object({
port = number
}))
http = optional(object({
port = number
headers = optional(map(string))
path = optional(string, "/")
}))
https = optional(object({
port = number
headers = optional(map(string))
path = optional(string, "/")
}))
})))
}))
n/a yes
context Receive contextual information. When Walrus deploys, Walrus will inject specific contextual information into this field.

Examples:
context:
project:
name: string
id: string
environment:
name: string
id: string
resource:
name: string
id: string
map(any) {} no
deployment Specify the deployment action.

Examples:
deployment:
fs_group: number, optional
sysctls:
- name: string
value: string
object({
fs_group = optional(number)
sysctls = optional(list(object({
name = string
value = string
})))
})
{} no
infrastructure Specify the infrastructure information for deploying.

Examples:
infrastructure:
network_id: string, optional
domain_suffix: string, optional
pause_image: string, optional # keep worker containers crashing or restarting without losing the network.
unhealthy_restart_image: string, optional # restart the unhealthy containers, moby/moby#22719.
object({
network_id = optional(string, "local-walrus")
domain_suffix = optional(string, "cluster.local")
pause_image = optional(string, "docker/desktop-kubernetes-pause:3.9")
unhealthy_restart_image = optional(string, "willfarrell/autoheal:latest")
})
{
"domain_suffix": "cluster.local",
"network_id": "local-walrus",
"pause_image": "docker/desktop-kubernetes-pause:3.9",
"unhealthy_restart_image": "willfarrell/autoheal:latest"
}
no

Outputs

Name Description
address The address, a string only has host, might be a comma separated string or a single string.
connection The connection, a string combined host and port, might be a comma separated string or a single string.
context The input context, a map, which is used for orchestration.
endpoints The endpoints, a string map, the key is the name, and the value is the URL.
ports The port list of the service.
refer The refer, a map, including hosts, ports and account, which is used for dependencies or collaborations.

License

Copyright (c) 2023 Seal, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at LICENSE file for details.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Deploy containerized Service on Docker.

License:Apache License 2.0


Languages

Language:HCL 56.2%Language:Shell 41.4%Language:Makefile 2.4%