Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Crash Import service docker module with hosts include #304

Open
martinezhenry opened this issue Nov 5, 2020 · 0 comments
Open

Crash Import service docker module with hosts include #304

martinezhenry opened this issue Nov 5, 2020 · 0 comments

Comments

@martinezhenry
Copy link

Hi, when I execute a terraform import command of a docker service using a resource docker_service the provider throw a crash.

module.services.module.novotrans.docker_service.create_replicated_service["jenkins"]: Importing from ID "o0i2rg24dflqequp6pz3pivm9"...
module.services.module.novotrans.docker_service.create_replicated_service["jenkins"]: Import prepared!
  Prepared docker_service for import
module.services.module.novotrans.docker_service.create_replicated_service["jenkins"]: Refreshing state... [id=o0i2rg24dflqequp6pz3pivm9]

Error: rpc error: code = Unavailable desc = transport is closing

Terraform Version

image

Affected Resource(s)

  • docker_service

Terraform Configuration Files

data "docker_registry_image" "reg_image_replicated" {
  for_each = {for image in local.images:  replace(image, ":", "") => image}
  name = each.value


}


resource "docker_image" "image_replicated" {
  for_each = {for data in data.docker_registry_image.reg_image_replicated:  replace(data.name, ":", "") => data}
  name = each.value.name
  pull_triggers = [
    each.value.sha256_digest]

}


resource "docker_service" "create_replicated_service" {

  for_each = {for stack in var.replicated_services:  stack.name => stack}
  name = each.value.name

  task_spec {
    container_spec {
      image = join(":", [
        each.value.image,
        each.value.version])
      hostname = each.value.hostname


      dynamic "mounts" {
        for_each = [for mount in each.value.mounts: {
          source = mount.source
          target = mount.target
          type = mount.type
          external = mount.external
        }]

        content {
          source = mounts.value.external ? mounts.value.source : join(".", [each.key, mounts.value.source])
          target = mounts.value.target
          type = mounts.value.type

        }
      }


      dynamic "hosts" {
        for_each = [for host in each.value.hosts: {
          host = host.host
          ip = host.ip

        }]

        content {
          host = hosts.value.host
          ip = hosts.value.ip
        }
      }

      env = {for environment in each.value.environments:  environment.name => environment.value }

    }

    resources {
      limits {
        #nano_cpus = 1000000
        memory_bytes = each.value.memory

      }
    }


    restart_policy = var.restart_policy

  }

  mode {
    replicated {
        replicas = each.value.replicas_nr
    }

  }


  endpoint_spec {

    dynamic "ports" {
      for_each = [for port in each.value.ports: {
        published = port.published
        target = port.target
      }]

      content {
        target_port = ports.value.target
        published_port = ports.value.published

      }
    }

  }

}

resource "docker_service" "create_global_service" {

  for_each = {for stack in var.global_services:  stack.name => stack}
  name = each.value.name

  task_spec {
    container_spec {
      image = join(":", [
        each.value.image,
        each.value.version])
      hostname = each.value.hostname


      dynamic "mounts" {
        for_each = [for mount in each.value.mounts: {
          source = mount.source
          target = mount.target
          type = mount.type
          external = mount.external
        }]

        content {
          source = mounts.value.external ? mounts.value.source : join(".", [each.key, mounts.value.source])
          target = mounts.value.target
          type = mounts.value.type

        }
      }

      dynamic "hosts" {
        for_each = [for host in each.value.hosts: {
          host = host.host
          ip = host.ip

        }]

        content {
          host = hosts.value.host
          ip = hosts.value.ip
        }
      }

      env = {for environment in each.value.environments:  environment.name => environment.value }

    }

    networks = [for network in each.value.networks:  network.name]

    resources {
      limits {
        #nano_cpus = 1000000
        memory_bytes = each.value.memory

      }
    }


  }

  mode {
    global = each.value.global
  }

  endpoint_spec {

    dynamic "ports" {
      for_each = [for port in each.value.ports: {
        published = port.published
        target = port.target
      }]

      content {
        target_port = ports.value.target
        published_port = ports.value.published

      }
    }

  }

}

Debug Output

https://gist.github.com/martinezhenry/2584b772cf25abcd4388c83e3ece43b4

Panic Output

https://gist.github.com/martinezhenry/2584b772cf25abcd4388c83e3ece43b4

Expected Behavior

Import service docker currently running

Actual Behavior

terrafrom crash and import failed

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform import 'module.services.module.novotrans.docker_service.create_replicated_service["jenkins"]' $(docker service inspect --format="{{.ID}}" jenkins)

Important Factoids

N/A

References

N/A

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant