gpt4 book ai didi

amazon-web-services - 使用 terraform 创建数据库实例

转载 作者:行者123 更新时间:2023-12-04 01:35:49 24 4
gpt4 key购买 nike

我正在尝试创建只能在 Intranet(又名某些私有(private)子网)中运行的 RDS。对它的访问将只提供给应用程序。

我在单独的 terraform 文件中创建了 vpc 配置 link该文件包含vpc配置、routesnat等。

resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true

tags {
Environment = "Dev"
}
}

resource "aws_subnet" "intranet" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "10.0.1.0/24"
availability_zone = "eu-central-1a"
tags {
Name = "Intranet"
Environemnt = "Dev"
}
}
....

resource "aws_route_table_association" "intranet" {
subnet_id = "${aws_subnet.intranet.id}"
route_table_id = "${aws_route_table.intranet_routetable.id}"
}

对于我的 RDS 配置,我创建了一个具有相似内容的单独的 terraform 文件

terraform {
backend "s3" {
bucket = "s3-terraform-state-backend"
region = "eu-central-1"
key = "common/terraform.tfstate"
}
}

provider "aws" {
region = "eu-central-1"
}

resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true

tags {
Environment = "Dev"
}
}

resource "aws_subnet" "intranet" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "10.0.1.0/24"
availability_zone = "eu-central-1a"
tags {
Name = "Intranet"
Environemnt = "Dev"
}
}

# should contain configuration for common components (rds, sqs etc.)
resource "aws_db_subnet_group" "db_subnet" {
name = "intranet"
subnet_ids = ["${aws_subnet.intranet.id}"]
}

resource "aws_db_instance" "core" {
name = "gj-core-db"
engine = "postgres"

allocated_storage = 10
storage_type = "gp2"
instance_class = "db.t2.micro"

db_subnet_group_name = "${aws_db_subnet_group.db_subnet.name}"
}

基本上我从另一个文件复制了 subnetvpc 配置(因为我在这里也需要它)。文件本身在这里link

当我尝试应用配置时出现错误

* aws_db_subnet_group.db_subnet: Error creating DB Subnet Group: DBSubnetGroupDoesNotCoverEnoughAZs: DB Subnet Group doesn't meet availability zone coverage requirement
. Please add subnets to cover at least 2 availability zones. Current coverage: 1
status code: 400, request id: 44e37b59-1db1-4519-847f-d35f5d150592

我只有一个子网。问题是什么?我应该创建更多子网吗?或者使这个 intranet 子网覆盖更多区域?

最佳答案

一个子网不能跨越多个可用区。您应该创建多个子网并将它们分配给您正在创建的子网组。这是为了保证HA。如果您配置多可用区 RDS 数据库实例并且您的主数据库发生故障,RDS 将确保您的数据库移动到不同的可用区(具有相同端点)。

对于子网组,AWS 强制要求每个子网组的子网分布在多个可用区中。可以找到更多详细信息here .

以下是 AWS 文档中的相关部分。

Each DB subnet group should have subnets in at least two Availability Zones in a given region. When creating a DB instance in VPC, you must select a DB subnet group. Amazon RDS uses that DB subnet group and your preferred Availability Zone to select a subnet and an IP address within that subnet to associate with your DB instance. If the primary DB instance of a Multi-AZ deployment fails, Amazon RDS can promote the corresponding standby and subsequently create a new standby using an IP address of the subnet in one of the other Availability Zones

关于amazon-web-services - 使用 terraform 创建数据库实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49862422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com