{"id":15779859,"url":"https://github.com/rgl/terraform-aws-rds-postgres-example","last_synced_at":"2026-05-06T13:10:19.161Z","repository":{"id":238381626,"uuid":"796434559","full_name":"rgl/terraform-aws-rds-postgres-example","owner":"rgl","description":"An example Amazon RDS for PostgreSQL database that can be used from an AWS EC2 Ubuntu Virtual Machine","archived":false,"fork":false,"pushed_at":"2024-06-23T08:43:01.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-31T11:06:15.063Z","etag":null,"topics":["aws","aws-rds","aws-rds-postgres","postgres","postgresql","terraform"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rgl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-05T23:06:15.000Z","updated_at":"2024-09-10T12:29:35.000Z","dependencies_parsed_at":"2024-06-23T00:05:01.235Z","dependency_job_id":"e69fa446-5f32-4df9-ad31-d915c5f13b3e","html_url":"https://github.com/rgl/terraform-aws-rds-postgres-example","commit_stats":null,"previous_names":["rgl/terraform-aws-rds-postgres-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rgl/terraform-aws-rds-postgres-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fterraform-aws-rds-postgres-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fterraform-aws-rds-postgres-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fterraform-aws-rds-postgres-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fterraform-aws-rds-postgres-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rgl","download_url":"https://codeload.github.com/rgl/terraform-aws-rds-postgres-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fterraform-aws-rds-postgres-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32695066,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T08:33:17.875Z","status":"ssl_error","status_checked_at":"2026-05-06T08:33:17.221Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-rds","aws-rds-postgres","postgres","postgresql","terraform"],"created_at":"2024-10-04T18:21:42.287Z","updated_at":"2026-05-06T13:10:19.146Z","avatar_url":"https://github.com/rgl.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\n[![Lint](https://github.com/rgl/terraform-aws-rds-postgres-example/actions/workflows/lint.yml/badge.svg)](https://github.com/rgl/terraform-aws-rds-postgres-example/actions/workflows/lint.yml)\n\nAn example [Amazon RDS for PostgreSQL](https://aws.amazon.com/rds/postgresql/) database that can be used from an AWS EC2 Ubuntu Virtual Machine.\n\n**NB** For an [Amazon RDS Aurora PostgreSQL](https://aws.amazon.com/rds/aurora/) example see the [rgl/terraform-aws-rds-aurora-postgres-example repository](https://github.com/rgl/terraform-aws-rds-aurora-postgres-example).\n\nThis will:\n\n* Use the [Amazon RDS for PostgreSQL service](https://aws.amazon.com/rds/postgresql/).\n  * Create a Database Instance.\n* Create an example Ubuntu Virtual Machine.\n  * Can be used to access the Database Instance.\n* Create a VPC and all the required plumbing required for the Ubuntu Virtual\n  Machine to use an Amazon RDS PostgreSQL Database Instance.\n\n# Usage (on a Ubuntu Desktop)\n\nInstall the tools:\n\n```bash\n./provision-tools.sh\n```\n\nSet the account credentials using SSO:\n\n```bash\n# set the account credentials.\n# see https://docs.aws.amazon.com/cli/latest/userguide/sso-configure-profile-token.html#sso-configure-profile-token-auto-sso\naws configure sso\n# dump the configured profile and sso-session.\ncat ~/.aws/config\n# set the environment variables to use a specific profile.\nexport AWS_PROFILE=my-profile\nunset AWS_ACCESS_KEY_ID\nunset AWS_SECRET_ACCESS_KEY\nunset AWS_DEFAULT_REGION\n# show the user, user amazon resource name (arn), and the account id, of the\n# profile set in the AWS_PROFILE environment variable.\naws sts get-caller-identity\n```\n\nOr, set the account credentials using an access key:\n\n```bash\n# set the account credentials.\n# NB get these from your aws account iam console.\n#    see Managing access keys (console) at\n#        https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey\nexport AWS_ACCESS_KEY_ID='TODO'\nexport AWS_SECRET_ACCESS_KEY='TODO'\n# set the default region.\nexport AWS_DEFAULT_REGION='eu-west-1'\n# show the user, user amazon resource name (arn), and the account id.\naws sts get-caller-identity\n```\n\nReview `main.tf`.\n\nInitialize terraform:\n\n```bash\nmake terraform-init\n```\n\nLaunch the example:\n\n```bash\nrm -f terraform.log\nmake terraform-apply\n```\n\nShow the terraform state:\n\n```bash\nmake terraform-show\n```\n\nAt VM initialization time [cloud-init](https://cloudinit.readthedocs.io/en/latest/index.html) will run the `provision-app.sh` script to launch the example application.\n\nAfter VM initialization is done (check the instance system log for cloud-init entries), test the `app` endpoint:\n\n```bash\nwhile ! wget -qO- \"http://$(terraform output --raw app_ip_address)/test\"; do sleep 3; done\n```\n\nAnd open a shell inside the VM:\n\n```bash\nssh \"ubuntu@$(terraform output --raw app_ip_address)\"\ncloud-init status --wait\nless /var/log/cloud-init-output.log\nsystemctl status app\njournalctl -u app\nexit\n```\n\nTry accessing the PostgreSQL Database Instance, from within the AWS VPC, using [`psql`](https://www.postgresql.org/docs/current/app-psql.html):\n\n```bash\nssh \"ubuntu@$(terraform output --raw app_ip_address)\" \\\n  LC_ALL='C.UTF-8' \\\n  PGSSLMODE='verify-full' \\\n  PGHOST=\"$(printf '%q' \"$(terraform output --raw db_address)\")\" \\\n  PGDATABASE='postgres' \\\n  PGUSER=\"$(printf '%q' \"$(terraform output --raw db_admin_username)\")\" \\\n  PGPASSWORD=\"$(printf '%q' \"$(terraform output --raw db_admin_password)\")\" \\\n  psql \\\n    --echo-all \\\n    --no-password \\\n    --variable ON_ERROR_STOP=1 \\\n    \u003c\u003c'EOF'\n-- show information the postgresql version.\nselect version();\n-- show information about the current connection.\nselect current_user, current_database(), inet_client_addr(), inet_client_port(), inet_server_addr(), inet_server_port(), pg_backend_pid(), pg_postmaster_start_time();\n-- show information about the current tls connection.\nselect case when ssl then concat('YES (', version, ')') else 'NO' end as ssl from pg_stat_ssl where pid=pg_backend_pid();\n-- list roles.\n\\dg\n-- list databases.\n\\l\nEOF\n```\n\nOpen an interactive psql session, show the PostgreSQL version, and exit:\n\n```bash\nssh -t \"ubuntu@$(terraform output --raw app_ip_address)\" \\\n  LC_ALL='C.UTF-8' \\\n  PGSSLMODE='verify-full' \\\n  PGHOST=\"$(printf '%q' \"$(terraform output --raw db_address)\")\" \\\n  PGDATABASE='postgres' \\\n  PGUSER=\"$(printf '%q' \"$(terraform output --raw db_admin_username)\")\" \\\n  PGPASSWORD=\"$(printf '%q' \"$(terraform output --raw db_admin_password)\")\" \\\n  psql\nselect version();\nexit\n```\n\nDestroy the example:\n\n```bash\nmake terraform-destroy\n```\n\nList this repository dependencies (and which have newer versions):\n\n```bash\nGITHUB_COM_TOKEN='YOUR_GITHUB_PERSONAL_TOKEN' ./renovate.sh\n```\n\n# References\n\n* [Environment variables to configure the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html)\n* [Token provider configuration with automatic authentication refresh for AWS IAM Identity Center](https://docs.aws.amazon.com/cli/latest/userguide/sso-configure-profile-token.html) (SSO)\n* [Managing access keys (console)](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey)\n* [AWS General Reference](https://docs.aws.amazon.com/general/latest/gr/Welcome.html)\n  * [Amazon Resource Names (ARNs)](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)\n* [Connect to the internet using an internet gateway](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html#vpc-igw-internet-access)\n* [Retrieve instance metadata](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html)\n* [How Instance Metadata Service Version 2 works](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-metadata-v2-how-it-works.html)\n* [Amazon RDS for PostgreSQL service](https://aws.amazon.com/rds/postgresql/)\n* [Amazon RDS for PostgreSQL resources](https://aws.amazon.com/rds/postgresql/resources/)\n* [Amazon RDS for PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)\n* [Common DBA tasks for Amazon RDS for PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.PostgreSQL.CommonDBATasks.html)\n* [Using SSL with a PostgreSQL DB instance](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html)\n* [Using SSL/TLS to encrypt a connection to a DB instance or cluster](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html)\n* [PostgreSQL Environment Variables](https://www.postgresql.org/docs/16/libpq-envars.html)\n* [PostgreSQL System Information Functions and Operators](https://www.postgresql.org/docs/16/functions-info.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgl%2Fterraform-aws-rds-postgres-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frgl%2Fterraform-aws-rds-postgres-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgl%2Fterraform-aws-rds-postgres-example/lists"}