scaleway / terraform-provider-scaleway

Terraform Scaleway provider

Home Page:https://www.terraform.io/docs/providers/scaleway/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IoT Route DNS Cache Issue: Unreachable Host After Container Recreation

SebUndefined opened this issue · comments

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 other comments that do not add relevant new information or questions, 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 Version

terraform -v
Terraform v1.6.5
on darwin_arm64
+ provider registry.terraform.io/scaleway/scaleway v2.34.0

Affected Resource(s)

  • scaleway_domain_record
  • scaleway_iot_route

Terraform Configuration Files

resource "scaleway_iot_route" "telemetry" {
  name = "telemetry-route"
  hub_id = scaleway_iot_hub.default.id
  topic = "telemetry/#"
  rest {
    headers = {
      "Content-Type" = "application/json",
      ...
    }
    uri     = "https://simple.mydomain.com/v1/telemetries"
    verb    = "post"
  }
  depends_on = [scaleway_iot_hub.default, scaleway_container_domain.transport]
}

resource scaleway_domain_record "asimpledomain" {
  dns_zone = "mydomain.com"
  name     = "simple"
  type     = "CNAME"
  data     = "${module.container_service.domain_name}." 
  ttl      = 3600
}

resource scaleway_container_domain "transport" {
  container_id = module.container.id
  hostname = "${scaleway_domain_record.asimpledomain.name}.${scaleway_domain_record.asimpledomain.dns_zone}"
}

Debug Output

Nothing

Expected Behavior

In the example above, the domain simple.mydomain.com seems to be unavailable for my IoT route in case the container is recreated and his domain_name is changed (here "${module.container_service.domain_name}.") . The IoT route should refresh his DNS cache.

Actual Behavior

The host (here simple.mydomain.com) is unreachable by the IoT route.

Workaround : delete the route and create it again.

Steps to Reproduce

  1. Add the definition in a specific terraform module for a container with a RestAPI
  2. terraform apply

A potential solution to ensure the IoT route can consistently resolve the correct endpoint, even after the container is recreated, is to implement a custom, static endpoint for the container. This way, the route's endpoint remains constant, and it does not rely directly on the dynamic domain name that changes upon container recreation.

To achieve this, you could configure a custom endpoint within your container configuration that does not change, and then reference this static endpoint in your scaleway_iot_route configuration. This would prevent the need to delete and recreate the route every time the container is updated.

Here is an example to set up a custom endpoint:

resource scaleway_container_namespace main {
    name = "my-ns-test"
    description = "test container"
}

resource scaleway_container app {
    name = "app"
    namespace_id = scaleway_container_namespace.main.id
    registry_image = "${scaleway_container_namespace.main.registry_endpoint}/nginx:alpine"
    port = 80
    cpu_limit = 140
    memory_limit = 256
    min_scale = 1
    max_scale = 1
    timeout = 600
    max_concurrency = 80
    privacy = "public"
    protocol = "http1"
    deploy = true
}

resource scaleway_domain_record "app" {
  dns_zone = "domain.tld"
  name     = "subdomain"
  type     = "CNAME"
  data     = "${scaleway_container.app.domain_name}." // Trailing dot is important in CNAME
  ttl      = 3600
}

resource scaleway_container_domain "app" {
  container_id = scaleway_container.app.id
  hostname = "${scaleway_domain_record.app.name}.${scaleway_domain_record.app.dns_zone}"
}