Ask questionsFeature Request - Allow list/array in 'query' in 'external' data source
0.8.7
data "external" "create_policy" {
program = ["bash", "${path.module}/create_policy.sh"]
query = {
list_of_images = "${var.list_of_images}"
}
}
List list_of_images
should have been passed to the script.
Error refreshing state: 1 error(s) occurred:
* query: 1 error(s) decoding:
* '[list_of_images]' expected type 'string', got unconvertible type '[]interface {}'
0.8.7
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":"*"}]}'
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": "*"
}
]
}
* data.external.create_policy: command "bash" produced invalid JSON: json: cannot unmarshal array into Go value of type string
Create the resource and the script files and run terraform plan
Related questions