Environment variable in if condition is not working

Hello there,

I have the following pipeline output configuration:

output {
  if ("${ELASTICSEARCH_HOSTS:}" == "http://elasticsearch:9200") {
    elasticsearch {
      action => "index"
      index => "street"
      hosts => ["${ELASTICSEARCH_HOSTS}"]
      document_id => "%{id}"
    }
  }
  else {
    elasticsearch {
      action => "index"
      index => "street"
      hosts => ["${ELASTICSEARCH_HOSTS}"]
      user => "${ELASTICSEARCH_USERNAME}"
      password => "${ELASTICSEARCH_PASSWORD}"
      ssl_certificate_verification => "${ELASTICSEARCH_SSL_CERTIFICATE_VERIFICATION}"
      cacert => "${ELASTICSEARCH_CA_CERT_PATH}"
      document_id => "%{id}"
    }
  }
  stdout {}
}

Even though, the environment variable ELASTICSEARCH_HOSTS is set to "http://elasticsearch:9200", the "else condition" is executed as the pipeline fails due to missing credentials, certificate and so on.

So, my question is: What am I doing wrong in my config?

Referencing an environment variable in a conditional. You would think it would be supported, but it is not. See this thread.

It is supported since Logstash v7.17.0, see PR:
Support env variable in condition by kaisecheng · Pull Request #13608 · elastic/logstash (github.com)

Clearly I do not spend enough time reading release notes :laughing:

Is this typo? You have a : at the end of the variable name.