我使用下面的Terraform manifest成功地为Postgres创建了AWS RDS示例,但无法从我的本地计算机中建立连接以进行测试。尝试超时。
- host: blog.abcdefg12345.eu-west-1.rds.amazonaws.com
- port: 5432
- name: mydatabase
- user: myusername
- pass: mypassword
我检查了这两篇文章,但仍然找不到任何明显的东西。
- https://repost.aws/knowledge-center/rds-cannot-connect
- https://repost.aws/knowledge-center/rds-connectivity-instance-subnet-vpc
resource "aws_db_instance" "blog" {
identifier = "blog"
engine = "postgres"
engine_version = "12.10"
instance_class = "db.t2.micro"
storage_type = "gp2"
allocated_storage = 5
db_name = "mydatabase"
username = "myusername"
password = "mypassword"
publicly_accessible = true
skip_final_snapshot = true
}
tfstate(隐藏)
{
"version": 4,
"terraform_version": "1.4.4",
"serial": 7,
"lineage": "324343434-fd2f-vv7d-2ac1-11f1011d222v",
"outputs": {
"blog_database": {
"value": "blog.abcdefg12345.eu-west-1.rds.amazonaws.com:5432",
"type": "string"
}
},
"resources": [
{
"mode": "managed",
"type": "aws_db_instance",
"name": "blog",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 1,
"attributes": {
"address": "blog.abcdefg12345.eu-west-1.rds.amazonaws.com",
"allocated_storage": 5,
"allow_major_version_upgrade": null,
"apply_immediately": null,
"arn": "arn:aws:rds:eu-west-1:123456789012:db:blog",
"auto_minor_version_upgrade": true,
"availability_zone": "eu-west-1a",
"backup_retention_period": 0,
"backup_window": "00:22-00:52",
"ca_cert_identifier": "rds-ca-2019",
"character_set_name": "",
"copy_tags_to_snapshot": false,
"customer_owned_ip_enabled": false,
"db_name": "mydatabase",
"db_subnet_group_name": "default",
"delete_automated_backups": true,
"deletion_protection": false,
"domain": "",
"domain_iam_role_name": "",
"enabled_cloudwatch_logs_exports": null,
"endpoint": "blog.abcdefg12345.eu-west-1.rds.amazonaws.com:5432",
"engine": "postgres",
"engine_version": "12.10",
"engine_version_actual": "12.10",
"final_snapshot_identifier": null,
"hosted_zone_id": "ABCDEFGHIJKLMNO",
"iam_database_authentication_enabled": false,
"id": "blog",
"identifier": "blog",
"identifier_prefix": "",
"instance_class": "db.t2.micro",
"iops": 0,
"kms_key_id": "",
"latest_restorable_time": "",
"license_model": "postgresql-license",
"maintenance_window": "thu:01:29-thu:01:59",
"max_allocated_storage": 0,
"monitoring_interval": 0,
"monitoring_role_arn": "",
"multi_az": false,
"name": "mydatabase",
"nchar_character_set_name": "",
"network_type": "IPV4",
"option_group_name": "default:postgres-12",
"parameter_group_name": "default.postgres12",
"password": "mypassword",
"performance_insights_enabled": false,
"performance_insights_kms_key_id": "",
"performance_insights_retention_period": 0,
"port": 5432,
"publicly_accessible": true,
"replica_mode": "",
"replicas": [],
"replicate_source_db": "",
"resource_id": "db-ABCDEFGHIJKLMNOPRSTOPUWYZ",
"restore_to_point_in_time": [],
"s3_import": [],
"security_group_names": null,
"skip_final_snapshot": true,
"snapshot_identifier": null,
"status": "available",
"storage_encrypted": false,
"storage_type": "gp2",
"tags": null,
"tags_all": {},
"timeouts": null,
"timezone": "",
"username": "myusername",
"vpc_security_group_ids": [
"sg-0053deef5e6484f4f"
]
},
"sensitive_attributes": [],
"private": "qwertyuio123456789"
}
]
}
],
"check_results": null
}
1条答案
按热度按时间q8l4jmvw1#
除了将
publicly_accessible
设置为true
之外,您的数据库至少需要一个允许在端口5432
上进行连接的安全组。例如,您将需要一个类似于以下内容的安全组:
您可以使用
vpc_security_group_ids
属性将此安全组关联到数据库: