From ae7e29ff49f26536c6557c7be0f4191c3daf5e0d Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 11 Dec 2020 13:32:51 -0500 Subject: [PATCH 1/2] actually pass env-vars to hcl2 parsing --- command/helpers.go | 1 + command/helpers_test.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/command/helpers.go b/command/helpers.go index a09382fefe0..74b221bba40 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -458,6 +458,7 @@ func (j *JobGetter) ApiJobWithArgs(jpath string, vars []string, varfiles []strin ArgVars: vars, AllowFS: true, VarFiles: varfiles, + Envs: os.Environ(), }) if err != nil { diff --git a/command/helpers_test.go b/command/helpers_test.go index d07f3deedde..dcdd7f20789 100644 --- a/command/helpers_test.go +++ b/command/helpers_test.go @@ -338,16 +338,20 @@ variables { var1 = "default-val" var2 = "default-val" var3 = "default-val" + var4 = "default-val" } job "example" { - datacenters = ["${var.var1}", "${var.var2}", "${var.var3}"] + datacenters = ["${var.var1}", "${var.var2}", "${var.var3}", "${var.var4}"] } ` + os.Setenv("NOMAD_VAR_var4", "from-envvar") + defer os.Unsetenv("NOMAD_VAR_var4") + cliArgs := []string{`var2=from-cli`} fileVars := `var3 = "from-varfile"` - expected := []string{"default-val", "from-cli", "from-varfile"} + expected := []string{"default-val", "from-cli", "from-varfile", "from-envvar"} hclf, err := ioutil.TempFile("", "hcl") require.NoError(t, err) From 205a1de6f3bdf870649197a1cc6f12ec19e17b6a Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 11 Dec 2020 13:34:53 -0500 Subject: [PATCH 2/2] docs: remove envvar option --- .../docs/job-specification/hcl2/variables.mdx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/website/pages/docs/job-specification/hcl2/variables.mdx b/website/pages/docs/job-specification/hcl2/variables.mdx index 350d1df9ce8..0858355a673 100644 --- a/website/pages/docs/job-specification/hcl2/variables.mdx +++ b/website/pages/docs/job-specification/hcl2/variables.mdx @@ -153,15 +153,6 @@ documentation about the job, and so it should be written from the perspective of the user of the job rather than its maintainer. For commentary for job maintainers, use comments. -## Assigning Values to job Variables - -Once a variable is declared in your configuration, you can set it: - -- Individually, with the `-var foo=bar` command line option. -- As environment variables, for example: `NOMAD_VAR_foo=bar` - -The following sections describe these options in more detail. - ### Variables on the Command Line To specify individual variables on the command line, use the `-var` option when @@ -211,7 +202,6 @@ corresponding to variable names: "labels": ["testing", "internal"], } ``` ----> ### Environment Variables @@ -234,6 +224,8 @@ Nomad matches the variable name exactly as given in configuration, and so the required environment variable name will usually have a mix of upper and lower case letters as in the above example. +---> + ### Complex-typed Values When variable values are provided in a variable definitions file, Nomad's @@ -262,6 +254,7 @@ For readability, and to avoid the need to worry about shell escaping, we recommend always setting complex variable values via variable definitions files. + + ## A variable value must be known: Take the following variable for example: