How do I deploy an AWS EFS mount target with Pulumi?
In this tutorial, we will deploy an AWS Elastic File System (EFS) and create a mount target for it using Pulumi. An EFS mount target allows you to mount the file system to an Amazon EC2 instance within a specific subnet and security group.
Key Points
- We will create an EFS file system.
- We will create a security group to allow NFS traffic.
- We will create a mount target within a specified subnet and associate it with the security group.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create an AWS VPC
const vpc = new aws.ec2.Vpc("vpc", {
cidrBlock: "10.0.0.0/16",
});
// Create a subnet within the VPC
const subnet = new aws.ec2.Subnet("subnet", {
vpcId: vpc.id,
cidrBlock: "10.0.1.0/24",
availabilityZone: "us-west-2a",
});
// Create a security group to allow NFS traffic
const securityGroup = new aws.ec2.SecurityGroup("efs-sg", {
vpcId: vpc.id,
ingress: [
{
protocol: "tcp",
fromPort: 2049,
toPort: 2049,
cidrBlocks: ["0.0.0.0/0"],
},
],
egress: [
{
protocol: "-1", // All traffic
fromPort: 0,
toPort: 0,
cidrBlocks: ["0.0.0.0/0"],
},
],
});
// Create an EFS file system
const efs = new aws.efs.FileSystem("efs", {
tags: {
Name: "my-efs",
},
});
// Create a mount target for the EFS file system
const mountTarget = new aws.efs.MountTarget("efs-mount-target", {
fileSystemId: efs.id,
subnetId: subnet.id,
securityGroups: [securityGroup.id],
});
Summary
We created an AWS VPC and a subnet within it. We then created a security group that allows NFS traffic. After that, we created an EFS file system and a mount target within the specified subnet, associating it with the security group. This setup allows you to mount the EFS file system to EC2 instances within the VPC.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.