profile
viewpoint

Ask questionsFeature Request - Allow list/array in 'query' in 'external' data source

Terraform Version

0.8.7

Affected Resource(s)

external data source

Terraform Configuration Files

data "external" "create_policy" {
  program = ["bash", "${path.module}/create_policy.sh"]

  query = {
    list_of_images = "${var.list_of_images}"
  }
}

Expected Behavior

List list_of_images should have been passed to the script.

Actual Behavior

Error refreshing state: 1 error(s) occurred:

* query: 1 error(s) decoding:

* '[list_of_images]' expected type 'string', got unconvertible type '[]interface {}'

Terraform Version

0.8.7

Affected Resource(s)

Terraform Configuration Files

data "external" "create_policy" {
  program = ["bash", "${path.module}/create_policy.sh"]
}

create_policy.sh

#!/bin/bash
set -e
# This works
jq -n --arg foobaz "$FOOBAZ" '{"foobaz":$foobaz}'
# This throws an error
jq -n '{"Version":"2008-10-17","Statement":[{"Sid":"repo_policy","Effect":"Allow","Principal":{"AWS":["arn:aws:iam::${account_id}:root","arn:aws:iam::${account_id}:role/ecr_restricted_admin"]},"Action":"*"}]}'

Expected Behavior

Terraform shouldn't thrown an error when the the bash script is producing a valid json

$ bash modules/ecr/create_policy.sh  | jq .
{
  "Version": "2008-10-17",
  "Statement": [
    {
      "Sid": "repo_policy",
      "Effect": "Allow",
      "Principal": {
        "AWS": [
          "arn:aws:iam::${account_id}:root",
          "arn:aws:iam::${account_id}:role/ecr_restricted_admin"
        ]
      },
      "Action": "*"
    }
  ]
}

Actual Behavior

* data.external.create_policy: command "bash" produced invalid JSON: json: cannot unmarshal array into Go value of type string

Steps to Reproduce

Create the resource and the script files and run terraform plan

hashicorp/terraform

Answer questions debu99

+1

useful!

Related questions

failed to save provider manifest: open .terraform/plugins/linux_amd64/lock.json: permission denied hot 4
The argument "host" is required, but no definition was found. hot 3
Unable to run 0.12upgrade hot 3
Module cannot find alias AWS provider in 0.12.0 hot 3
Error: Invalid template interpolation value hot 2
Terraform v0.11.1 : Error downloading modules: Error loading modules: open .terraform/modules/3f10921295c292995128e9e36eb: no such file or directory hot 2
MalformedPolicyDocument: Policy document should not specify a principal. hot 2
Error in Terraform 0.12.0: This object has no argument, nested block, or exported attribute hot 2
Terraform provider downloads fail with TLS handshake timeout hot 2
'terraform init' failed with 'Registry service unreachable.' error hot 2
for_each attribute for creating multiple resources based on a map hot 2
`Unreadable module directory` error is not clear for nested modules hot 2
Provider Development: Expected type 'string', got unconvertible type '[]interface {}' - with complicated block hot 2
Error loading state: state snapshot was created by Terraform v0.12.7, which is newer than current v0.12.6 hot 2
[BUG] Terraform 0.12.x corrupts state when upgrading from 0.11.14 hot 1
Github User Rank List