Skip to content

Commit

Permalink
Merge pull request #30 from srevinsaju/fix/srevin/error-on-empty-default
Browse files Browse the repository at this point in the history
fix(data.env): fall back to empty string when default is unspecified
  • Loading branch information
srevinsaju authored Aug 6, 2023
2 parents 1e5cd04 + 05d5b3a commit 45377c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions examples/env/togomak.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
togomak {
version = 1
}

data "env" "HOME" {
key = "HOME"
}

stage "example" {
name = "example"
script = "echo ${data.env.HOME.value}"
}
6 changes: 5 additions & 1 deletion pkg/blocks/data/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ func (e *EnvProvider) DecodeBody(body hcl.Body) hcl.Diagnostics {

e.keyParsed = key.AsString()

attr = content.Attributes["default"]
attr, ok := content.Attributes["default"]
if !ok {
e.def = ""
return diags
}
key, d = attr.Expr.Value(hclContext)
diags = diags.Extend(d)

Expand Down
11 changes: 11 additions & 0 deletions tests/tests/failing/env-data-key-missing/togomak.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
togomak {
version = 1
}

data "env" "hello" {
}

stage "example" {
name = "example"
script = "echo hello world ${data.env.hello.value}"
}

0 comments on commit 45377c9

Please sign in to comment.