redpanda-data / redpanda-data/connect

Environment variables are not resolved when using templates

Open
#3,054 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs investigation ux
Dominant language
Go
Stars
8.8k
Forks
969
Avg merge
1d 13h
Merged PRs (30d)
64

Description

It seems that environment variables are not resolved the same way in templates as they are in regular configuration files. There is a workaround, so it's not a major issue, but I assume this could be a challenge for many newcomers, as it was for me.

Given this template:

type: input
name: kafka
fields:
  - name: topic
    type: string

mapping: |
  #!blobl
  root = {
    "kafka_franz": {
      "seed_brokers": [ "${KAFKA_BROKERS}" ],
      "topics": [ this.topic ],
      "sasl": ...
    }
}

Here's the error I encounter when using templates:

WARN unable to open connection to broker           @service=redpanda-connect addr="${KAFKA_BROKERS}:9092" broker=seed_0 err="dial tcp: lookup ${KAFKA_BROKERS}: no such host" label="" path=root.input
(edited)

It's simple to replace seed_brokers with env("KAFKA_BROKERS"), if you know you need to, but this is a bit of a gotcha.

Moreover, it seems you can't set defaults using environment variables. Both default: "${SOME_VARIABLE}" and default: ${! env("SOME_VARIABLE") } appear to evaluate to null, resulting in the error: expected object value, got !!null.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the template YAML example with ${KAFKA_BROKERS} and compare it with the equivalent regular configuration behavior. Investigate the template handling for broker values and defaults using env("KAFKA_BROKERS"); done means environment variables resolve consistently in templates, including defaults, without producing null values.

Written by the indexing model from the issue text.

Assessment

Tech stack
kafka
Domain
stream-processing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.