Sidecar Container

The Sidecar resource allows you to run associated processes for containers. Sidecar does not have its own network, a sidecar resource shares the network with the target container. For example, localhost in the sidecar is localhost in the container.

Sidecar resources are not routable in the same way as container resources are. You can not map an ingress to a sidecar and a sidecar can not expose ports. Traffic which is destined for a process running in a sidecar must be sent to the target container.

Examples

resource "container" "consul" {
  image {
    name = "consul:${variable.consul_version}"
  }

  command = ["consul", "agent", "-config-file", "/config/config.hcl"]

  volume {
    source      = "./"
    destination = "/files"
  }

  volume {
    source      = resource.template.consul_config.destination
    destination = "/config/config.hcl"
  }

  network {
    id         = resource.network.onprem.meta.id
    ip_address = "10.6.0.200" // optional
    aliases    = ["myalias"]
  }

  environment = {
    something       = variable.something
    foo             = env("BAH")
    file            = file("./conf.txt")
    abc             = "123"
    SHIPYARD_FOLDER = shipyard()
    HOME_FOLDER     = home()
  }
  
  port_range {
    range       = "8500-8502"
    enable_host = true
  }

}

resource "sidecar" "envoy" {
  target = resource.container.consul.meta.id

  image {
    name = "envoyproxy/envoy:v${variable.envoy_version}"
  }

  command = ["tail", "-f", "/dev/null"]

  volume {
    source      = data("config")
    destination = "/config"
  }
}

Last updated