Skip to content

Commit d745b0c

Browse files
Merge pull request #20 from clouddrove/feature/sftp
Feature/sftp : Update the sftp module for the sftp server with vpc endpoint and custom domain
2 parents a3ef365 + d815900 commit d745b0c

File tree

15 files changed

+666
-98
lines changed

15 files changed

+666
-98
lines changed

.github/workflows/terraform.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: static-checks
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
versionExtract:
8+
name: Get min/max versions
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Terraform min/max versions
16+
id: minMax
17+
uses: clowdhaus/terraform-min-max@main
18+
outputs:
19+
minVersion: ${{ steps.minMax.outputs.minVersion }}
20+
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
21+
22+
23+
versionEvaluate:
24+
name: Evaluate Terraform versions
25+
runs-on: ubuntu-latest
26+
needs: versionExtract
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
version:
31+
- ${{ needs.versionExtract.outputs.minVersion }}
32+
- ${{ needs.versionExtract.outputs.maxVersion }}
33+
directory:
34+
- _example/public/
35+
- _example/vpc/
36+
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v2
40+
41+
- name: Install Terraform v${{ matrix.version }}
42+
uses: hashicorp/setup-terraform@v1
43+
with:
44+
terraform_version: ${{ matrix.version }}
45+
46+
- name: 'Configure AWS Credentials'
47+
uses: clouddrove/configure-aws-credentials@v1
48+
with:
49+
aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }}
50+
aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }}
51+
aws-region: us-east-2
52+
53+
- name: Init & validate v${{ matrix.version }}
54+
run: |
55+
cd ${{ matrix.directory }}
56+
terraform init
57+
terraform validate
58+
terraform plan -input=false -no-color
59+
60+
- name: tflint
61+
uses: reviewdog/action-tflint@master
62+
with:
63+
tflint_version: v0.29.0
64+
github_token: ${{ secrets.GITHUB }}
65+
working_directory: ${{ matrix.directory }}
66+
fail_on_error: 'true'
67+
filter_mode: 'nofilter'
68+
flags: '--module'
69+
70+
format:
71+
name: Check code format
72+
runs-on: ubuntu-latest
73+
needs: versionExtract
74+
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@v2
78+
79+
- name: Install Terraform v${{ needs.versionExtract.outputs.maxVersion }}
80+
uses: hashicorp/setup-terraform@v1
81+
with:
82+
terraform_version: ${{ needs.versionExtract.outputs.maxVersion }}
83+
84+
- name: Check Terraform format changes
85+
run: terraform fmt --recursive
86+

.github/workflows/tf-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ jobs:
88
example:
99
uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master
1010
with:
11-
working_directory: './_example/'
11+
working_directory: './_example/public'

_example/main.tf

Lines changed: 0 additions & 29 deletions
This file was deleted.

_example/outputs.tf

Lines changed: 0 additions & 9 deletions
This file was deleted.

_example/public/example.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
################################################################################
6+
# AWS S3
7+
################################################################################
8+
9+
module "s3_bucket" {
10+
source = "clouddrove/s3/aws"
11+
version = "1.3.0"
12+
13+
name = "clouddrove-sftp-bucket01"
14+
environment = "test"
15+
label_order = ["environment", "name"]
16+
17+
versioning = true
18+
logging = true
19+
acl = "private"
20+
force_destroy = true
21+
}
22+
23+
################################################################################
24+
# AWS SFTP
25+
################################################################################
26+
27+
module "sftp" {
28+
source = "../.."
29+
name = "sftp"
30+
environment = "test"
31+
label_order = ["environment", "name"]
32+
enable_sftp = true
33+
s3_bucket_name = module.s3_bucket.id
34+
endpoint_type = "PUBLIC"
35+
workflow_details = {
36+
on_upload = {
37+
execution_role = "arn:aws:iam::1234567890:role/test-sftp-transfer-role"
38+
workflow_id = "w-12345XXXX6da"
39+
}
40+
}
41+
}

_example/public/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "id" {
2+
description = "ID of the created example"
3+
value = module.sftp.id
4+
}

_example/public/variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
variable "sftp_users" {
2+
type = list(object({
3+
username = string
4+
password = string
5+
home_dir = string
6+
}))
7+
default = []
8+
}
9+
10+
variable "eip_enabled" {
11+
type = bool
12+
description = "Whether to provision and attach an Elastic IP to be used as the SFTP endpoint. An EIP will be provisioned per subnet."
13+
default = false
14+
}

_example/vpc/example.tf

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
################################################################################
6+
# VPC
7+
################################################################################
8+
9+
module "vpc" {
10+
source = "clouddrove/vpc/aws"
11+
version = "2.0.0"
12+
name = "vpc"
13+
environment = "test"
14+
cidr_block = "10.0.0.0/16"
15+
enable_flow_log = true # Flow logs will be stored in cloudwatch log group. Variables passed in default.
16+
create_flow_log_cloudwatch_iam_role = true
17+
additional_cidr_block = ["172.3.0.0/16", "172.2.0.0/16"]
18+
dhcp_options_domain_name = "service.consul"
19+
dhcp_options_domain_name_servers = ["127.0.0.1", "10.10.0.2"]
20+
}
21+
22+
################################################################################
23+
# Subnets
24+
################################################################################
25+
26+
module "subnets" {
27+
source = "clouddrove/subnet/aws"
28+
version = "1.0.1"
29+
30+
name = "subnets"
31+
environment = "test"
32+
label_order = ["environment", "name"]
33+
# tags = local.tags
34+
enabled = true
35+
36+
nat_gateway_enabled = true
37+
single_nat_gateway = true
38+
availability_zones = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
39+
vpc_id = module.vpc.vpc_id
40+
cidr_block = module.vpc.vpc_cidr_block
41+
ipv6_cidr_block = module.vpc.ipv6_cidr_block
42+
type = "public-private"
43+
}
44+
45+
################################################################################
46+
# AWS SFTP SECURITY GROUP
47+
################################################################################
48+
49+
module "security_group_sftp" {
50+
source = "clouddrove/security-group/aws"
51+
version = "2.0.0"
52+
name = "sftp-sg"
53+
environment = "test"
54+
label_order = ["environment", "name"]
55+
vpc_id = module.vpc.vpc_id
56+
## INGRESS Rules
57+
new_sg_ingress_rules_with_cidr_blocks = [{
58+
rule_count = 1
59+
from_port = 22
60+
protocol = "tcp"
61+
to_port = 22
62+
cidr_blocks = [module.vpc.vpc_cidr_block, "172.16.0.0/16"]
63+
description = "Allow ssh traffic."
64+
},
65+
{
66+
rule_count = 2
67+
from_port = 27017
68+
protocol = "tcp"
69+
to_port = 27017
70+
cidr_blocks = ["172.16.0.0/16"]
71+
description = "Allow SFTP traffic."
72+
}
73+
]
74+
75+
## EGRESS Rules
76+
new_sg_egress_rules_with_cidr_blocks = [{
77+
rule_count = 1
78+
from_port = 22
79+
protocol = "tcp"
80+
to_port = 22
81+
cidr_blocks = [module.vpc.vpc_cidr_block, "172.16.0.0/16"]
82+
description = "Allow ssh outbound traffic."
83+
},
84+
{
85+
rule_count = 2
86+
from_port = 27017
87+
protocol = "tcp"
88+
to_port = 27017
89+
cidr_blocks = ["172.16.0.0/16"]
90+
description = "Allow SFTP outbound traffic."
91+
}]
92+
}
93+
94+
################################################################################
95+
# AWS S3
96+
################################################################################
97+
98+
module "s3_bucket" {
99+
source = "clouddrove/s3/aws"
100+
version = "1.3.0"
101+
102+
name = "clouddrove-sftp-bucket"
103+
environment = "test"
104+
label_order = ["environment", "name"]
105+
106+
versioning = true
107+
logging = true
108+
acl = "private"
109+
force_destroy = true
110+
}
111+
112+
################################################################################
113+
# AWS SFTP
114+
################################################################################
115+
116+
module "sftp" {
117+
source = "../.."
118+
name = "sftp"
119+
environment = "test"
120+
label_order = ["environment", "name"]
121+
eip_enabled = false
122+
s3_bucket_name = module.s3_bucket.id
123+
sftp_users = var.sftp_users
124+
subnet_ids = module.subnets.private_subnet_id
125+
vpc_id = module.vpc.vpc_id
126+
restricted_home = true
127+
vpc_security_group_ids = [module.security_group_sftp.security_group_id]
128+
workflow_details = {
129+
on_upload = {
130+
execution_role = "arn:aws:iam::1234567890:role/test-sftp-transfer-role"
131+
workflow_id = "w-12345XXXX6da"
132+
}
133+
}
134+
}

_example/vpc/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "id" {
2+
description = "ID of the created example"
3+
value = module.sftp.id
4+
}

0 commit comments

Comments
 (0)