Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

networks_advanced forces replacement #648

Open
OlegKunitsyn opened this issue Sep 23, 2024 · 0 comments
Open

networks_advanced forces replacement #648

OlegKunitsyn opened this issue Sep 23, 2024 · 0 comments

Comments

@OlegKunitsyn
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and docker Provider) Version

Affected Resource(s)

  • docker_service

Terraform Configuration Files

terraform {
  required_providers {
    docker = {
      source = "kreuzwerker/docker"
    }
  }
}
variable "swarm_host" {
  type = string
}
provider "docker" {
  host = var.swarm_host
  ssh_opts = ["-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null"]
}

resource "docker_volume" "caddy" {
  name = "caddy"
}

resource "docker_network" "caddy" {
  name   = "caddy"
  driver = "overlay"
}

resource "docker_image" "caddy" {
  name = "lucaslorentz/caddy-docker-proxy:2.9.1"
  keep_locally = false
}

resource "docker_image" "nginx" {
  name = "nginx:1.27.1"
  keep_locally = false
}

resource "docker_service" "caddy" {
  name = "caddy"
  depends_on = [docker_volume.caddy]
  task_spec {
    force_update = 0
    networks_advanced {
      name = docker_network.caddy.name
    }
    container_spec {
      image = docker_image.caddy.image_id
      env = {
        CADDY_DOCKER_MODE = "swarm"
        DOCKER_HOST = "unix:///var/run/docker.sock"
        CADDY_INGRESS_NETWORK = docker_network.caddy.name
        CADDY_ACME_EMAIL = "info@example.com",
        CADDY_STORAGE = "/data/caddy"
      }
      mounts {
        type   = "bind"
        target = "/var/run/docker.sock"
        source = "/var/run/docker.sock"
      }
    }
  }
  endpoint_spec {
    ports {
      target_port    = "80"
      published_port = "80"
    }
    ports {
      target_port    = "443"
      published_port = "443"
    }
  }
}

resource "docker_service" "app" {
  name = "app"
  task_spec {
    force_update = 0
    networks_advanced {
      name = docker_network.caddy.name
    }
    container_spec {
      image = docker_image.nginx.image_id
      labels {
        label = "caddy"
        value = "architech.bg"
      }
      labels {
        label = "caddy.reverse_proxy"
        value = "{{upstreams 80}}"
      }
      labels {
        label = "caddy.tls"
        value = "internal"
      }
    }
  }
  mode {
    replicated {
      replicas = 2
    }
  }
}

Expected Behaviour

Second terraform apply must not recreate services.

Actual Behaviour

Second terraform apply recreates services.

Steps to Reproduce

  1. terraform apply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant