hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.42k stars 9.5k forks source link

Terraform unable to render list type variable appropriately #23900

Closed pkaramol closed 4 years ago

pkaramol commented 4 years ago

Terraform Version

Terraform v0.11.14

Terraform Configuration Files

resource "null_resource" "run_ansible" {
  count = "${var.install_jenkins}"

  triggers {
    run_me_everytime = "${uuid()}"
  }

  provisioner "local-exec" {
    command = "ansible-playbook -vvv ${path.module}/playbooks/playbook.yaml -i ./playbooks/hosts --extra-vars \"{ \"k8s_cluster_name\": \"${local.k8s_name}\", \"zonename\": \"${var.zone}\", \"env_name\": \"${var.env_name}\", \"google_project_name\": \"${var.project_id}\", \"jenkins_master_image_tag\": \"${var.jenkins_master_image_tag}\", \"jenkins_agent_image_tag\": \"${var.jenkins_agent_image_tag}\", \"jenkins_plugins_list\": \"${var.jenkins_plugins_list}\" }\""
  }
}

And the corresponding (problematic) variable declaration

variable "jenkins_plugins_list" {
  description = "The list of jenkins' plugins to be installed"
  type = "list"
  default = ["kubernetes:1.21.2", "workflow-job:2.36", "workflow-aggregator:2.6", "credentials-binding:1.20", "git:4.0.0"]
}

Debug Output

Pasting only the debug output of interest here

2020/01/20 13:41:40 [TRACE] root.jenkins: eval: *terraform.EvalCompareDiff
2020/01/20 13:41:40 [TRACE] root.jenkins: eval: *terraform.EvalGetProvider
2020/01/20 13:41:40 [TRACE] root.jenkins: eval: *terraform.EvalReadState
2020/01/20 13:41:40 [TRACE] root.jenkins: eval: *terraform.EvalApplyPre
2020/01/20 13:41:40 [TRACE] root.jenkins: eval: *terraform.EvalApply
2020/01/20 13:41:40 [DEBUG] apply: null_resource.run_ansible: executing Apply
module.jenkins.null_resource.run_ansible: Creating...
  triggers.%:                "" => "1"
  triggers.run_me_everytime: "" => "9244dc45-3510-25a4-a9fe-163513740b92"
2020/01/20 13:41:40 [TRACE] root.jenkins: eval: *terraform.EvalWriteState
2020/01/20 13:41:40 [TRACE] root.jenkins: eval: *terraform.EvalApplyProvisioners
2020/01/20 13:41:40 [ERROR] root.jenkins: eval: *terraform.EvalApplyProvisioners, err: At column 1, line 1: output of an HIL expression must be a string, or a single list (argument 16 is TypeList) in:

ansible-playbook -vvv ${path.module}/playbooks/playbook.yaml -i ./playbooks/hosts --extra-vars "{ "k8s_cluster_name": "${local.k8s_name}", "zonename": "${var.zone}", "env_name": "${var.env_name}", "google_project_name": "${var.project_id}", "jenkins_master_image_tag": "${var.jenkins_master_image_tag}", "jenkins_agent_image_tag": "${var.jenkins_agent_image_tag}", "jenkins_plugins_list": "${var.jenkins_plugins_list}" }"
2020/01/20 13:41:40 [ERROR] root.jenkins: eval: *terraform.EvalSequence, err: At column 1, line 1: output of an HIL expression must be a string, or a single list (argument 16 is TypeList) in:

ansible-playbook -vvv ${path.module}/playbooks/playbook.yaml -i ./playbooks/hosts --extra-vars "{ "k8s_cluster_name": "${local.k8s_name}", "zonename": "${var.zone}", "env_name": "${var.env_name}", "google_project_name": "${var.project_id}", "jenkins_master_image_tag": "${var.jenkins_master_image_tag}", "jenkins_agent_image_tag": "${var.jenkins_agent_image_tag}", "jenkins_plugins_list": "${var.jenkins_plugins_list}" }"
2020/01/20 13:41:40 [TRACE] [walkApply] Exiting eval tree: module.jenkins.null_resource.run_ansible
2020/01/20 13:41:40 [TRACE] dag/walk: upstream errored, not walking "provisioner.local-exec (close)"
2020/01/20 13:41:40 [TRACE] dag/walk: upstream errored, not walking "meta.count-boundary (count boundary fixup)"
2020/01/20 13:41:40 [TRACE] dag/walk: upstream errored, not walking "provid

Expected Behavior

The jenkins_plugin_list should have been rendered as list and passed as extra var to ansible.

Actual Behavior

Execution fails with the following error:

Error: Error applying plan:

1 error occurred:
    * module.jenkins.null_resource.run_ansible: At column 1, line 1: output of an HIL expression must be a string, or a single list (argument 16 is TypeList) in:

ansible-playbook -vvv ${path.module}/playbooks/playbook.yaml -i ./playbooks/hosts --extra-vars "{ "k8s_cluster_name": "${local.k8s_name}", "zonename": "${var.zone}", "env_name": "${var.env_name}", "google_project_name": "${var.project_id}", "jenkins_master_image_tag": "${var.jenkins_master_image_tag}", "jenkins_agent_image_tag": "${var.jenkins_agent_image_tag}", "jenkins_plugins_list": "${var.jenkins_plugins_list}" }"

ΝΟΤΕ: I am forced to use the above approach due to severe limitation of TF helm provider, not working over TLS

https://github.com/terraform-providers/terraform-provider-helm/issues/389 https://github.com/terraform-providers/terraform-provider-helm/issues/281 https://github.com/terraform-providers/terraform-provider-helm/issues/355 https://github.com/terraform-providers/terraform-provider-helm/issues/385 https://github.com/terraform-providers/terraform-provider-helm/issues/13 https://discuss.hashicorp.com/t/error-with-helm-provider-using-tls/

teamterraform commented 4 years ago

Hi @pkaramol,

The configuration language for Terraform has had significant updates in 0.12, which may produce a better error here. I think the problem is likely the fact that var.jenkins_plugins_list and cannot be rendered as a string. You would need to format that using a function like join or jsonencode to get a single string for the command.

While we can sometimes help with certain simple problems here, it's better to use the community forum where there are more people ready to help. The GitHub issues here are monitored only by our few core maintainers.

Since 0.11 is no longer under active development, We're going to close it for now. Please do feel free to ask your question in the community forum. Thanks!

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.