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

False drift with nomad variables containing newlines #476

Open
optiz0r opened this issue Aug 16, 2024 · 4 comments
Open

False drift with nomad variables containing newlines #476

optiz0r opened this issue Aug 16, 2024 · 4 comments
Labels
hcc/jira Admin - internal

Comments

@optiz0r
Copy link

optiz0r commented Aug 16, 2024

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Terraform v1.5.1
on linux_amd64
+ provider registry.terraform.io/hashicorp/nomad v2.3.0

Only tested on 1.5.1 but very likely to be the same on newer versions, due to relevant logic being in nomad core and this provider only.

Nomad Version

Nomad v1.8.3+ent
BuildDate 2024-08-13T07:52:39Z
Revision 82fa712be0e7c1e07d6d630e0583c188347411ee

Provider Configuration

data "vault_nomad_access_token" "nomad_token" {
  backend = "nomad"
  role    = "admin"
}

provider "nomad" {
  secret_id = local.is_remote_run ? data.vault_nomad_access_token.nomad_token.secret_id : null
  region    = "london"
}

Environment Variables

NOMAD_ADDR=https://...:4646

Affected Resource(s)

Please list the resources as a list, for example:

  • nomad_job

Terraform Configuration Files

resource "nomad_job" "foo" {
  jobspec = file("${path.module}/foo.nomad.hcl")
  hcl2 {
    vars    = {
      example = <<-EOT
        This is an example multi
        line variable
        EOT
    }
  }
}

Debug Output

Omitted, includes sensitive data

Expected Behavior

If the example variable has not changed, no drift should be detected and no change to be made.

Actual Behavior

Since Nomad 1.8.2, Nomad re-encodes the newlines in variables received in JobSubmission so that the internal variables file is well formed, and the job once stopped through the UI can be started again.

This provider retrieves the modified variable definitions from the Nomad API, and then compares it to the unmodified content of the example variable in the terraform code. Since they no longer match, this is reported as a drift, and the nomad_job resource is refreshed.

This doesn't appear actually cause nomad to interrupt the running job, but does cause false reporting of changes.

Steps to Reproduce

  1. terraform apply
  2. terraform apply

Important Factoids

It's unclear if this is a fault in nomad core itself (i.e. the values returned by the read API should be unmodified to match what terraform would have already submitted), or if a fault in the provider (i.e. it should be pre-encoding the newlines before submission, or handling the diff ignoring changes in newline encoding).

References

@optiz0r
Copy link
Author

optiz0r commented Oct 18, 2024

Actually it's worse than just newlines. The HCL file is also not handling quotes properly.

Input file:

blah blah
some_string="foobar"
some_other_string="foo&bar"
settings_file="blah blah\nsome_string="foobar"\nsome_other_string="foo&bar""

Attempting to restart a job such as the above fails with an error that bitwise AND is not supported. It's not possible to restart a job which has been stopped if one of the input variables contained quotes and other symbols, which is a repeat of #23560.

@mmcquillan mmcquillan added the hcc/jira Admin - internal label Oct 18, 2024
@tgross
Copy link
Member

tgross commented Oct 18, 2024

@optiz0r the bug fix you linked to hashicorp/nomad#23560 landed in Nomad 1.8.2 (ref changelog) but looking at the releases for the provider that API didn't land until v2.3.1. Provider v2.3.0 has the 1.8.0 API.

Can you verify you're seeing this with a more recent version of the provider?

@optiz0r
Copy link
Author

optiz0r commented Oct 18, 2024

I was running on 2.3.0 of the provider, but having just tested, I am seeing the same behaviour on 2.3.1 and 2.4.0.

On reflection I think the quoting escape is actually a problem in the hashicorp/nomad#23560 implementation (improper encoding of user input), rather than a problem with the provider. The drift relating to encoded newlines might fall either in nomad core or this provider.

@tgross
Copy link
Member

tgross commented Oct 18, 2024

Ok, thanks @optiz0r, we'll take a look. (Leaving a note that this is being tracked internally as https://hashicorp.atlassian.net/browse/NET-11421)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hcc/jira Admin - internal
Projects
None yet
Development

No branches or pull requests

3 participants