Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade security group module #24

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fa934a0
Fixing 'id' output to properly output the disambiguated ID of the pro…
girdot Jun 1, 2022
213a41d
Auto Format
cloudpossebot Jun 1, 2022
9e74ef0
Null 'id' output if module disabled
girdot Jun 1, 2022
c79bda1
make pr/auto-format
nitrocode Jul 25, 2022
03ed99f
Auto Format
cloudpossebot Jul 25, 2022
590b65a
Add sg inputs, deprecate inputs, migration doc
nitrocode Jul 25, 2022
33b12c5
Auto Format
cloudpossebot Jul 25, 2022
9e1aa12
Use non-deprecated inputs
nitrocode Jul 25, 2022
aa94a7f
Auto Format
cloudpossebot Jul 25, 2022
f8e87bb
rm duplicate input var.vpc_id
nitrocode Jul 25, 2022
8f79a0c
Auto Format
cloudpossebot Jul 25, 2022
6b825ad
Merge branch 'feature/add-transfer-server-id-to-output' into sg-latest
nitrocode Jul 25, 2022
a790dbc
make pr/auto-format
nitrocode Jul 25, 2022
1dcfe77
tf 0.14 versions and make pr/auto-format
nitrocode Jul 25, 2022
e019969
Bump golang tests
nitrocode Jul 25, 2022
9bcc64d
Use var allowed security groups
nitrocode Jul 25, 2022
ed408aa
Allow optional vpc_id and regenerate readme
nitrocode Jul 25, 2022
ab64dbb
Remove unused golang var
nitrocode Jul 25, 2022
5fc222c
Use version 2 of sg inputs
nitrocode Jul 26, 2022
2bcf6ba
Auto Format
cloudpossebot Jul 26, 2022
aff8350
Use sg version 3 exports, v2 of sg module
nitrocode Jul 28, 2022
5328557
Bump versions to tf 1.0.0 as required by sg 2.x
nitrocode Jul 29, 2022
e7b2a4c
Use endpoint type, sg inputs, small fixes
nitrocode Jul 29, 2022
79b1093
Use upstream sg fix
nitrocode Jul 29, 2022
ff4897d
Used allowed ipv6 sg inputs
nitrocode Jul 29, 2022
a7d5331
wip
nitrocode Jul 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/**"]
}
}

55 changes: 41 additions & 14 deletions README.md

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@ usage: |-
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest)
(which tests and deploys the example on AWS), see [test](test).

**NOTE**: Release `0.7.0` contains breaking changes. To preserve the SG, follow the instructions in the [0.6.0 to 0.7.x+ migration path](./docs/migration-0.6.0-0.7.x+.md).

```hcl
module "example" {
source = "https://github.com/cloudposse/terraform-aws-transfer-sftp.git?ref=master"
example = "Hello world!"
module "sftp" {
source = "cloudposse/sftp-transfer/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"

sftp_users = var.sftp_users

s3_bucket_name = module.s3_bucket.bucket_id

context = module.this.context
}
```

Expand All @@ -96,3 +105,5 @@ include:
contributors:
- name: "Erik Osterman"
github: "osterman"
- name: "RB"
github: "nitrocode"
11 changes: 11 additions & 0 deletions docs/migration-0.6.0-0.7.x+.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Migration from 0.6.0 to 0.7.x+

Change the following

- `security_group_enabled` to `create_security_group`
- `security_group_use_name_prefix` to `security_group_create_before_destroy`. This now defaults to `true`.
- `security_group_rules` to `additional_security_group_rules` and omit the port `22` rules since those are added by the new version of the module.
- `security_group_description` may need to be set to `The Security Group description.` which was the original description in version 0.6.0.
- `vpc_security_group_ids` to `associated_security_group_ids`

A terraform state move may be needed in case the security group resource has moved between versions.
34 changes: 25 additions & 9 deletions docs/terraform.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ sftp_users = {
"kenny" = {
user_name = "kenny",
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCYN8IRq10gKJj5/y2IHYFFRXHctJ+VblcsOnwvsbUIB+PKMLLWd5ySpW30s8OFVcxpMu2VXzXVKRGGbOUbZEN7MqH9xkW8eV6tSfXsZK2osLdIQ3QG3eSyoN4gPFlDBkZSzmkb2oaaclGPGRezbzDnp+oz8IiC5ZE8aprq3Xk850fifIEEOhJtVsrL84uwgx4LGZMMQmLdf6xm2SMSMx53zDPtSnlSeMlC2qUz6LBC41gwObQDoh0j3svsENf8FS8iIkdX50NaRoZvhJU0Oud5A7bj3zz0xtKn6uQZnL9hb6ttvp2/mNe1CKBZt9hUdrn4SHPs0sbWYbQLTzp+9okcg8LCe7qnFdHH7xQGp17SAgi5f91RPOUWtqvkOC5yoVaveR82KZObU+HSCfT/PObLjdUDtWrZABp4VM/u5t9Fn6BQ+eRSAiCIqLQlizs9kpKO8LYX7CagxRJz8KtRXfhndA3nTFq35vml8rD5hKsTrtbSkycmytQZ8TF7IwuN0amRfZ7Iwb3/eLTEv6jp5PKKVprBvnjDH1ipn/AwidsKrbCCVquKg0X/7rwVLrvMuYAtlxPLqjqZpvfTwXBwLlHTEuCvuh/Y/TpjJqqxCnbY/6R4TcabHVGsA4b1kVajRbvVPZPGVcWs+XvycO4Y8KR/hZZGGxK16SVFGbrnhX1D2Q== [email protected]"

}
}
2 changes: 1 addition & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module "s3_bucket" {
context = module.this.context
}

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

sftp_users = var.sftp_users
Expand Down
4 changes: 2 additions & 2 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
output "id" {
description = "ID of the created example"
value = module.example.id
value = module.sftp.id
}

output "transfer_endpoint" {
description = "Endpoint for your SFTP connection"
value = module.example.transfer_endpoint
value = module.sftp.transfer_endpoint
}
10 changes: 8 additions & 2 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
terraform {
required_version = ">= 0.13.7"
required_version = ">= 1.0.0"

required_providers {}
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0"
}
}
}

6 changes: 3 additions & 3 deletions examples/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ module "s3_bucket" {
context = module.this.context
}

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

eip_enabled = true
security_group_enabled = true
eip_enabled = true
create_security_group = true
security_group_rules = [{
type = "ingress"
from_port = 22
Expand Down
4 changes: 2 additions & 2 deletions examples/vpc/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
output "id" {
description = "ID of the created example"
value = module.example.id
value = module.sftp.id
}

output "transfer_endpoint" {
description = "Endpoint for your SFTP connection"
value = module.example.transfer_endpoint
value = module.sftp.transfer_endpoint
}
10 changes: 8 additions & 2 deletions examples/vpc/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
terraform {
required_version = ">= 0.13.7"
required_version = ">= 1.0.0"

required_providers {}
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0"
}
}
}

64 changes: 51 additions & 13 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
locals {
enabled = module.this.enabled

is_vpc = var.vpc_id != null
security_group_enabled = module.this.enabled && var.security_group_enabled
is_vpc = var.vpc_id != null
endpoint_type = var.vpc_endpoint_id != null ? "VPC_ENDPOINT" : (local.is_vpc ? "VPC" : "PUBLIC")

security_group_enabled = module.this.enabled && (var.create_security_group && var.security_group_enabled) && local.is_vpc
user_names = keys(var.sftp_users)
user_names_map = { for idx, user in local.user_names : idx => user }
}
Expand All @@ -19,7 +21,7 @@ resource "aws_transfer_server" "default" {
identity_provider_type = "SERVICE_MANAGED"
protocols = ["SFTP"]
domain = var.domain
endpoint_type = local.is_vpc ? "VPC" : "PUBLIC"
endpoint_type = local.endpoint_type
force_destroy = var.force_destroy
security_policy_name = var.security_policy_name
logging_role = join("", aws_iam_role.logging[*].arn)
Expand All @@ -29,9 +31,10 @@ 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 = local.security_group_enabled ? module.security_group.*.id : concat(var.associated_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
vpc_endpoint_id = var.vpc_endpoint_id
}
}

Expand All @@ -47,7 +50,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 @@ -78,18 +81,45 @@ resource "aws_eip" "sftp" {
count = local.enabled && var.eip_enabled ? length(var.subnet_ids) : 0

vpc = local.is_vpc

tags = module.this.tags
}

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
source = "git::https://github.com/cloudposse/terraform-aws-security-group?ref=2.0.0-rc1"
# source = "cloudposse/security-group/aws"
# version = "1.0.1"
Comment on lines +89 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
source = "git::https://github.com/cloudposse/terraform-aws-security-group?ref=2.0.0-rc1"
# source = "cloudposse/security-group/aws"
# version = "1.0.1"
source = "cloudposse/security-group/aws"
version = "2.0.0-rc1"


enabled = local.security_group_enabled
security_group_name = var.security_group_name
create_before_destroy = var.security_group_create_before_destroy
security_group_create_timeout = var.security_group_create_timeout
security_group_delete_timeout = var.security_group_delete_timeout
security_group_description = var.security_group_description
preserve_security_group_id = var.preserve_security_group_id
allow_all_egress = var.allow_all_egress

rules = var.additional_security_group_rules
rule_matrix = [
{
source_security_group_ids = var.allowed_security_group_ids
cidr_blocks = var.allowed_cidr_blocks
ipv6_cidr_blocks = var.allowed_ipv6_cidr_blocks
prefix_list_ids = var.allowed_ipv6_prefix_list_ids
rules = [
{
key = "in"
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
description = "Allow ingress EFS traffic"
}
]
}
]
vpc_id = local.is_vpc ? var.vpc_id : null

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

Expand Down Expand Up @@ -199,6 +229,8 @@ resource "aws_iam_policy" "s3_access_for_sftp_users" {

name = module.iam_label[index(local.user_names, each.value)].id
policy = data.aws_iam_policy_document.s3_access_for_sftp_users[index(local.user_names, each.value)].json

tags = module.this.tags
}

resource "aws_iam_role" "s3_access_for_sftp_users" {
Expand All @@ -208,13 +240,17 @@ resource "aws_iam_role" "s3_access_for_sftp_users" {

assume_role_policy = join("", data.aws_iam_policy_document.assume_role_policy[*].json)
managed_policy_arns = [aws_iam_policy.s3_access_for_sftp_users[index(local.user_names, each.value)].arn]

tags = module.this.tags
}

resource "aws_iam_policy" "logging" {
count = local.enabled ? 1 : 0

name = module.logging_label.id
policy = join("", data.aws_iam_policy_document.logging[*].json)

tags = module.this.tags
}

resource "aws_iam_role" "logging" {
Expand All @@ -223,4 +259,6 @@ resource "aws_iam_role" "logging" {
name = module.logging_label.id
assume_role_policy = join("", data.aws_iam_policy_document.assume_role_policy[*].json)
managed_policy_arns = [join("", aws_iam_policy.logging[*].arn)]

tags = module.this.tags
}
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
output "id" {
description = "ID of the created example"
value = module.this.enabled ? module.this.id : null
description = "The ID of the Transfer Server"
value = module.this.enabled ? join("", aws_transfer_server.default.*.id) : null
}

output "transfer_endpoint" {
Expand Down
Loading