Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform Module for EFS #35

Merged
merged 10 commits into from
Oct 12, 2023
5 changes: 5 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ This are various examples build using the above modules.
[Compute Engine -GCP](/terraform/gcp/modules/compute_engine/compute_engine.tf)

This module will create a VM instance with the image chosen by the user (defaults to Ubuntu 22.04)

### 6. EFS - AWS
[Elastic File System -AWS](/terraform/aws/modules/efs/efs.tf)

This module will create EFS in AWS via Terraform.
15 changes: 15 additions & 0 deletions terraform/aws/examples/efs/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module "efs" {
source = "../../modules/efs"
creation_token = "test-efs"
performance_mode = "generalPurpose"
throughput_mode = "bursting"
encryption_set = true
kms_key_id = "arn:aws:kms:ap-south-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
subnet_id = "subnet-01234567890abcdef"
security_groups = ["sg-01234567890abcdef", "sg-01234567890abcdef"]

}

output "example_outputs" {
value = module.efs
}
19 changes: 19 additions & 0 deletions terraform/aws/examples/efs/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_version = ">= 1.0.0"
}

provider "aws" {
region = var.region
default_tags {
tags = {
Environment = "Test"
Project = "QBurst"
}
}
}

variable "region" {
type = string
description = "The default region to use"
default = "ap-south-1"
}
22 changes: 22 additions & 0 deletions terraform/aws/modules/efs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# EFS Module
This module will create EFS. As a part of the module it will generate the following

- 1 EFS in bursting throughput mode .


## Inputs
**Important**
All inputs :heavy_check_mark: must be configured.
Any with :x: can be ignored, but can be configurd if you want.

| Name | Description | Required | Type | Default |
| ----------- | ----------- | -------- | ---- | ------- |
| creation_token | A unique name (a maximum of 64 characters are allowed) used as reference when creating the Elastic File System to ensure idempotent file system creation | :x: | string | If not provided, it will generated by Terraform|
| performance_mode | The file system performance mode | :x:| string | "generalPurpose" |
| throughput_mode | Throughput mode for the file system | :x: | string | "bursting" |
| encrypted | Disk encryption to be set | :x: | bool | |
| kms_key_id| ARN of the KMS key to be used for encryption.This is to be set if encrypted is set to true | :x: | string | |
| file_system_id | The ID of the file system for which the mount target is intended | :heavy_check_mark: | string | |
| subnet_id | The ID of the subnet to add the mount target in | :heavy_check_mark: | string | |
| security_groups | A list of up to 5 VPC security group IDs | :x: | string | |
| enable_key_rotation | Variable to set rotation for keys | :x: | bool | false |
24 changes: 24 additions & 0 deletions terraform/aws/modules/efs/efs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*This will create EFS in bursting mode.The mode can be changed as per the requirement*/
resource "aws_efs_file_system" "elastic_file_system" {
creation_token = var.creation_token

lifecycle_policy {
transition_to_ia = "AFTER_30_DAYS"
}
qburst-praven marked this conversation as resolved.
Show resolved Hide resolved
encrypted = var.encryption_set
kms_key_id = aws_kms_key.kms_key_efs.arn
performance_mode = var.performance_mode
throughput_mode = var.throughput_mode
}

qburst-praven marked this conversation as resolved.
Show resolved Hide resolved
# Define the EFS mount target (optional)
resource "aws_efs_mount_target" "efs_mount_target" {
file_system_id = aws_efs_file_system.elastic_file_system.id
qburst-praven marked this conversation as resolved.
Show resolved Hide resolved
subnet_id = var.subnet_id
security_groups = var.security_groups
}
# KMS Key for EFS
resource "aws_kms_key" "kms_key_efs" {
description = "KMS key for EFS"
enable_key_rotation = true
}
12 changes: 12 additions & 0 deletions terraform/aws/modules/efs/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
output "efs_id" {
value = aws_efs_file_system.elastic_file_system.id
description = "The ID of the EFS created"
}
output "efs_arn" {
value = aws_efs_file_system.elastic_file_system.arn
description = "The ARN of the EFS created"
}
output "efs_mount_id" {
value = aws_efs_mount_target.efs_mount_target.id
description = "The ID of the EFS mount"
}
35 changes: 35 additions & 0 deletions terraform/aws/modules/efs/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
variable "creation_token" {
type = string
default = "test-efs"

}
variable "performance_mode" {
type = string
default = "generalPurpose"

}
variable "throughput_mode" {
type = string
default = "bursting"

}
variable "encryption_set" {
type = bool
default = true
}
variable "kms_key_id" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@angeleenasunny , I believe this variable is not needed anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qburst-praven This is removed.

type = string
default = "true"

}
variable "subnet_id" {
type = string
default = "subnet-01234567890abcdef"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls change the default values, these and the sec groups provided below might not exist.


}
variable "security_groups" {
type = list(string)
default = ["sg-01234567890abcdef", "sg-01234567890abcdef"]

}