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

tfe_variable unable create with value from file with hcl content #1367

Closed
psmola opened this issue May 27, 2024 · 3 comments
Closed

tfe_variable unable create with value from file with hcl content #1367

psmola opened this issue May 27, 2024 · 3 comments
Labels

Comments

@psmola
Copy link

psmola commented May 27, 2024

Terraform Enterprise version

Terraform Enterprise v202404-2

Terraform version

Terraform v1.8.3
on linux_amd64

Terraform Configuration Files

resource "tfe_variable" "variables" {
  key             = var.name
  value   = file("ws_vcf_app_settings.hcl")
  category        = "terraform"
  description     = "variable"
  hcl             = true
  sensitive             = false
  workspace_id    = var.workspace.id

  lifecycle {
    ignore_changes = [
      value
    ]
  }

  depends_on = [tfe_workspace.workspace]
}

File ws_vcf_app_settings.hcl :

{
    "deployment_service" = "manager01"
}

Debug Output

│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to
│ module.tfe_app8_ws1.tfe_variable.variables["ws_vcf_app_settings2"],
│ provider "provider[\"registry.terraform.io/hashicorp/tfe\"]" produced an
│ unexpected new value: .value: inconsistent values for sensitive attribute.
│
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to
│ module.tfe_app8_ws1.tfe_variable.variables["ws_vcf_app_settings2"],
│ provider "provider[\"registry.terraform.io/hashicorp/tfe\"]" produced an
│ unexpected new value: .readable_value: was cty.StringVal("{\r\n
│ \"deployment_service\" = \"manager01\"\r\n}"), but now cty.StringVal("{\n
│ \"deployment_service\" = \"manager01\"\n}").
│
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

Expected Behavior

Terraform Enterprise variable is created

Actual Behavior

│ Error: Provider produced inconsistent result after apply

Additional Context

Variable is created if file do not contain value in hcl format

@psmola psmola added the bug label May 27, 2024
@psmola
Copy link
Author

psmola commented May 27, 2024

Problem is with new line \n - for some reason cause a error

@ctrombley
Copy link
Contributor

Hi @psmola, thanks for creating this issue.

Couple questions for you:

  • Is this configuration hosted in a git repository? If so, is the repo configured to strip carriage returns on checkout? (Sometimes this is done with a .gitattributes file. You can list your repo's current config with git config --list.)
  • Was your secrets file created on a Windows machine?
  • Are your terraform runs executed locally or in your TFE instance?

It appears that carriage return characters ("\r") are being stripped at some point during the plan/apply. I'm not sure yet if this is a bug in Terraform, but in the meantime you should be able to work around it by stripping carriage returns yourself in the secrets file. This can be accomplished with the dos2unix tool or any capable text editor. Once it's done, your line breaks should only consist of line feed characters ("\n").

I'll follow up on my end with some more investigation to see if this is something that can be fixed on our end.

@barrettclark
Copy link
Collaborator

@psmola The issue is a function of windows CRLF vs *nix LF. The variable was set, but the CRLF was reformatted so it does not match on subsequent runs. The workaround/solution is to make sure the ws_vcf_app_settings.hcl file is formatted with *nix line endings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants