louis benagha
louis benagha

Reputation: 115

AWS RDS connection string

I have a question.

So I am trying to automate my RDS connection string with terraform, but the database identifier is randomly generated per region in each aws account.

Is it possible to know before hand the database identifier? and if so i there a way i can automate it?

Below is my current scripts:

sudo socat TCP-LISTEN:5432,reuseaddr,fork TCP4:env0.**cvhjdfmcu7ed**.us-east-1.rds.amazonaws.com:5432

I current i'm using this below script to feed in variables to terraform in my userdata tpl file

sudo nohup socat TCP-LISTEN:${port},reuseaddr,forkTCP4:${name}.${connection}.${aws_region}.rds.amazonaws.com:${port}

If some here can suggests ways that i can use to automate the ${connection} variable, so that i can deploy it in any aws account and region and don't have to worry what possibly the identifier would be.

Upvotes: 2

Views: 2394

Answers (1)

Mark B
Mark B

Reputation: 200476

You would use the endpoint attribute available in either the aws_db_instance or aws_rds_cluster Terraform resource to access the hostname:port RDS endpoint in Terraform.

If you are not creating/managing the RDS instance in the same Terraform where you need access to the endpoint address, then you would use the appropriate Terraform datasource instead of a Terraform resource, which would lookup the RDS information and make the endpoint value available within the rest of your Terraform template.

Upvotes: 2

Related Questions