From 4357f4c4a4aa0ea20bc9850d499dbb7eccfdedc5 Mon Sep 17 00:00:00 2001 From: Pedro Carmezim Date: Mon, 11 Apr 2022 15:01:21 +0100 Subject: [PATCH 1/4] add AWS EFS simple --- aws/aws_efs/simple/destroy.sh | 2 + aws/aws_efs/simple/main.tf | 76 +++++++++++++++++++++++++++++++++++ aws/aws_efs/simple/run.sh | 2 + 3 files changed, 80 insertions(+) create mode 100755 aws/aws_efs/simple/destroy.sh create mode 100644 aws/aws_efs/simple/main.tf create mode 100755 aws/aws_efs/simple/run.sh diff --git a/aws/aws_efs/simple/destroy.sh b/aws/aws_efs/simple/destroy.sh new file mode 100755 index 00000000..0f65744a --- /dev/null +++ b/aws/aws_efs/simple/destroy.sh @@ -0,0 +1,2 @@ +#!/bin/bash +../../../bin/destroy.sh aws diff --git a/aws/aws_efs/simple/main.tf b/aws/aws_efs/simple/main.tf new file mode 100644 index 00000000..8265f9ac --- /dev/null +++ b/aws/aws_efs/simple/main.tf @@ -0,0 +1,76 @@ + +# Summary: Create an EFS in AWS + +# Documentation: https://www.terraform.io/docs/language/settings/index.html +terraform { + required_version = ">= 1.0.0" + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.38" + } + } +} + +# Documentation: https://www.terraform.io/docs/language/providers/requirements.html +provider "aws" { + region = "us-east-1" + default_tags { + tags = { + cs_terraform_examples = "aws_efs/simple" + } + } +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc +data "aws_vpc" "changeme_default_aws_vpc" { + default = true +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids +data "aws_subnet_ids" "changeme_aws_subnet_ids" { + vpc_id = data.aws_vpc.changeme_default_aws_vpc.id +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group +resource "aws_security_group" "changeme_efs_aws_security_group" { + name = "changeme-simple-efs-security-group" + description = "Allow inbound traffic" + ingress { + from_port = 2049 + to_port = 2049 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/efs_file_system +resource "aws_efs_file_system" "changeme_aws_efs" { + performance_mode = "generalPurpose" + throughput_mode = "bursting" + encrypted = "false" + kms_key_id = null + + tags = { + Name = "changeme-simple-efs" + } + + lifecycle_policy { + transition_to_ia = "AFTER_30_DAYS" + } +} + +resource "aws_efs_mount_target" "changeme_efs_mount_target" { + for_each = data.aws_subnet_ids.changeme_aws_subnet_ids.ids + subnet_id = each.value + file_system_id = aws_efs_file_system.changeme_aws_efs.id + security_groups = [aws_security_group.changeme_efs_aws_security_group.id] + +} diff --git a/aws/aws_efs/simple/run.sh b/aws/aws_efs/simple/run.sh new file mode 100755 index 00000000..b84d2277 --- /dev/null +++ b/aws/aws_efs/simple/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +../../../bin/apply.sh aws From be8305edb981f4f9e3e1100f1e9af1f5c13b38ea Mon Sep 17 00:00:00 2001 From: Pedro Carmezim Date: Mon, 11 Apr 2022 15:34:09 +0100 Subject: [PATCH 2/4] add missing documentation refer --- aws/aws_efs/simple/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/aws_efs/simple/main.tf b/aws/aws_efs/simple/main.tf index 8265f9ac..a053a360 100644 --- a/aws/aws_efs/simple/main.tf +++ b/aws/aws_efs/simple/main.tf @@ -67,10 +67,10 @@ resource "aws_efs_file_system" "changeme_aws_efs" { } } +# Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/efs_mount_target resource "aws_efs_mount_target" "changeme_efs_mount_target" { for_each = data.aws_subnet_ids.changeme_aws_subnet_ids.ids subnet_id = each.value file_system_id = aws_efs_file_system.changeme_aws_efs.id security_groups = [aws_security_group.changeme_efs_aws_security_group.id] - } From 461fb40d8255e5e926d660650ce42f5594455383 Mon Sep 17 00:00:00 2001 From: Pedro Carmezim Date: Tue, 12 Apr 2022 18:55:35 +0100 Subject: [PATCH 3/4] fix entry to efs on INDEX.md for simple --- INDEX.md | 1 + aws/aws_efs/simple/main.tf | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/INDEX.md b/INDEX.md index 88021edf..d783cec7 100644 --- a/INDEX.md +++ b/INDEX.md @@ -9,6 +9,7 @@ | `aws_dynamodb_table` | [aws](aws/aws_dynamodb_table)

[simple](aws/aws_dynamodb_table/simple) | | `aws_ebs_volume` | [aws](aws/aws_ebs_volume)

[simple](aws/aws_ebs_volume/simple)

[volume_attachment](aws/aws_ebs_volume/volume_attachment)

[ebs_snapshot](aws/aws_ebs_volume/ebs_snapshot) | | `aws_eks` | [aws, spot_and_fargate](aws/aws_eks/fargate/spot_and_fargate) | +| `aws_efs` | [aws](aws/aws_efs)

[simple](aws/aws_efs/simple) | | `aws_elb` | [aws](aws/aws_elb)

[application_elb](aws/aws_elb/application_elb)

[network_elb](aws/aws_elb/network_elb) [classic_elb](aws/aws_elb/classic_elb) | | `aws_iam` | [iam_user_and_access_key](aws/aws_iam/users)

[users_and_groups](aws/aws_iam/groups) | | `aws_instance` | [aws](aws/aws_instance)

[simple](aws/aws_instance/simple)

[simple_ssh_access](aws/aws_instance/simple_ssh_access)

[ami_lookup](aws/aws_instance/ami_lookup) | diff --git a/aws/aws_efs/simple/main.tf b/aws/aws_efs/simple/main.tf index a053a360..f45ba041 100644 --- a/aws/aws_efs/simple/main.tf +++ b/aws/aws_efs/simple/main.tf @@ -34,8 +34,8 @@ data "aws_subnet_ids" "changeme_aws_subnet_ids" { # Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group resource "aws_security_group" "changeme_efs_aws_security_group" { - name = "changeme-simple-efs-security-group" - description = "Allow inbound traffic" + name = "changeme-simple-efs-security-group" + description = "Allow inbound traffic" ingress { from_port = 2049 to_port = 2049 @@ -53,10 +53,10 @@ resource "aws_security_group" "changeme_efs_aws_security_group" { # Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/efs_file_system resource "aws_efs_file_system" "changeme_aws_efs" { - performance_mode = "generalPurpose" - throughput_mode = "bursting" - encrypted = "false" - kms_key_id = null + performance_mode = "generalPurpose" + throughput_mode = "bursting" + encrypted = "false" + kms_key_id = null tags = { Name = "changeme-simple-efs" From b8c47ca2fb68ede2f162e6737af001afffd639ad Mon Sep 17 00:00:00 2001 From: Pedro Carmezim <33536538+b4ld@users.noreply.github.com> Date: Wed, 13 Apr 2022 18:45:29 +0100 Subject: [PATCH 4/4] Update main.tf fix black space --- aws/aws_efs/simple/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/aws_efs/simple/main.tf b/aws/aws_efs/simple/main.tf index f45ba041..04557500 100644 --- a/aws/aws_efs/simple/main.tf +++ b/aws/aws_efs/simple/main.tf @@ -34,8 +34,8 @@ data "aws_subnet_ids" "changeme_aws_subnet_ids" { # Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group resource "aws_security_group" "changeme_efs_aws_security_group" { - name = "changeme-simple-efs-security-group" - description = "Allow inbound traffic" + name = "changeme-simple-efs-security-group" + description = "Allow inbound traffic" ingress { from_port = 2049 to_port = 2049