使用Terraform,我可以使用区域1中的以下配置成功创建RDS群集 -
resource "aws_rds_cluster" "aurora_cluster" {
cluster_identifier = "${var.environment_name}-aurora-cluster"
database_name = "mydb"
master_username = "${var.rds_master_username}"
master_password = "${var.rds_master_password}"
backup_retention_period = 14
final_snapshot_identifier = "${var.environment_name}AuroraCluster"
apply_immediately = true
db_cluster_parameter_group_name = "${aws_rds_cluster_parameter_group.default.name}"
tags {
Name = "${var.environment_name}-Aurora-DB-Cluster"
ManagedBy = "terraform"
Environment = "${var.environment_name}"
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_rds_cluster_instance" "aurora_cluster_instance" {
count = "${length(split(",", var.multi_azs))}"
identifier = "${var.environment_name}-aurora-instance-${count.index}"
cluster_identifier = "${aws_rds_cluster.aurora_cluster.id}"
instance_class = "db.t2.small"
publicly_accessible = true
apply_immediately = true
tags {
Name = "${var.environment_name}-Aurora-DB-Instance-${count.index}"
ManagedBy = "terraform"
Environment = "${var.environment_name}"
}
lifecycle {
create_before_destroy = true
}
}
output "db_primary_cluster_arn" {
rds_cluster.aurora_cluster.cluster_identifier}"
value = "${"${format("arn:aws:rds:%s:%s:cluster:%s", "${var.db_region}", "${data.aws_caller_identity.current.account_id}", "${aws_rds_cluster.aurora_cluster.cluster_identifier}")}"}"
}
并使用下面的区域2 -
创建一个跨区域副本resource "aws_rds_cluster" "aurora_crr_cluster" {
cluster_identifier = "${var.environment_name}-aurora-crr-cluster"
database_name = "mydb"
master_username = "${var.rds_master_username}"
master_password = "${var.rds_master_password}"
backup_retention_period = 14
final_snapshot_identifier = "${var.environment_name}AuroraCRRCluster"
apply_immediately = true
# Referencing to the primary region's cluster
replication_source_identifier = "${var.db_primary_cluster_arn}"
tags {
Name = "${var.environment_name}-Aurora-DB-CRR-Cluster"
ManagedBy = "terraform"
Environment = "${var.environment_name}"
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_rds_cluster_instance" "aurora_crr_cluster_instance" {
count = "${length(split(",", var.multi_azs))}"
identifier = "${var.environment_name}-aurora-crr-instance-${count.index}"
cluster_identifier = "${aws_rds_cluster.aurora_crr_cluster.id}"
instance_class = "db.t2.small"
publicly_accessible = true
apply_immediately = true
tags {
Name = "${var.environment_name}-Aurora-DB-Instance-${count.index}"
ManagedBy = "terraform"
Environment = "${var.environment_name}"
}
lifecycle {
create_before_destroy = true
}
}
当我想将区域2中的跨区域副本提升为独立群集时 - 我尝试从跨区域RDS群集中删除复制源(replication_source_identifier)并执行" terraform apply"。我看到Terraform的输出说 -
module.db_replica.aws_rds_cluster.aurora_crr_cluster: Modifying... (ID: dev-aurora-crr-cluster)
replication_source_identifier: "arn:aws:rds:us-east-2:account_nbr:cluster:dev-aurora-cluster" => ""
module.db_replica.aws_rds_cluster.aurora_crr_cluster: Modifications complete after 1s (ID: dev-aurora-crr-cluster)
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
但是,我看到"没有变化"发生在AWS控制台上的跨区域群集中。我仍然看到复制源是现有的并且相同,并且交叉区域集群没有更新为独立的"在AWS。
如果我尝试通过AWS CLI执行相同的操作 -
aws rds promote-read-replica-db-cluster --db-cluster-identifier="dev-aurora-crr-cluster" --region="us-west-1"
我发现更改会立即触发,并且跨区域副本将提升为独立群集。有谁知道我可能做错了什么? 或Terraform不支持将跨区域副本提升为独立群集。请指教。