hashicorp / terraform-provider-tfe

Official HCP Terraform and Terraform Enterprise provider, maintained by HashiCorp. Provision HCP Terraform or Terraform Enterprise - with Terraform!
https://registry.terraform.io/providers/hashicorp/tfe
Mozilla Public License 2.0
159 stars 151 forks source link

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

Open psmola opened 1 month ago

psmola commented 1 month ago

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 commented 1 month ago

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

ctrombley commented 1 month ago

Hi @psmola, thanks for creating this issue.

Couple questions for you:

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.