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

Terraform unable to render list type variable appropriately #23900

Closed
pkaramol opened this issue Jan 20, 2020 · 2 comments
Closed

Terraform unable to render list type variable appropriately #23900

pkaramol opened this issue Jan 20, 2020 · 2 comments

Comments

@pkaramol
Copy link

pkaramol commented Jan 20, 2020

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

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

@teamterraform
Copy link
Contributor

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
Copy link

ghost commented Mar 28, 2020

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.

@ghost ghost locked and limited conversation to collaborators Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants