Skip to content

Commit

Permalink
Use external module for EFS
Browse files Browse the repository at this point in the history
  • Loading branch information
vivgoyal-aws committed Jul 1, 2022
1 parent 8cf6032 commit 889c315
Show file tree
Hide file tree
Showing 36 changed files with 223 additions and 532 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tfsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
branches: [ "main" ]
schedule:
- cron: '39 18 * * 2'

Expand All @@ -29,10 +29,10 @@ jobs:
- name: Run tfsec
uses: aquasecurity/tfsec-sarif-action@9a83b5c3524f825c020e356335855741fd02745f
with:
sarif_file: tfsec.sarif
sarif_file: tfsec.sarif

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
# Path to SARIF file relative to the root of the repository
sarif_file: tfsec.sarif
sarif_file: tfsec.sarif
9 changes: 7 additions & 2 deletions README-PORTABLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ The solution has following features and benefits:

- The target AWS Account and AWS Region are identified.
- The AWS User/Role executing the Terraform scripts must have permissions to provision the target resources.
- The Terraform CLI (`version = ">= 1.0.4"`) is installed.
- The [Terraform CLI](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) (`version = ">= 1.1.9"`) is installed.
- The [Python 3.9+](https://www.python.org/downloads/) is installed.
- AWS SDK for Python [boto3 1.24+](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#installation) is installed.
- Terraform backend provider and state locking providers are identified and bootstrapped.
- An [example bootstrap](https://github.com/aws-samples/aws-tf-transfer-sftp-efs/tree/main/bootstrap) module/example is provided that provisions an Amazon S3 bucket for Terraform state storage and Amazon DynamoDB table for Terraform state locking.
- The Amazon S3 bucket name has to be globally unique.
Expand All @@ -49,7 +51,10 @@ The solution has following features and benefits:
## Usage
- Use the module via [GitHub source](https://www.terraform.io/language/modules/sources#github) or copy the module into your repository.
- Incorporate the module in your CI/CD pipeline as appropriate.
- Incorporate the module in your infrastructure/storage [CI](https://aws.amazon.com/devops/continuous-integration/)/[CD](https://aws.amazon.com/devops/continuous-delivery/) [pipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/concepts.html) as appropriate.
- This solution uses following external modules
- [aws-tf-kms](https://github.com/aws-samples/aws-tf-kms) to provision AWS KMS Key, if encryption is enabled and `kms_alias` is not provided.
- [aws-tf-efs](https://github.com/aws-samples/aws-tf-efs) to provision Amazon EFS or EFS Access Point, if `efs_id` is null or `efs_ap_id` is null.
## Scenarios
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ The solution has following features and benefits:

- The target AWS Account and AWS Region are identified.
- The AWS User/Role executing the Terraform scripts must have permissions to provision the target resources.
- The Terraform CLI (`version = ">= 1.0.4"`) is installed.
- The [Terraform CLI](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) (`version = ">= 1.1.9"`) is installed.
- The [Python 3.9+](https://www.python.org/downloads/) is installed.
- AWS SDK for Python [boto3 1.24+](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#installation) is installed.
- Terraform backend provider and state locking providers are identified and bootstrapped.
- An [example bootstrap](./bootstrap) module/example is provided that provisions an Amazon S3 bucket for Terraform state storage and Amazon DynamoDB table for Terraform state locking.
- The Amazon S3 bucket name has to be globally unique.
Expand All @@ -49,7 +51,10 @@ The solution has following features and benefits:
## Usage
- Use the module via [GitHub source](https://www.terraform.io/language/modules/sources#github) or copy the module into your repository.
- Incorporate the module in your CI/CD pipeline as appropriate.
- Incorporate the module in your infrastructure/storage [CI](https://aws.amazon.com/devops/continuous-integration/)/[CD](https://aws.amazon.com/devops/continuous-delivery/) [pipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/concepts.html) as appropriate.
- This solution uses following external modules
- [aws-tf-kms](https://github.com/aws-samples/aws-tf-kms) to provision AWS KMS Key, if encryption is enabled and `kms_alias` is not provided.
- [aws-tf-efs](https://github.com/aws-samples/aws-tf-efs) to provision Amazon EFS or EFS Access Point, if `efs_id` is null or `efs_ap_id` is null.
## Scenarios
Expand Down
20 changes: 20 additions & 0 deletions examples/efs/scenario1/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/efs/scenario1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ No providers.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_common_efs"></a> [common\_efs](#module\_common\_efs) | ../../../modules/aws/efs | n/a |
| <a name="module_common_efs"></a> [common\_efs](#module\_common\_efs) | github.com/aws-samples/aws-tf-efs//modules/aws/efs | v1.0.0 |
## Resources
Expand All @@ -66,7 +66,7 @@ No resources.
| <a name="input_subnet_tags"></a> [subnet\_tags](#input\_subnet\_tags) | Tags to discover target subnets in the VPC, these tags should identify one or more subnets | `map(string)` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | Common and mandatory tags for the resources | `map(string)` | n/a | yes |
| <a name="input_vpc_tags"></a> [vpc\_tags](#input\_vpc\_tags) | Tags to discover target VPC, these tags should uniquely identify a VPC | `map(string)` | n/a | yes |
| <a name="input_efs_access_point_specs"></a> [efs\_access\_point\_specs](#input\_efs\_access\_point\_specs) | List of EFS Access Point Specs to be created. It can be empty list. | <pre>list(object({<br> efs_name = string # unique name e.g. common<br> efs_ap = string # unique name e.g. common_sftp<br> uid = number<br> gid = number<br> root_path = string # e.g. /{env}/{project}/{purpose}/{name}<br> owner_uid = number # e.g. 0<br> owner_gid = number # e.g. 0<br> root_permission = string # e.g. 0755<br> }))</pre> | `[]` | no |
| <a name="input_efs_access_point_specs"></a> [efs\_access\_point\_specs](#input\_efs\_access\_point\_specs) | List of EFS Access Point Specs to be created. It can be empty list. | <pre>list(object({<br> efs_name = string # unique name e.g. common<br> efs_ap = string # unique name e.g. common_sftp<br> uid = number<br> gid = number<br> secondary_gids = list(number)<br> root_path = string # e.g. /{env}/{project}/{purpose}/{name}<br> owner_uid = number # e.g. 0<br> owner_gid = number # e.g. 0<br> root_permission = string # e.g. 0755<br> principal_arns = list(string)<br> }))</pre> | `[]` | no |
| <a name="input_efs_id"></a> [efs\_id](#input\_efs\_id) | EFS File System Id, if not provided a new EFS will be created | `string` | `null` | no |
| <a name="input_kms_alias"></a> [kms\_alias](#input\_kms\_alias) | KMS Alias to discover KMS for EFS encryption, if not provided a new CMK will be created | `string` | `""` | no |
| <a name="input_security_group_tags"></a> [security\_group\_tags](#input\_security\_group\_tags) | Tags used to discover EFS Security Group, if not provided new EFS security group will be created | `map(string)` | `null` | no |
Expand Down
26 changes: 13 additions & 13 deletions examples/efs/scenario1/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "common_efs" {
source = "../../../modules/aws/efs"
source = "github.com/aws-samples/aws-tf-efs//modules/aws/efs?ref=v1.0.0"

region = var.region

Expand All @@ -14,18 +14,18 @@ module "common_efs" {
kms_alias = var.kms_alias
kms_admin_roles = ["Admin"]

efs_specs = [
{
name = "common"
efs_id = var.efs_id
encrypted = true
performance_mode = "generalPurpose"
transition_to_ia = "AFTER_7_DAYS"
backup_plan = "EVERY-DAY"
# If security_group_tags is null, EFS security group is created
security_group_tags = var.security_group_tags
}
]
# If security_group_tags is null, EFS security group is created
security_group_tags = var.security_group_tags

efs_name = "common"
efs_id = var.efs_id
encrypted = true
performance_mode = "generalPurpose"
transition_to_ia = "AFTER_7_DAYS"

efs_tags = {
"BackupPlan" = "EVERY-DAY"
}

efs_access_point_specs = var.efs_access_point_specs
}
2 changes: 1 addition & 1 deletion examples/efs/scenario1/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ output "efs_ap" {

output "efs_kms" {
description = "KMS Keys created for EFS"
value = module.common_efs.efs_kms
value = module.common_efs.efs_kms_aliases
}
8 changes: 5 additions & 3 deletions examples/efs/scenario1/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ region = "us-east-1"
/*---------------------------------------------------------
Common Variables
---------------------------------------------------------*/
project = "scenario1-efs"
project = "scenario1-efs-sftp"
env_name = "dev"
tags = {
Env = "DEV"
Project = "scenario1-efs"
Project = "scenario1-efs-sftp"
}

/*---------------------------------------------------------
Expand Down Expand Up @@ -40,9 +40,11 @@ efs_access_point_specs = [
efs_ap = "sftp_scenario1"
uid = 0
gid = 0
root_path = "/dev/scenario1-efs/sftp/common"
secondary_gids = []
root_path = "/dev/scenario1-efs-sftp/sftp/common"
owner_uid = 0
owner_gid = 0
root_permission = "0755"
principal_arns = ["*"]
}
]
2 changes: 2 additions & 0 deletions examples/efs/scenario1/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ variable "efs_access_point_specs" {
efs_ap = string # unique name e.g. common_sftp
uid = number
gid = number
secondary_gids = list(number)
root_path = string # e.g. /{env}/{project}/{purpose}/{name}
owner_uid = number # e.g. 0
owner_gid = number # e.g. 0
root_permission = string # e.g. 0755
principal_arns = list(string)
}))
default = []
}
20 changes: 20 additions & 0 deletions examples/efs/scenario2/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/efs/scenario2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ No providers.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_common_efs"></a> [common\_efs](#module\_common\_efs) | ../../../modules/aws/efs | n/a |
| <a name="module_common_efs"></a> [common\_efs](#module\_common\_efs) | github.com/aws-samples/aws-tf-efs//modules/aws/efs | v1.0.0 |
## Resources
Expand All @@ -66,7 +66,7 @@ No resources.
| <a name="input_subnet_tags"></a> [subnet\_tags](#input\_subnet\_tags) | Tags to discover target subnets in the VPC, these tags should identify one or more subnets | `map(string)` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | Common and mandatory tags for the resources | `map(string)` | n/a | yes |
| <a name="input_vpc_tags"></a> [vpc\_tags](#input\_vpc\_tags) | Tags to discover target VPC, these tags should uniquely identify a VPC | `map(string)` | n/a | yes |
| <a name="input_efs_access_point_specs"></a> [efs\_access\_point\_specs](#input\_efs\_access\_point\_specs) | List of EFS Access Point Specs to be created. It can be empty list. | <pre>list(object({<br> efs_name = string # unique name e.g. common<br> efs_ap = string # unique name e.g. common_sftp<br> uid = number<br> gid = number<br> root_path = string # e.g. /{env}/{project}/{purpose}/{name}<br> owner_uid = number # e.g. 0<br> owner_gid = number # e.g. 0<br> root_permission = string # e.g. 0755<br> }))</pre> | `[]` | no |
| <a name="input_efs_access_point_specs"></a> [efs\_access\_point\_specs](#input\_efs\_access\_point\_specs) | List of EFS Access Point Specs to be created. It can be empty list. | <pre>list(object({<br> efs_name = string # unique name e.g. common<br> efs_ap = string # unique name e.g. common_sftp<br> uid = number<br> gid = number<br> secondary_gids = list(number)<br> root_path = string # e.g. /{env}/{project}/{purpose}/{name}<br> owner_uid = number # e.g. 0<br> owner_gid = number # e.g. 0<br> root_permission = string # e.g. 0755<br> principal_arns = list(string)<br> }))</pre> | `[]` | no |
| <a name="input_efs_id"></a> [efs\_id](#input\_efs\_id) | EFS File System Id, if not provided a new EFS will be created | `string` | `null` | no |
| <a name="input_kms_alias"></a> [kms\_alias](#input\_kms\_alias) | KMS Alias to discover KMS for EFS encryption, if not provided a new CMK will be created | `string` | `""` | no |
| <a name="input_security_group_tags"></a> [security\_group\_tags](#input\_security\_group\_tags) | Tags used to discover EFS Security Group, if not provided new EFS security group will be created | `map(string)` | `null` | no |
Expand Down
26 changes: 13 additions & 13 deletions examples/efs/scenario2/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "common_efs" {
source = "../../../modules/aws/efs"
source = "github.com/aws-samples/aws-tf-efs//modules/aws/efs?ref=v1.0.0"

region = var.region

Expand All @@ -14,18 +14,18 @@ module "common_efs" {
kms_alias = var.kms_alias
kms_admin_roles = ["Admin"]

efs_specs = [
{
name = "common"
efs_id = var.efs_id
encrypted = true
performance_mode = "generalPurpose"
transition_to_ia = "AFTER_7_DAYS"
backup_plan = "EVERY-DAY"
# If security_group_tags is null, EFS security group is created
security_group_tags = var.security_group_tags
}
]
# If security_group_tags is null, EFS security group is created
security_group_tags = var.security_group_tags

efs_name = "common"
efs_id = var.efs_id
encrypted = true
performance_mode = "generalPurpose"
transition_to_ia = "AFTER_7_DAYS"

efs_tags = {
"BackupPlan" = "EVERY-DAY"
}

efs_access_point_specs = var.efs_access_point_specs
}
2 changes: 1 addition & 1 deletion examples/efs/scenario2/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ output "efs_ap" {

output "efs_kms" {
description = "KMS Keys created for EFS"
value = module.common_efs.efs_kms
value = module.common_efs.efs_kms_aliases
}
4 changes: 2 additions & 2 deletions examples/efs/scenario2/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ region = "us-east-1"
/*---------------------------------------------------------
Common Variables
---------------------------------------------------------*/
project = "scenario2-efs"
project = "scenario2-efs-sftp"
env_name = "dev"
tags = {
Env = "DEV"
Project = "scenario2-efs"
Project = "scenario2-efs-sftp"
}

/*---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions examples/efs/scenario2/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ variable "efs_access_point_specs" {
efs_ap = string # unique name e.g. common_sftp
uid = number
gid = number
secondary_gids = list(number)
root_path = string # e.g. /{env}/{project}/{purpose}/{name}
owner_uid = number # e.g. 0
owner_gid = number # e.g. 0
root_permission = string # e.g. 0755
principal_arns = list(string)
}))
default = []
}
20 changes: 20 additions & 0 deletions examples/sftp/scenario1/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/sftp/scenario1/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ efs_id = "your-efs-id"
efs_ap_id = "your-efs-ap-id"
# Use existing EFS SG
efs_sg_tags = {
Name = "scenario1-efs-common-efs-sg"
Name = "scenario1-efs-sftp-common-efs-sg"
Env = "DEV"
}

#efs exists, so kms must exist
efs_kms_alias = "alias/scenario1-efs/efs"
efs_kms_alias = "alias/scenario1-efs-sftp/efs"

#create new roles
user_role = null
Expand Down
20 changes: 20 additions & 0 deletions examples/sftp/scenario2/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 889c315

Please sign in to comment.