unable to parse JSON using terraform external data

白昼怎懂夜的黑 提交于 2019-12-24 09:19:14

问题


USE CASE

I wanted to provision an EFS in a given region with an EC2 instance and then mount that instance with EFSand if EFS doesn't exist in that region then I need to provision an alternate of EFS.

PROBLEMS

  1. Amazon is not offering EFS service in every region.
  2. There is no way to identify the availability of service using aws-cli. Already asked but didn't get an answer yet link

WHAT I TRIED

This is the case where amazon provide the service, If I run this command curl -ls https://elasticfilesystem.us-east-1.amazonaws.com system returns the following output.

<MissingAuthenticationTokenException>
  <Message>Missing Authentication Token</Message>
</MissingAuthenticationTokenException>

And if I change the region to eu-west-3 (paris) and run the command system returns nothing.

So this is the WORKAROUND that I've in my mind to check the availability of service in any particular region. But If i write a bash script for this and run the same command using terraform datasource external it shows an error message that unable to parse a JSON error pasring '<'. I've no clue why bash-script considering this returned XML, though I'm checking the exit code instead.

bash script

function check_efs() {
curl -ls https://elasticfilesystem.us-east-1.amazonsaws.com
if [ $? -eq 0 ]; then
        output=1
else:
        output=0
}

function produce_output() {
value=$(output)

jq -n \
    --arg is_efs_exist "$value" \
    '{"is_efs_exist":$is_efs_exist}'
}

check_efs
produce_output

main.tf

provider external {}

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

来源:https://stackoverflow.com/questions/52789813/unable-to-parse-json-using-terraform-external-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!