CodexBloom - Programming Q&A Platform

Terraform scenarios with AWS EFS and Security Group References

πŸ‘€ Views: 0 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-15
terraform aws efs security-group HCL

Could someone explain I just started working with I'm wondering if anyone has experience with I've searched everywhere and can't find a clear answer. I tried several approaches but none seem to work. I'm trying to set up an AWS Elastic File System (EFS) using Terraform, but I'm running into an scenario with the security group configuration. I'm attempting to allow NFS traffic (port 2049) from my EC2 instances to the EFS, but it seems the security group is not being applied as expected. Here's my configuration for the EFS and the security group: ```hcl resource "aws_security_group" "efs_security_group" { name = "efs_security_group" description = "Allow NFS access to EFS" vpc_id = "${aws_vpc.main.id}" ingress { from_port = 2049 to_port = 2049 protocol = "tcp" cidr_blocks = ["${aws_subnet.main.cidr_block}"] } } resource "aws_efs_file_system" "my_efs" { creation_token = "my-efs-token" performance_mode = "generalPurpose" } resource "aws_efs_mount_target" "my_mount_target" { file_system_id = "${aws_efs_file_system.my_efs.id}" subnet_id = "${aws_subnet.main.id}" security_groups = [aws_security_group.efs_security_group.id] } ``` When I apply this configuration, I receive the following behavior message: ``` behavior: creating EFS Mount Target: InvalidParameterValue: The security group 'sg-xxxxxxx' is not associated with the specified subnet 'subnet-xxxxxxx'. ``` I've double-checked to ensure that the security group is indeed associated with the VPC and subnet, but it keeps throwing this behavior. I've tried explicitly adding the security group to the subnet, but that doesn’t seem to resolve the scenario. Is there a specific way to handle security group references when creating EFS mount targets, or is there something I might be overlooking? I'm using Terraform version 1.1.0 and the AWS provider version 3.50.0. Any help would be greatly appreciated! For context: I'm using Hcl on Linux. This is part of a larger API I'm building. Has anyone else encountered this? This is happening in both development and production on Debian. I'm using Hcl 3.10 in this project. I'm using Hcl 3.10 in this project.