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

Can not create the empty file from template: Must specify a source path or have an embedded template #23415

Closed
EugenKon opened this issue Jun 21, 2024 · 1 comment

Comments

@EugenKon
Copy link

EugenKon commented Jun 21, 2024

Nomad version

v1.8.0

Issue

I am trying to create the empty file

      template {
        destination = "$NOMAD_ALLOC_DIR/creds.env"
        data = ""
      }

but have got the error:

Error during plan: Unexpected response code: 500 (1 error occurred:
	* Task group postgres-db validation failed: 1 error occurred:
	* Task postgres-task validation failed: 1 error occurred:
	* Template 2 validation failed: 1 error occurred:
	* Must specify a source path or have an embedded template)

The documentation says:

One of source or data must be specified, but not both.

I have specified data option and I provided the explicit value "" .

Reproduction steps

nomad plan ...

Expected Result

I should be able to create the empty file.

Actual Result

An empty file was not created. The user should not be restricted from a creation of empty files.

@tgross
Copy link
Member

tgross commented Jun 21, 2024

Hi @EugenKon! Go's deserialization of JSON to a string can't differentiate between an empty string and unset, so when the template block is parsed we always end up with an empty string for that field. We need to validate that one of source vs data is set, so that's why you're getting that error. There are ways we could have designed the API around this but changing it now would break backwards compatibility.

You can workaround this by having the template data contain something that evaluates to an empty body. For example, something like:

template {
  data = "{{ \" \" | trimSpace }}"
}

@tgross tgross closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants