Skip to content

Commit

Permalink
Restricted and unrestricted users (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru committed Jul 29, 2022
1 parent 6f3e1b9 commit 770061d
Show file tree
Hide file tree
Showing 19 changed files with 705 additions and 429 deletions.
1 change: 0 additions & 1 deletion .github/auto-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ version-resolver:
- 'bugfix'
- 'bug'
- 'hotfix'
- 'no-release'
default: 'minor'

categories:
Expand Down
2 changes: 1 addition & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
":preserveSemverRanges"
],
"labels": ["auto-update"],
"dependencyDashboardAutoclose": true,
"enabledManagers": ["terraform"],
"terraform": {
"ignorePaths": ["**/context.tf", "examples/**"]
}
}

11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,21 @@ Available targets:

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_iam_label"></a> [iam\_label](#module\_iam\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_logging_label"></a> [logging\_label](#module\_logging\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | cloudposse/security-group/aws | 0.3.1 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |

## Resources
Expand Down Expand Up @@ -195,10 +194,6 @@ Available targets:
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| <a name="input_restricted_home"></a> [restricted\_home](#input\_restricted\_home) | Restricts SFTP users so they only have access to their home directories. | `bool` | `true` | no |
| <a name="input_s3_bucket_name"></a> [s3\_bucket\_name](#input\_s3\_bucket\_name) | This is the bucket that the SFTP users will use when managing files | `string` | n/a | yes |
| <a name="input_security_group_description"></a> [security\_group\_description](#input\_security\_group\_description) | The Security Group description. | `string` | `"AWS Transfer Server Security Group"` | no |
| <a name="input_security_group_enabled"></a> [security\_group\_enabled](#input\_security\_group\_enabled) | Whether to create default Security Group for AWS Transfer Server. | `bool` | `true` | no |
| <a name="input_security_group_rules"></a> [security\_group\_rules](#input\_security\_group\_rules) | A list of maps of Security Group rules. <br>The values of map is fully complated with `aws_security_group_rule` resource. <br>To get more info see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule . | `list(any)` | <pre>[<br> {<br> "cidr_blocks": [<br> "0.0.0.0/0"<br> ],<br> "description": "Allow inbound traffic",<br> "from_port": 22,<br> "protocol": "tcp",<br> "to_port": 22,<br> "type": "ingress"<br> }<br>]</pre> | no |
| <a name="input_security_group_use_name_prefix"></a> [security\_group\_use\_name\_prefix](#input\_security\_group\_use\_name\_prefix) | Whether to create a default Security Group with unique name beginning with the normalized prefix. | `bool` | `false` | no |
| <a name="input_security_policy_name"></a> [security\_policy\_name](#input\_security\_policy\_name) | Specifies the name of the security policy that is attached to the server. Possible values are TransferSecurityPolicy-2018-11, TransferSecurityPolicy-2020-06, and TransferSecurityPolicy-FIPS-2020-06. Default value is: TransferSecurityPolicy-2018-11. | `string` | `"TransferSecurityPolicy-2018-11"` | no |
| <a name="input_sftp_users"></a> [sftp\_users](#input\_sftp\_users) | List of SFTP usernames and public keys | <pre>map(object({<br> user_name = string,<br> public_key = string<br> }))</pre> | `{}` | no |
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
Expand Down
11 changes: 3 additions & 8 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_iam_label"></a> [iam\_label](#module\_iam\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_logging_label"></a> [logging\_label](#module\_logging\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | cloudposse/security-group/aws | 0.3.1 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |

## Resources
Expand Down Expand Up @@ -65,10 +64,6 @@
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| <a name="input_restricted_home"></a> [restricted\_home](#input\_restricted\_home) | Restricts SFTP users so they only have access to their home directories. | `bool` | `true` | no |
| <a name="input_s3_bucket_name"></a> [s3\_bucket\_name](#input\_s3\_bucket\_name) | This is the bucket that the SFTP users will use when managing files | `string` | n/a | yes |
| <a name="input_security_group_description"></a> [security\_group\_description](#input\_security\_group\_description) | The Security Group description. | `string` | `"AWS Transfer Server Security Group"` | no |
| <a name="input_security_group_enabled"></a> [security\_group\_enabled](#input\_security\_group\_enabled) | Whether to create default Security Group for AWS Transfer Server. | `bool` | `true` | no |
| <a name="input_security_group_rules"></a> [security\_group\_rules](#input\_security\_group\_rules) | A list of maps of Security Group rules. <br>The values of map is fully complated with `aws_security_group_rule` resource. <br>To get more info see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule . | `list(any)` | <pre>[<br> {<br> "cidr_blocks": [<br> "0.0.0.0/0"<br> ],<br> "description": "Allow inbound traffic",<br> "from_port": 22,<br> "protocol": "tcp",<br> "to_port": 22,<br> "type": "ingress"<br> }<br>]</pre> | no |
| <a name="input_security_group_use_name_prefix"></a> [security\_group\_use\_name\_prefix](#input\_security\_group\_use\_name\_prefix) | Whether to create a default Security Group with unique name beginning with the normalized prefix. | `bool` | `false` | no |
| <a name="input_security_policy_name"></a> [security\_policy\_name](#input\_security\_policy\_name) | Specifies the name of the security policy that is attached to the server. Possible values are TransferSecurityPolicy-2018-11, TransferSecurityPolicy-2020-06, and TransferSecurityPolicy-FIPS-2020-06. Default value is: TransferSecurityPolicy-2018-11. | `string` | `"TransferSecurityPolicy-2018-11"` | no |
| <a name="input_sftp_users"></a> [sftp\_users](#input\_sftp\_users) | List of SFTP usernames and public keys | <pre>map(object({<br> user_name = string,<br> public_key = string<br> }))</pre> | `{}` | no |
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
Expand Down
2 changes: 1 addition & 1 deletion examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ environment = "ue2"

stage = "test"

name = "example"
name = "sftp"

sftp_users = {
"brad" = {
Expand Down
7 changes: 6 additions & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ provider "aws" {
region = var.region
}

provider "awsutils" {
region = var.region
}

module "s3_bucket" {
source = "cloudposse/s3-bucket/aws"
version = "0.41.0"
version = "2.0.3"
acl = "private"
enabled = true
user_enabled = false
versioning_enabled = false
force_destroy = true

context = module.this.context
}
Expand Down
13 changes: 11 additions & 2 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
terraform {
required_version = ">= 0.13.7"
required_version = ">= 1.0"

required_providers {}
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0"
}
awsutils = {
source = "cloudposse/awsutils"
version = ">= 0.11.0"
}
}
}
6 changes: 5 additions & 1 deletion examples/vpc/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ environment = "ue2"

stage = "test"

name = "example"
name = "sftp"

availability_zones = ["us-east-2a", "us-east-2b"]

cidr_block = "10.0.0.0/16"

sftp_users = {
"brad" = {
Expand Down
65 changes: 43 additions & 22 deletions examples/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,76 @@ provider "aws" {
region = var.region
}

provider "awsutils" {
region = var.region
}


module "vpc" {
source = "cloudposse/vpc/aws"
version = "0.25.0"
version = "1.1.0"

cidr_block = "10.0.0.0/16"
cidr_block = var.cidr_block

context = module.this.context
}

module "dynamic_subnets" {
module "subnets" {
source = "cloudposse/dynamic-subnets/aws"
version = "0.39.3"
version = "2.0.2"

availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
igw_id = [module.vpc.igw_id]
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
max_nats = 1
nat_gateway_enabled = true
nat_instance_enabled = false

availability_zones = ["us-east-2a", "us-east-2b"]
vpc_id = module.vpc.vpc_id
igw_id = module.vpc.igw_id
cidr_block = "10.0.0.0/16"
context = module.this.context
}

module "security_group" {
source = "cloudposse/security-group/aws"
version = "1.0.1"

vpc_id = module.vpc.vpc_id
rules = [
{
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
]

context = module.this.context
}

module "s3_bucket" {
source = "cloudposse/s3-bucket/aws"
version = "0.41.0"
version = "2.0.3"
acl = "private"
enabled = true
user_enabled = false
versioning_enabled = false
force_destroy = true

context = module.this.context
}


module "example" {
source = "../.."

eip_enabled = true
security_group_enabled = true
security_group_rules = [{
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}]
s3_bucket_name = module.s3_bucket.bucket_id
sftp_users = var.sftp_users
subnet_ids = [module.dynamic_subnets.public_subnet_ids[1]]
vpc_id = module.vpc.vpc_id
restricted_home = true
s3_bucket_name = module.s3_bucket.bucket_id
sftp_users = var.sftp_users
subnet_ids = [module.subnets.public_subnet_ids[1]]
vpc_id = module.vpc.vpc_id
restricted_home = true
vpc_security_group_ids = [module.security_group.id]

context = module.this.context
}
10 changes: 10 additions & 0 deletions examples/vpc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ variable "region" {
type = string
}

variable "availability_zones" {
type = list(string)
description = "List of availability zones"
}

variable "cidr_block" {
type = string
description = "CIDR for the VPC"
}

variable "sftp_users" {
type = map(object({
user_name = string,
Expand Down
13 changes: 11 additions & 2 deletions examples/vpc/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
terraform {
required_version = ">= 0.13.7"
required_version = ">= 1.0"

required_providers {}
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0"
}
awsutils = {
source = "cloudposse/awsutils"
version = ">= 0.11.0"
}
}
}
24 changes: 5 additions & 19 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
locals {
enabled = module.this.enabled

is_vpc = var.vpc_id != null
security_group_enabled = module.this.enabled && var.security_group_enabled
user_names = keys(var.sftp_users)
user_names_map = { for idx, user in local.user_names : idx => user }
is_vpc = var.vpc_id != null
user_names = keys(var.sftp_users)
user_names_map = { for idx, user in local.user_names : idx => user }
}

data "aws_s3_bucket" "landing" {
Expand All @@ -29,7 +28,7 @@ resource "aws_transfer_server" "default" {

content {
subnet_ids = var.subnet_ids
security_group_ids = local.security_group_enabled ? module.security_group.*.id : var.vpc_security_group_ids
security_group_ids = var.vpc_security_group_ids
vpc_id = var.vpc_id
address_allocation_ids = var.eip_enabled ? aws_eip.sftp.*.id : var.address_allocation_ids
}
Expand All @@ -47,7 +46,7 @@ resource "aws_transfer_user" "default" {
user_name = each.value.user_name

home_directory_type = var.restricted_home ? "LOGICAL" : "PATH"
home_directory = ! var.restricted_home ? "/${var.s3_bucket_name}" : null
home_directory = !var.restricted_home ? "/${var.s3_bucket_name}" : null

dynamic "home_directory_mappings" {
for_each = var.restricted_home ? [1] : []
Expand Down Expand Up @@ -80,19 +79,6 @@ resource "aws_eip" "sftp" {
vpc = local.is_vpc
}

module "security_group" {
source = "cloudposse/security-group/aws"
version = "0.3.1"

use_name_prefix = var.security_group_use_name_prefix
rules = var.security_group_rules
description = var.security_group_description
vpc_id = local.is_vpc ? var.vpc_id : null

enabled = local.security_group_enabled
context = module.this.context
}

# Custom Domain
resource "aws_route53_record" "main" {
count = local.enabled && length(var.domain_name) > 0 && length(var.zone_id) > 0 ? 1 : 0
Expand Down
4 changes: 2 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ clean:
all: module examples/complete

## Run basic sanity checks against the module itself
module: export TESTS ?= installed lint get-modules module-pinning get-plugins provider-pinning validate terraform-docs input-descriptions output-descriptions
module: export TESTS ?= installed lint module-pinning provider-pinning validate terraform-docs input-descriptions output-descriptions
module: deps
$(call RUN_TESTS, ../)

## Run tests against example
examples/complete: export TESTS ?= installed lint get-modules get-plugins validate
examples/complete: export TESTS ?= installed lint validate
examples/complete: deps
$(call RUN_TESTS, ../$@)
5 changes: 2 additions & 3 deletions test/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export TF_CLI_ARGS_init ?= -get-plugins=true
export TERRAFORM_VERSION ?= $(shell curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version' | cut -d. -f1-2)
export TERRAFORM_VERSION ?= $(shell curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version' | cut -d. -f1)

.DEFAULT_GOAL : all
.PHONY: all
Expand All @@ -16,7 +15,7 @@ init:
## Run tests
test: init
go mod download
go test -v -timeout 60m -run TestExamples
go test -v -timeout 40m

## Run tests in docker container
docker/test:
Expand Down
Loading

0 comments on commit 770061d

Please sign in to comment.