Data external is giving error while fetching the RDS address

This command on CLI works fine:

$ aws rds describe-db-instances --db-instance-identifier "blast-dev-postgres --region eu-west-1 | jq -r '.DBInstances[0].Endpoint'
{
  "Address": "blast-dev-postgres.dfsdfssf.eu-west-1.rds.amazonaws.com",
  "Port": 5432,
  "HostedZoneId": "Z29XKXDKYMONMX"
}

I need to extract the address to be able to pass it to the TF code. Using TF version 1.5

This is my data block

data "external" "rds_endpoint" {
  program = ["/bin/bash", "-c", "aws rds describe-db-instances --db-instance-identifier "blast-dev-postgres --region eu-west-1 | jq -r '.DBInstances[0].Endpoint.Address'"]
}

This is the error I get

 Error: Unexpected External Program Results
│ 
│   with data.external.rds_endpoint,
│   on data.tf line 2, in data "external" "rds_endpoint":
│    2:   program = ["/bin/bash", "-c", "aws rds describe-db-instances --db-instance-identifier blast-dev-postgres --region eu-west-1 | jq -r '.DBInstances[0].Endpoint.Address'"]
│ 
│ The data source received unexpected results after executing the program.
│ 
│ Program output must be a JSON encoded map of string keys and string values.
│ 
│ If the error is unclear, the output can be viewed by enabling Terraform's logging at TRACE level. Terraform documentation on logging: https://www.terraform.io/internals/debugging
│ 
│ Program: /bin/bash
│ Result Error: invalid character 'b' looking for beginning of value

How do I extract the Address to be able to pass it to my code?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.