Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace string with concatenate variables #534

Open
Amonlol opened this issue Mar 27, 2024 · 0 comments
Open

Replace string with concatenate variables #534

Amonlol opened this issue Mar 27, 2024 · 0 comments

Comments

@Amonlol
Copy link

Amonlol commented Mar 27, 2024

Description

I'm having a hard time understanding levant templating for my nomad job. Let's say I have a variable .shortJobNames (can be true of false). I want to construct my prometheus config out of local file template and replace blackbox exporter service name placeholder with the actual one for prometheus to use consul service mesh (can be "blackbox" if .shortJobNames or [[ .jobName ]]-blackbox-[[ .instanceName ]] if not)

So this:

      template {
        destination = "local/prometheus.yml"
        data = <<EOH
[[fileContents "monitoring/templates/prometheus/config.yml" ]]
EOH
      }

Turns into this:

      template {
        destination = "local/prometheus.yml"
        data = <<EOH
[[fileContents "monitoring/templates/prometheus/config.yml" | replace "$BLACKBOXSERVICENAME" [[ if .shortJobNames ]][[ with $blackboxservicename := "blackbox" ]][[ else ]][[ with $blackboxservicename := [[ .jobName ]]-blackbox-[[ .instanceName ]] ]]
EOH
        [[ end ]]
      }

Also tried with variable, but could not find in docs how to construct such a string:

      template {
        destination = "local/prometheus.yml"
        [[ if .shortJobNames ]]
        [[ with $blackboxservicename := "blackbox" ]]
        [[ else ]]
        [[ with $blackboxservicename := ".jobName-blackbox-.instanceName" ]]
        [[end]]
        data = <<EOH
[[fileContents "monitoring/templates/prometheus/config.yml" | replace "$BLACKBOXSERVICENAME" $blackboxservicename ]]
EOH
      }

UPD: I do not want to hardcode name in config and\or job itself to utilize DRY. I have multiple environments which are independantly deployed

Output of levant version:

Levant v0.3.2
@Amonlol Amonlol changed the title Construct a string out of Replace string with concatenate variables Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant