I have a file for creating terraform resources with helm helm.tf
.
In this file I create a honeycomb agent and need to pass in some watchers, so I'm using a yaml file for configuration. Here is the snippet from helm.tf:
resource "helm_release" "honeycomb" {
version = "0.11.0"
depends_on = [module.eks]
repository = "https://honeycombio.github.io/helm-charts"
chart = "honeycomb"
name = "honeycomb"
values = [
file("modules/kubernetes/helm/honeycomb.yml")
]
}
and here is the yaml file
agent:
watchers:
- labelSelector: "app=my-app"
namespace: my-namespace
dataset: {{$env}}
parser:
name: nginx
dataset: {{$env}}
options:
log_format: "blah"
Unfortunately my attempt at setting the variables with {{$x}}
has not worked, so how would I send the env
variable to the yaml values file? I have the variable available to me in the tf file but am unsure how to set it up in the values file.
Thanks
Passing variables between tasks in the same jobSet the value with the command echo "##vso[task. setvariable variable=FOO]some value" In subsequent tasks, you can use the $(FOO) syntax to have Azure Pipelines replace the variable with some value.
YAML does not natively support variable placeholders. Anchors and Aliases almost provide the desired functionality, but these do not work as variable placeholders that can be inserted into arbitrary regions throughout the YAML text. They must be placed as separate YAML nodes.
PY-yaml library doesn't resolve environment variables by default. You need to define an implicit resolver that will find the regex that defines an environment variable and execute a function to resolve it. You can do it through yaml.
If a value after a colon starts with a “{”, YAML will think it is a dictionary, so you must quote it, like so: foo: "{{ variable }}" If your value starts with a quote the entire value must be quoted, not just part of it.
You may use templatefile
function
main.tf
resource "helm_release" "honeycomb" {
version = "0.11.0"
depends_on = [module.eks]
repository = "https://honeycombio.github.io/helm-charts"
chart = "honeycomb"
name = "honeycomb"
values = [
templatefile("modules/kubernetes/helm/honeycomb.yml", { env = "${var.env}" })
]
}
honeycomb.yml
agent:
watchers:
- labelSelector: "app=my-app"
namespace: my-namespace
dataset: "${env}"
parser:
name: nginx
dataset: "${env}"
options:
log_format: "blah"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With