Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in AWS by (5.6k points)

I have 2 EC2 instances in two AZ and now I need to mount the EFS in both instances. So how can I do this using terraform?

Here is my code,

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}"]

}

Any solution for this?

1 Answer

0 votes
by (12.4k points)

 Here you just need to add one more mount target in a subnet in AZ, like:

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}"]

}

 Or you can try this:

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}"]

}

Interested in learning AWS? Come & join: AWS Course

For more information about Terraform, check out:

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
asked Dec 8, 2020 in AWS by devin (5.6k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 5, 2020 in AWS by Justin (7k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...