hashicorp / terraform-aws-vault

A Terraform Module for how to run Vault on AWS using Terraform and Packer
Apache License 2.0
656 stars 465 forks source link

vault-examples-helper error #229

Open doncorsean opened 3 years ago

doncorsean commented 3 years ago

Getting this error in helper script /vault-examples-helper/vault-examples-helper.sh

2021-01-10 17:57:17 [INFO] [vault-examples-helper.sh] Fetching public IP addresses for EC2 Instances in "us-east-1" with tag "Name"="vault-example"

Error parsing parameter '--filters': Expected: ',', received: '"' for input: Name=tag:"Name",Values="vault-example"

If up correct the query so that it executes I receive the following

2021-01-10 18:41:48 [INFO] [vault-examples-helper.sh] Found all 3 public IP addresses! 2021-01-10 18:41:50 [INFO] [vault-examples-helper.sh] Waiting for 3 Vault servers to come up 2021-01-10 18:41:50 [INFO] [vault-examples-helper.sh] Checking health of Vault server via URL https://null:8200/v1/sys/health curl: (6) Could not resolve host: null 2021-01-10 18:41:55 [INFO] [vault-examples-helper.sh] Got a 000 response from Vault server null with body:

brikis98 commented 3 years ago

Can you show the full command you're running and the full log output?

doncorsean commented 3 years ago

% ../vault-examples-helper/vault-examples-helper.sh
2021-01-14 07:10:17 [INFO] [vault-examples-helper.sh] Looking up public IP addresses for 3 Vault server EC2 Instances. 2021-01-14 07:10:22 [INFO] [vault-examples-helper.sh] Fetching public IP addresses for EC2 Instances in "us-east-1" with tag "Name"="vault-cluster"

Error parsing parameter '--filters': Expected: ',', received: '"' for input: Name=tag:"Name",Values="vault-cluster" ^ 2021-01-14 07:10:23 [WARN] [vault-examples-helper.sh] Found 0 of 3 public IP addresses. Will sleep for 10 seconds and try again. 2021-01-14 07:10:39 [INFO] [vault-examples-helper.sh] Fetching public IP addresses for EC2 Instances in "us-east-1" with tag "Name"="vault-cluster"

Error parsing parameter '--filters': Expected: ',', received: '"' for input: Name=tag:"Name",Values="vault-cluster" ^ 2021-01-14 07:10:39 [WARN] [vault-examples-helper.sh] Found 0 of 3 public IP addresses. Will sleep for 10 seconds and try again.

doncorsean commented 3 years ago

It's the double quoting tripping things up. If I edit the script and hardcode the values it works fine.

  instances=$(aws ec2 describe-instances \
    --region "$aws_region" \
    --filter "Name=tag:$cluster_tag_key,Values=$cluster_tag_value" "Name=instance-state-name,Values=running")

vs.

  instances=$(aws ec2 describe-instances \
    --region "us-east-1" \
    --filter "Name=tag:Name,Values=vault-cluster" "Name=instance-state-name,Values=running")
brikis98 commented 3 years ago

Ohhhh, are you using Terraform 0.14? If so, we have not yet updated this repo to work with it, and the issue you're hitting is that there was a backward incompatible change in the terraform output command introduced in Terraform 0.14. String values now come back with double quotes around them, which did not used to be the case before, and these unexpected double quotes, as you've seen, can cause a variety of issues.

We'll probably need to update the code to use the -json param with terraform output and carefully parse the results in the future, as the output API without -json is not stable for scripting, I guess.