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

Fix sftp users ssh resource, add custom domain tag and more improvments #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 17 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ data "aws_iam_policy_document" "assume_role_policy" {
resource "aws_iam_role" "s3_access_for_sftp_users" {
for_each = var.enabled ? local.user_names_map : {}

name = module.labels.id
name = "${module.labels.id}-${each.value.user_name}"
assume_role_policy = join("", data.aws_iam_policy_document.assume_role_policy[*].json)
managed_policy_arns = [aws_iam_policy.s3_access_for_sftp_users[each.value.user_name].arn]
}

resource "aws_iam_policy" "s3_access_for_sftp_users" {
for_each = var.enabled ? local.user_names_map : {}

name = module.labels.id
name = "${module.labels.id}-${each.value.user_name}"
policy = data.aws_iam_policy_document.s3_access_for_sftp_users[each.value.user_name].json

tags = module.labels.tags
Expand All @@ -149,7 +149,7 @@ resource "aws_iam_policy" "s3_access_for_sftp_users" {
resource "aws_iam_policy" "logging" {
count = var.enabled ? 1 : 0

name = module.labels.id
name = "${module.labels.id}-logging"
policy = join("", data.aws_iam_policy_document.logging[*].json)

tags = module.labels.tags
Expand All @@ -158,7 +158,7 @@ resource "aws_iam_policy" "logging" {
resource "aws_iam_role" "logging" {
count = var.enabled ? 1 : 0

name = module.labels.id
name = "${module.labels.id}-logging"
assume_role_policy = join("", data.aws_iam_policy_document.assume_role_policy[*].json)
managed_policy_arns = [join("", aws_iam_policy.logging[*].arn)]

Expand All @@ -171,7 +171,7 @@ resource "aws_iam_role" "logging" {
##----------------------------------------------------------------------------------

resource "aws_transfer_server" "transfer_server" {
count = var.enable_sftp ? 1 : 0
count = var.enabled ? 1 : 0
identity_provider_type = var.identity_provider_type
protocols = ["SFTP"]
domain = var.domain
Expand Down Expand Up @@ -240,10 +240,10 @@ resource "aws_transfer_user" "transfer_server_user" {
##----------------------------------------------------------------------------------

resource "aws_transfer_ssh_key" "transfer_server_ssh_key" {
count = var.enabled ? length(var.sftp_users) : 0
for_each = var.enabled ? { for user in var.sftp_users : user.user_name => user } : {}
server_id = join("", aws_transfer_server.transfer_server[*].id)
user_name = aws_transfer_user.transfer_server_user[count.index].user_name
body = aws_transfer_user.transfer_server_user[count.index].public_key
user_name = aws_transfer_user.transfer_server_user[each.value.user_name].user_name
body = each.value.public_key
}


Expand All @@ -263,10 +263,17 @@ resource "aws_eip" "sftp" {
# Description : Provides a Custom Domain
##----------------------------------------------------------------------------------

resource "aws_transfer_tag" "custom_hostname" {
count = var.enabled && length(var.custom_domain) > 0 ? 1 : 0
resource_arn = aws_transfer_server.transfer_server[0].arn
key = "aws:transfer:customHostname"
value = var.custom_domain
}

resource "aws_route53_record" "custom_domain" {
count = var.enabled && length(var.domain_name) > 0 && length(var.zone_id) > 0 ? 1 : 0
count = var.enabled && length(var.custom_domain) > 0 && length(var.zone_id) > 0 ? 1 : 0

name = var.domain_name
name = var.custom_domain
zone_id = var.zone_id
type = "CNAME"
ttl = "300"
Expand Down
10 changes: 3 additions & 7 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ variable "enabled" {
#Module : SFTP
#Description : Terraform sftp module variables.
##----------------------------------------------------------------------------------
variable "enable_sftp" {
type = bool
default = true
description = "Set to false to prevent the module from creating any resources."
}

variable "identity_provider_type" {
type = string
Expand Down Expand Up @@ -125,9 +120,9 @@ variable "retention_in_days" {
default = 3
}

variable "domain_name" {
variable "custom_domain" {
type = string
description = "Domain to use when connecting to the SFTP endpoint"
description = "Custom domain to use when connecting to the SFTP endpoint"
default = ""
}

Expand All @@ -151,6 +146,7 @@ variable "workflow_details" {
})
})
description = "Workflow details for triggering the execution on file upload."
default = null
}

variable "enable_workflow" {
Expand Down
Loading