gpt4 book ai didi

amazon-web-services - 如何使用 Terraform 在多可用区中创建 EFS

转载 作者:行者123 更新时间:2023-12-04 12:19:43 27 4
gpt4 key购买 nike

我在两个可用区中启动了两个 EC2 实例,我需要使用 Terraform 在两个实例中安装 EFS。

resource "aws_efs_file_system" "magento-efs" {
creation_token = "efs-demo"
performance_mode = "generalPurpose"
throughput_mode = "bursting"
encrypted = "true"
tags = {
Name = "Magento-EFS"
}
}

resource "aws_efs_mount_target" "efs-mount" {
file_system_id = "${aws_efs_file_system.magento-efs.id}"
subnet_id = "${aws_subnet.public_subnet.0.id}"
security_groups = ["${aws_security_group.efs-sg.id}"]
}
使用上面的代码,我可以在 us-east-1a 中创建 EFS。我需要在 us-east-1a 和 us-east-1b 中都提供它。

最佳答案

您只需要在 AZ us-east-1b 的子网中添加另一个挂载目标:

resource "aws_efs_mount_target" "efs-mount-b" {
file_system_id = "${aws_efs_file_system.magento-efs.id}"
subnet_id = "${aws_subnet.public_subnet.1.id}"
security_groups = ["${aws_security_group.efs-sg.id}"]
}

更优雅(使用 count 取决于子网的数量):
resource "aws_efs_mount_target" "efs-mount" {
count = "length(aws_subnet.public_subnet.*.id)"
file_system_id = "${aws_efs_file_system.magento-efs.id}"
subnet_id = "${element(aws_subnet.public_subnet.*.id, count.index)}"
security_groups = ["${aws_security_group.efs-sg.id}"]
}

关于amazon-web-services - 如何使用 Terraform 在多可用区中创建 EFS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57547045/

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