Here is an example HCL code snippet that demonstrates how to use AWS EFS Terraform module:
module "efs" {
source = "../.."
# Basic EFS configuration
name = "example-elastic-file-system"
creation_token = "example-creation-token"
encrypted = true
enable_automatic_backups = true
kms_key_id = "example-kms-key-id"
performance_mode = "generalPurpose"
throughput_mode = "provisioned"
provisioned_throughput_in_mibps = 100
# Lifecycle management
lifecycle_policy = {
transition_to_ia = "AFTER_7_DAYS"
transition_to_primary_storage_class = "AFTER_1_ACCESS"
}
# Access points
access_points = {
example_posix_user = {
ac_name = "example-posix-user"
posix_user = {
gid = 1001
uid = 1001
secondary_gids = [1002, 1003, 1004]
}
root_directory = {
path = "/example-posix-user"
creation_info = {
owner_gid = 1001
owner_uid = 1001
permissions = "755"
}
}
}
}
# Security Group Configuration for EFS Mount Targets
security_group_configuration = {
description = "Security group for EFS mount targets"
name_prefix = "efs-"
vpc_id = "vpc-1234567890"
# Ingress rules are automatically configured for EFS port 2049
ingress_rules = {
allow_vpc = {
description = "Allow NFS access from VPC"
cidr_blocks = ["10.0.0.0/16"]
}
allow_specific_sg = {
description = "Allow NFS from specific security group"
source_security_group_id = "example-sg-0"
}
}
# Configurable egress rules
egress_rules = {
allow_all = {
description = "Allow all outbound traffic"
protocol = "-1"
from_port = "0"
to_port = "0"
cidr_blocks = ["0.0.0.0/0"]
}
}
}
# Mount targets in multiple AZs
mount_targets = [
{
subnet_id = "example-subnet-id-1"
security_groups = ["example-sg-id-1", "example-sg-id-2"]
timeouts = {
create = "50m"
delete = "40m"
}
},
{
subnet_id = "example-subnet-id-2"
security_groups = ["example-sg-id-3", "example-sg-id-4"]
timeouts = {
create = "40m"
delete = "30m"
}
}
]
# Cross-region replication
replication_configuration = {
region = "us-east-1"
availability_zone_name = "us-east-1a"
timeouts = {
create = "1h"
delete = "30m"
}
}
# File System IAM policy
policy_configuration = {
version = "2012-10-17"
policy_id = "example-policy-id"
statements = [
{
sid = "example-sid"
actions = [
"elasticfilesystem:ClientMount",
"elasticfilesystem:ClientWrite"
]
principals = [
{
type = "AWS"
identifiers = ["arn:aws:iam::111122223333:role/ExampleEFSRole"]
}
]
}
]
bypass_policy_lockout_safety_check = false
}
tags = {
CreatedBy = "Terraform"
}
}
Examples
demonstrate use-cases and configurations of the module. They serve both as a reference for users implementing the module and as integration tests for validating module functionality.
Name | Version |
---|---|
terraform | >= 1.3 |
aws | >= 5.40 |
Name | Version |
---|---|
aws | >= 5.40 |
No modules.
Name | Type |
---|---|
aws_efs_access_point.this | resource |
aws_efs_backup_policy.this | resource |
aws_efs_file_system.this | resource |
aws_efs_file_system_policy.this | resource |
aws_efs_mount_target.this | resource |
aws_efs_replication_configuration.this | resource |
aws_security_group.this | resource |
aws_security_group_rule.egress | resource |
aws_security_group_rule.ingress | resource |
aws_iam_policy_document.this | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
access_points | A map of access points to create for the file system. Each access point supports the following settings:
|
map(object({ |
null |
no |
availability_zone_name | The AWS Availability Zone in which to create the file system. Used to create a file system that uses One Zone storage classes | string |
null |
no |
creation_token | A unique name used to ensure idempotent file system creation. If not specified, defaults to an auto-generated string combining timestamp and UUID in the format: "terraform-<YYYYMMDDhhmmss>-<random_uuid>" (defined as a local value in main.tf file) |
string |
null |
no |
enable_automatic_backups | If true , automatic backups will be enabled for the file system. Defaults to false |
bool |
false |
no |
encrypted | If true , the disk will be encrypted. Defaults to true |
bool |
true |
no |
kms_key_id | The ARN for the KMS encryption key. When specifying kms_key_id , encrypted needs to be set to true |
string |
null |
no |
lifecycle_policy | Configuration for EFS lifecycle policy transitions. Supports the following settings:
|
map(string) |
null |
no |
mount_targets | Configuration block for EFS mount targets. Accepts a list of objects with the following settings:
|
list(object({ |
null |
no |
name | A unique name for the Elastic File System (EFS) | string |
null |
no |
performance_mode | The file system performance mode. Can be either "generalPurpose" or "maxIO" . Defaults to "generalPurpose" |
string |
"generalPurpose" |
no |
policy_configuration | Configuration block for EFS policy configuration. Supports the following settings:
|
object({ |
null |
no |
protection | Configuration block for EFS file system protection settings. Supports the following settings:
|
object({ |
null |
no |
provisioned_throughput_in_mibps | The throughput, measured in MiB/s, to provision for the file system. Only applicable with throughput_mode set to "provisioned" |
number |
null |
no |
replication_configuration | Configuration block for EFS replication configuration. Supports the following settings:
|
object({ |
null |
no |
security_group_configuration | Configuration for AWS security group with flexible rule management:
|
object({ |
null |
no |
tags | A map of tags to add to all resources | map(string) |
{} |
no |
throughput_mode | Throughput mode for the file system. Valid values: "bursting" , "provisioned" , or "elastic" .When using "provisioned" , also set provisioned_throughput_in_mibps ". Defaults to "bursting" |
string |
"bursting" |
no |
Name | Description |
---|---|
access_points_arns | The ARN(s) of the access point(s) |
access_points_file_system_arn | The Amazon Resource Name (ARN) of the EFS file system associated with the access point(s) |
access_points_file_system_ids | The ID(s) of the access point(s) |
backup_policy_id | The ID of the backup policy |
file_system_arn | The Amazon Resource Name (ARN) of the file system |
file_system_availability_zone_id | The identifier of the Availability Zone in which the file system's One Zone storage classes exist |
file_system_dns_name | The DNS name for the filesystem per documented convention |
file_system_id | The ID that identifies the file system |
file_system_name | The value of the file system's Name tag |
file_system_number_of_mount_targets | The current number of mount targets that the file system has |
file_system_owner_id | The AWS account that created the file system. If the file system was createdby an IAM user, the parent account to which the user belongs is the owner |
file_system_policy_id | The ID that identifies the file system policy |
file_system_size_in_bytes | The latest known metered size (in bytes) of data stored in the file system, the value is not the exact size that the file system was at any point in time |
mount_targets_availability_zone_ids | The unique and consistent identifier of the Availability Zone(s) that the mount target(s) reside in |
mount_targets_availability_zone_names | The name(s) of the Availability Zone(s) that the mount target(s) reside in |
mount_targets_dns_names | The DNS name(s) for the mount target(s) in each subnet/AZ, following the format [az].[filesystem-id].efs.[region].amazonaws.com |
mount_targets_file_system_arn | The Amazon Resource Name (ARN) of the EFS file system associated with the mount target(s). This will be the same ARN for all mount targets in a file system |
mount_targets_file_system_dns_name | The DNS name for the EFS file system, which can be used to mount the file system using the NFS protocol. This is the same for all mount targets in a file system |
mount_targets_ids | The ID(s) of the mount target(s) |
mount_targets_network_interface_ids | The ID(s) of the ENI(s) that AWS EFS automatically created and attached when provisioning the mount target(s). This ENI enables network connectivity to the EFS file system |
mount_targets_owner_id | The AWS account ID that owns the mount target(s) |
replication_configuration_creation_time | The timestamp indicating when the replication configuration was initially created (expressed in Unix timestamp format) |
replication_configuration_destination_file_system_id | The file system ID of the destination EFS replica created by the replication configuration |
replication_configuration_destination_status | The current status of the EFS replication configuration destination |
replication_configuration_original_source_file_system_arn | The Amazon Resource Name (ARN) of the original source Amazon EFS file system in the replication configuration |
replication_configuration_source_file_system_arn | The Amazon Resource Name (ARN) of the current source file system in the replication configuration |
replication_configuration_source_file_system_region | The AWS Region in which the source Amazon EFS file system is located |
tags_all | A map of tags assigned to the resource |