Skip to content

Commit

Permalink
Merge pull request #3 from ghrcdaac/mlh0079-4541-configurable-efs
Browse files Browse the repository at this point in the history
 - Allowing configuration for most of the efs fields.
  • Loading branch information
Michaellh0079 authored Mar 2, 2023
2 parents 128ae60 + 9134048 commit 62aeca3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
41 changes: 38 additions & 3 deletions inputs.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
variable "creation_token" {
description = "Optional) 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. By default generated by Terraform. See Elastic File System user guide for more information."
type = number
default = null
}

variable "name" {
type = string
description = "(Required) The reference_name of your file system. Also, used in tags."
}

variable "subnets" {
type = list
type = list(string)
description = "(Required) A list of subnet ids where mount targets will be."
}

Expand All @@ -19,15 +25,44 @@ variable "encrypted" {
type = bool
}


variable "kms_key_id" {
type = string
description = "The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `encrypted = true`"
default = ""
default = null
}

variable "performance_mode" {
description = "(Optional) The file system performance mode. Can be either generalPurpose or maxIO"
type = string
default = "generalPurpose"
}

variable "provisioned_throughput_in_mibps" {
description = "(Optional) The throughput, measured in MiB/s, that you want to provision for the file system. Only applicable with throughput_mode set to provisioned"
type = number
default = null
}

variable "tags" {
description = "A mapping of tags to apply to resources"
type = map(string)
default = {}
}

variable "throughput_mode" {
description = "(Optional) Throughput mode for the file system. Defaults to bursting. Valid values: bursting, provisioned, or elastic. When using provisioned, also set provisioned_throughput_in_mibps"
type = string
default = "bursting"
}

variable "transition_to_ia" {
description = "(Optional) Indicates how long it takes to transition files to the IA storage class. Valid values: AFTER_1_DAY, AFTER_7_DAYS, AFTER_14_DAYS, AFTER_30_DAYS, AFTER_60_DAYS, or AFTER_90_DAYS"
type = string
default = null
}

variable "transition_to_primary_storage_class" {
description = " (Optional) Describes the policy used to transition a file from infequent access storage to primary storage. Valid values: AFTER_1_ACCESS"
type = string
default = null
}
22 changes: 9 additions & 13 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ resource "random_id" "creation_token" {
prefix = "${var.name}-"
}

resource "aws_efs_file_system" "this" {
creation_token = random_id.creation_token.hex

resource "aws_efs_file_system" "file_system" {
creation_token = var.creation_token
encrypted = var.encrypted
kms_key_id = var.kms_key_id

tags = merge(
map("Name", var.name),
map("CreationToken", random_id.creation_token.hex),
map("terraform", "true"),
var.tags,
)
throughput_mode = var.throughput_mode
performance_mode = var.performance_mode
provisioned_throughput_in_mibps = var.provisioned_throughput_in_mibps
tags = var.tags
}

resource "aws_efs_mount_target" "this" {
resource "aws_efs_mount_target" "mount_target" {
count = length(var.subnets)

file_system_id = aws_efs_file_system.this.id
file_system_id = aws_efs_file_system.file_system.id
subnet_id = element(var.subnets, count.index)
security_groups = [aws_security_group.mount_target.id]
}
Expand All @@ -30,7 +26,7 @@ resource "aws_security_group" "mount_target_client" {
description = "Allow traffic out to NFS for ${var.name}-mnt."
vpc_id = var.vpc_id

depends_on = [aws_efs_mount_target.this]
depends_on = [aws_efs_mount_target.mount_target]

tags = merge(
map("Name", "${var.name}-mount-target-client"),
Expand Down
8 changes: 4 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
output "file_system_dns_name" {
value = aws_efs_file_system.this.dns_name
value = aws_efs_file_system.file_system.dns_name
}
output "file_system_arn" {
value = aws_efs_file_system.this.arn
value = aws_efs_file_system.file_system.arn
}

output "file_system_id" {
value = aws_efs_file_system.this.id
value = aws_efs_file_system.file_system.id
}

output "ec2_security_group_id" {
Expand All @@ -15,5 +15,5 @@ output "ec2_security_group_id" {

output "mount_target_ids" {

value = [for mount_target in aws_efs_mount_target.this: mount_target.id ]
value = [for mount_target in aws_efs_mount_target.mount_target: mount_target.id ]
}

0 comments on commit 62aeca3

Please sign in to comment.