hashicorp / terraform-provider-docker

As part of our introduction to self-service publishing in the Terraform Registry, this copy of the provider has been archived, and ownership has been transferred to active maintainers in the community. Please see the new location on the Terraform Registry: https://registry.terraform.io/providers/kreuzwerker/docker/latest
https://registry.terraform.io/providers/kreuzwerker/docker/latest
Mozilla Public License 2.0
132 stars 92 forks source link

Allow range of ports for containers and services #223

Open tomalok opened 5 years ago

tomalok commented 5 years ago

Terraform Version

Terraform v0.12.16

Affected Resource(s)

Terraform Configuration Files

resource docker_container "exhibit_a" {
  name = "exhibit_a"
  image = "alpine:latest"
  ports {
    protocol = "udp"
    internal = "61000-62000"
    external = "61000-62000"
  }
} 

resource docker_service "exhibit_b" {
  name = "exhibit_b"
  task_spec {
    container_spec {
      image = "alpine:latest"
    }
  }
  endpoint_spec {
    ports {
      name = "MOSH"
      protocol = "udp"
      target_port = "61000-62000"
      published_port = "61000-62000"
    }
  }
}

Expected Behavior

The Docker provider should accept the string specifying a range of ports, which Docker itself has supported since v1.5 or thereabouts.

Actual Behavior

Error: Incorrect attribute value type

  on main.tf line 176, in resource "docker_service" "this":
 176:         target_port     = p.value.target

Inappropriate value for attribute "target_port": a number is required.

Error: Incorrect attribute value type

  on main.tf line 177, in resource "docker_service" "this":
 177:         published_port  = p.value.publish

Inappropriate value for attribute "published_port": a number is required.
mavogel commented 4 years ago

Shouldn't be much parsing logic, but I need to check if changing the int to a string would be a BC or if it's handled internally as interface{} and it does not matter...

innovate-invent commented 4 years ago

You might be able to utilize https://github.com/docker/go-connections/blob/fcb221ce27f4dd4e7ab3c4ad5f6178ec95b4a7a4/nat/nat.go#L62

You can see it in use here: https://github.com/docker/go-connections/blob/fcb221ce27f4dd4e7ab3c4ad5f6178ec95b4a7a4/nat/nat.go#L193-L204