FLY_CONSUL_URL no such host

Wanting to play with Consul I’ve created a simple Go app with Consul client:

client, err := api.NewClient(&api.Config{
	Address: os.Getenv("FLY_CONSUL_URL"),
})

Trying to access the KV store I see this:

Put "https://:26c4294a-b440-b543-1ae7-79620e7f15e5%40consul-fra-8.fly-shared.net/evcc-consul-4nml16r0rp51vp2y//v1/kv/value?cas=0": dial tcp: lookup :26c4294a-b440-b543-1ae7-79620e7f15e5@consul-fra-8.fly-shared.net: no such host

The Consul URL looks clearly wrong, both the starting : in the host name as the //v1.

Ah, part of the confusion comes from Go consul module HTML-escaping the error message which seems to explain the %40. The plain FLY_CONSUL_URL is this:

https://:26c4294a-b440-b543-1ae7-79620e7f15e5@consul-fra-8.fly-shared.net/evcc-consul-4nml16r0rp51vp2y/

Still, the connection error remains:

dial tcp: lookup :26c4294a-b440-b543-1ae7-79620e7f15e5@consul-fra-8.fly-shared.net: no such host

Looks as if consul is not connected. May be worth noting that the machines are in the AMS region while the consule url seems to indicate FRA?

Next issue is the // due to fly url containing trailing /. This must not be passed as address in the config, hence

Address: strings.TrimRight(os.Getenv("FLY_CONSUL_URL"), "/"),

. Still, TCP lookup problem remains :frowning:

Any idea what to do about the no such host for Consul detaching/re-attaching doesn’t help.

@tvdfly any chance to look into this? Just recreated the app, with same result. Attached Consul host is not reachable.

Gave it one last try:

u, err := url.Parse(os.Getenv("FLY_CONSUL_URL"))
if err != nil {
	panic(err)
}

config := &api.Config{
	Address: u.Host,
	Scheme:  u.Scheme,
}
if u.User != nil {
	config.Token, _ = u.User.Password()
}

client, err := api.NewClient(config)
if err != nil {
	panic(err)
}

finally results in

response code: 403 (rpc error making call: Permission denied)

Giving up :open_mouth:

I’m still stuck with connecting to Consul. Is that really not possible???

Still looking for a solution.

See the Sneak peak: global lock service post for details on this service and the structure of the FLY_CONSUL_URL variable.

Specifically, I think you’re missing this part:

the path section (/app-name-23sxdf ) is the prefix that token has write access to.

If I understand this correctly you need to make sure the Name field in any queries you send to the Consul service start with the provided path prefix, e.g., evcc-consul-4nml16r0rp51vp2y/. Hope this helps!

Thank you so much- this wasn’t obvious for me, thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.