---
title: "How to Use the Terraform EFS (Elastic File System) Module"
description: "Learn how to create and mount your file system in AWS Cloud by using Terraform EFS module in this step-by-step tutorial!"
canonical: "https://adamtheautomator.com/terraform-efs/"
---

# How to Use the Terraform EFS (Elastic File System) Module

> Learn how to create and mount your file system in AWS Cloud by using Terraform EFS module in this step-by-step tutorial!

Source: https://adamtheautomator.com/terraform-efs/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Use the Terraform EFS (Elastic File System) Module](https://adamtheautomator.com/wp-content/uploads/2022/03/How-to-Use-the-Terraform-EFS-Elastic-File-System-Module.jpg)

# How to Use the Terraform EFS (Elastic File System) Module

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)7 March 20226 min. read

Categories: [DevOps](/category/devops/)

Tags:[AWS Terraform](/tag/aws-terraform/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Building the Terraform EFS Configuration for AWS](#building-the-terraform-efs-configuration-for-aws)
*   [Creating the AWS EFS with a Terraform Configuration](#creating-the-aws-efs-with-a-terraform-configuration)
*   [Verifying the AWS EFS in AWS Cloud](#verifying-the-aws-efs-in-aws-cloud)
*   [Mounting AWS EFS in AWS EC2 instance](#mounting-aws-efs-in-aws-ec2-instance)
*   [Conclusion](#conclusion)

Are you looking to create and configure file systems quickly in AWS Cloud? Before scouring the internet for a solution, consider using the [Amazon Elastic File System (Amazon EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) and [Terraform EFS module](https://registry.terraform.io/modules/cloudposse/efs/aws/latest).

Amazon EFS provides serverless and scalable solutions to store huge data automatically as you add and remove files without affecting applications. And in this tutorial, you’ll learn to build and run a Terraform configuration to build an Amazon EFS from scratch!

Let’s dive in quickly!

## **Prerequisites**

This post will be a step-by-step tutorial. If you’d like to follow along, ensure you have the following in place:

*   An [Amazon Web Service (AWS) account](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).
    
*   A code editor – Even though you can use any text editor to work with Terraform configuration files, you should consider [Visual Studio (VS) Code](https://code.visualstudio.com/) as it understands the HCL Terraform language well.
    
*   [Terraform](https://www.terraform.io/docs/enterprise/install/index.html) – This tutorial uses Terraform v1.1.5 running on [Ubuntu 20.0](https://adamtheautomator.com/install-ubuntu/)4 LTS, but any operating system with Terraform will work.
    

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

Related:[How to Install Terraform on Windows](https://adamtheautomator.com/terraform-windows/)

*   [IAM role](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) attached on Ubuntu 20.04 LTS with full privileges to create AWS EFS and related components.
*   The [Amazon EFS client](https://docs.aws.amazon.com/efs/latest/ug/installing-amazon-efs-utils.html#installing-other-distro) installed on Ubuntu 20.04 LTS for connecting to AWS EFS.

## Building the Terraform EFS Configuration for AWS

Since you’ll be using the Terraform EFS module to create a file system in AWS Cloud, you’ll first have to build a Terraform configuration for AWS EFS. The Terraform configuration will set your file system’s properties and the AWS EFS mount point.

1\. Log in to the Ubuntu machine with your favorite SSH client.

2\. Next, run the commands below to create a working directory called `~/terraform-amazon-efs-demo`_._ This folder will contain all of the configuration files you’ll be working on in this tutorial

```bash
mkdir ~/terraform-amazon-efs-demo
cd ~/terraform-amazon-efs-demo
```

3\. Open your preferred code editor, and create a file called _main.tf_ inside the ~/_terraform-amazon-efs-demo_ directory.

Copy/paste the following configuration to the main.tf file, and save the changes. This _main.tf_ file is the Terraform configuration for the AWS EFS.

The below Terraform configuration creates the following resources:

*   EFS file system named (`Myfilesystem`)
    
*   EFS lifecycle policy – used to inform when to transition files into and out of the file system.
    
*   EFS system policy – defines what a client can do with EFS file systems, such as mounting or just the reading file.
    
*   EFS mount target in the specified subnet that you’ll mount with your AWS EC2 instance later in this tutorial.
    

> _Your subnet id will be different than the id specified in the below code._

```bash
# Creating Amazon EFS File system
resource "aws_efs_file_system" "myfilesystem" {
# Creating the AWS EFS lifecycle policy
# Amazon EFS supports two lifecycle policies. Transition into IA and Transition out of IA
# Transition into IA transition files into the file systems's Infrequent Access storage class
# Transition files out of IA storage
  lifecycle_policy {
    transition_to_ia = "AFTER_30_DAYS"
  }
# Tagging the EFS File system with its value as Myfilesystem
  tags = {
    Name = "Myfilesystem"
  }
}

# Creating the EFS access point for AWS EFS File system
resource "aws_efs_access_point" "test" {
  file_system_id = aws_efs_file_system.myfilesystem.id
}
# Creating the AWS EFS System policy to transition files into and out of the file system.
resource "aws_efs_file_system_policy" "policy" {
  file_system_id = aws_efs_file_system.myfilesystem.id
# The EFS System Policy allows clients to mount, read and perform 
# write operations on File system 
# The communication of client and EFS is set using aws:secureTransport Option
  policy = <<POLICY
{
    "Version": "2012-10-17",
    "Id": "Policy01",
    "Statement": [
        {
            "Sid": "Statement",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Resource": "${aws_efs_file_system.myfilesystem.arn}",
            "Action": [
                "elasticfilesystem:ClientMount",
                "elasticfilesystem:ClientRootAccess",
                "elasticfilesystem:ClientWrite"
            ],
            "Condition": {
                "Bool": {
                    "aws:SecureTransport": "false"
                }
            }
        }
    ]
}
POLICY
}
# Creating the AWS EFS Mount point in a specified Subnet 
# AWS EFS Mount point uses File system ID to launch.
resource "aws_efs_mount_target" "alpha" {
  file_system_id = aws_efs_file_system.myfilesystem.id
  subnet_id      = "subnet-019d9a5b90ab436c9"
}
```

4\. Create another file in _~/terraform-amazon-efs-demo_ and name it _provider.tf,_ and populate the file with the content below.

> _Including all configuration values in a single configuration file is possible. But to keep things clear for developers and admins, breaking the logic and variables into separate files is preferable._

The _provider.tf_ file contains [Terraform providers](https://www.terraform.io/language/providers) as Terraform depends on the plugins to connect or interact with cloud providers or API services.

```bash
# Declaring the AWS Provider
provider "aws" {
   region = "us-east-1"
 }
```

Related:[Getting Started with the Terraform AWS Provider](https://adamtheautomator.com/terraform-aws/)

> _The tutorial creates resources in the us-east-1 region. But a list of_ [regions that AWS support](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) _is also available._

5\. Finally, run the `tree` command to verify all required files in the _~/terraform-amazon-efs-demo_ directory, as shown below.

```bash
tree
```

![Verifying the Required Files for Building AWS EFS in AWS Cloud](https://adamtheautomator.com/wp-content/uploads/2022/03/image-34.png)

Verifying the Required Files for Building AWS EFS in AWS Cloud

## Creating the AWS EFS with a Terraform Configuration

Now that you have the Terraform configuration file and variables files set up, it’s time to initiate Terraform and create the AWS EFS.

To provision the AWS EFS, like all other Terraform configurations, Terraform uses three commands in sequence ([`terraform init`](https://www.terraform.io/docs/cli/commands/init.html), [`terraform plan`](https://www.terraform.io/docs/cli/commands/plan.html), and [`terraform apply`](https://www.terraform.io/docs/cli/commands/apply.html)).

> _If the Terraform configuration files you created are not correctly formatted, you can run the_ [terraform fmt](https://www.terraform.io/cli/commands/fmt) _command to fix them._

1\. Run the `terraform init` command in the ~/_terraform-amazon-efs-demo_ directory to initialize the plugins and providers required to work with resources.

```bash
terraform init
```

If all goes well, you’ll see the message that says Terraform has been successfully initialized in the output, as shown below.

![Initializing Terraform to download the Plugins and dependencies ](https://adamtheautomator.com/wp-content/uploads/2022/03/image-35.png)

Initializing Terraform to download the Plugins and dependencies

2\. Next, run the `terraform plan` command to ensure your syntax of configuration files is correct and gives you a blueprint of resources that will be provisioned in your infrastructure.

```bash
terraform plan
```

Once the command completes, you’ll see a message like Plan: “X” to add, “Y” to change, or “Z” to destroy in the output. Below, the Plan shows 4 to add as four resources need to be created.

![Showing the resources to build ](https://adamtheautomator.com/wp-content/uploads/2022/03/image-36.png)

Showing the resources to build

3\. Finally, run the `terraform apply` the command to provision the AWS EFS and related components using each configuration (\*.tf) in the current directory.

The –auto-approve parameter automatically accepts all prompts while running the command.

```bash
terraform apply --auto-approve
```

![Provisioning the AWS EFS and Components in AWS.](https://adamtheautomator.com/wp-content/uploads/2022/03/image-37.png)

Provisioning the AWS EFS and Components in AWS.

## Verifying the AWS EFS in AWS Cloud

By now, you should have created the AWS Elastic File System and related components with Terraform. But how do you know they exist in your AWS cloud? Verify the AWF by manually checking in the AWS Management Console.

1\. Open your favorite web browser and log in to the [AWS Management Console](https://aws.amazon.com/console/).

2\. On the console’s home page, click on the search box, search for and click ‘EFS’ to access the EFS dashboard. Your browser automatically redirects the page to the EFS dashboard.

![Navigating to the AWS EFS Service Page](https://adamtheautomator.com/wp-content/uploads/2022/03/image-38.png)

Navigating to the AWS EFS Service Page

3\. Notice that the file system you specified in your _main.tf_ file is created successfully, as shown below.

![Checking the AWS EFS in AWS Cloud](https://adamtheautomator.com/wp-content/uploads/2022/03/image-39.png)

Checking the AWS EFS in AWS Cloud

4\. On the same EFS page, find and click on the attach button (upper-right), and copy the NFS client command that you will use to mount the Ubuntu machine with this EFS.

![Copying the Mount Command to Mount the Target Filesystem](https://adamtheautomator.com/wp-content/uploads/2022/03/image-40.png)

Copying the Mount Command to Mount the Target Filesystem

5\. Finally, verify the EFS mount target under the network tab. The **Mount target state** should be **Available**, which denotes that the mount target can be used for mounting.

![Verify the EFS mount target in AWS EFS](https://adamtheautomator.com/wp-content/uploads/2022/03/image-41.png)

Verify the EFS mount target in AWS EFS

## Mounting AWS EFS in AWS EC2 instance

Previously, you verified all the components of AWS EFS in AWS Cloud, which is great. But unless you add the data in AWS EFS, they are not doing much. You’ll have to mount AWS EFS in the AWS instance and add data from your AWS instance.

1\. Run each command below to create a working directory named _~/efs-mount-point_ in your home directory. This directory is what you’ll mount to the AWS EFS and store the data.

```bash
mkdir ~/efs-mount-point
cd ~/efs-mount-point
```

2\. Next, run the [`mount`](https://www.geeksforgeeks.org/mount-command-in-linux-with-examples/) command below to mount your Amazon EFS file system on your ubuntu machine.

The below command mounts the file system you created to the current directory (~/efs-mount-point), where nfsvers=4.1 is used when mounting on EC2 Linux instances. In the command below, fs-067b6e242bX143de5.efs.us-east-1.amazonaws.com is set as the AWS EFS endpoint.

```bash
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-067b6e242bX143de5.efs.us-east-1.amazonaws.com:/ efs-mount-point
```

![Verifying the Mount Point of the Amazon EFS File System on Ubuntu Machine ](https://adamtheautomator.com/wp-content/uploads/2022/03/image-42.png)

Verifying the Mount Point of the Amazon EFS File System on Ubuntu Machine

3\. After successful mounting, run each `wget` command below to add the data into the directory by installing two packages.

> _AWS EFS automatically grows and shrinks as you add or remove files, so there’s no need for management or user intervention._

```bash
wget http://212.183.159.230/100MB.zip
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.58/bin/apache-tomcat-9.0.58-deployer.tar.gz
```

Related:[How to Download Files with Python Wget](https://adamtheautomator.com/python-wget/)

You can see below that both packages are now installed, and the size of the packages is around 103MB.

![Verifying the Packages installed in the EFS client that is Ubuntu machine](https://adamtheautomator.com/wp-content/uploads/2022/03/image-43.png)

Verifying the Packages installed in the EFS client that is Ubuntu machine

4\. Finally, hop over to AWF EFS from [AWS Management Console](https://aws.amazon.com/console/) and check the stats of the storage.

As you can see below, both the Monitoring and Metered size tabs show the data you uploaded is around 103MB. And this output confirms the successful addition of data from the EFS client.

![Verifying the Storage in the Monitoring tab of AWS EFS](https://adamtheautomator.com/wp-content/uploads/2022/03/image-44.png)

Verifying the Storage in the Monitoring tab of AWS EFS

![Verifying the Storage in the Metered sites tab of AWS EFS](https://adamtheautomator.com/wp-content/uploads/2022/03/image-45.png)

Verifying the Storage in the Metered sites tab of AWS EFS

## Conclusion

In this tutorial, you’ve learned how to use Terraform to deploy an AWS EFS and its components with Terraform EFS module. You also learned how to securely mount other devices such as AWS EC2 instances with AWS EFS.

Now that you have EFS created on the AWS Cloud, what do you plan to store in your newly created EFS? Why not learn to modernize application development with [Persistent File Storage](https://aws.amazon.com/products/storage/persistent-file-storage-for-modern-apps/?pg=ln&sec=uc)?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fterraform-efs%2F&text=How%20to%20Use%20the%20Terraform%20EFS%20\(Elastic%20File%20System\)%20Module)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fterraform-efs%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fterraform-efs%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/08/featured_image-6.webp)

### [Automate Terraform with Azure DevOps](/automate-terraform-azure-devops/)

Automate Terraform with Azure DevOps Pipelines: structure a multi-environment repo, store remote state in Azure Storage with locking, and deploy through

![](https://adamtheautomator.com/wp-content/uploads/2026/08/featured_image-5.webp)

### [Azure DevOps Boards: Trace Every Commit to Deployment](/azure-devops-boards-traceability/)

Configure Azure DevOps Boards process templates, backlogs, and Kanban WIP limits, then trace every work item from commit to deployment.

![](https://adamtheautomator.com/wp-content/uploads/2026/07/featured_image-3.png)

### [Build Your First Internal Developer Platform](/build-first-internal-developer-platform/)

Build your first Internal Developer Platform with Backstage, a software catalog, software templates, CI/CD handoffs, and Kubernetes deployment manifests.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
