generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DSOS-2749: windows fsx module (#5865)
* add DC secret * fsx_windows module * add fsx to baseline * test fsx in ndh * fix * fix * test for FSX * add skip_final_backup * bodge * fix * undo bodge * fsx test * fix * fix * fs test * fix * fix * test * fix * README * fix * remove test fs * readme * remove from ndh * fix
- Loading branch information
1 parent
d2e6104
commit cb56db8
Showing
13 changed files
with
423 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
locals { | ||
# lookup kms_key_ids, subnet ids and lookup security group ids | ||
fsx_windows = { | ||
for key, value in var.fsx_windows : key => merge(value, { | ||
kms_key_id = try(var.environment.kms_keys[value.kms_key_id].arn, value.kms_key_id) | ||
preferred_subnet_id = value.preferred_availability_zone != null ? var.environment.subnet[value.preferred_subnet_name][value.preferred_availability_zone].id : null | ||
subnet_ids = flatten([ | ||
for subnet in value.subnets : [ | ||
for az in subnet.availability_zones : [ | ||
var.environment.subnet[subnet.name][az].id | ||
] | ||
] | ||
]) | ||
security_group_ids = [for sg in value.security_groups : try(aws_security_group.this[sg].id, sg)] | ||
}) | ||
} | ||
} | ||
|
||
module "fsx_windows" { | ||
for_each = local.fsx_windows | ||
|
||
source = "../../modules/fsx_windows" | ||
|
||
name = each.key | ||
active_directory_id = each.value.active_directory_id | ||
automatic_backup_retention_days = each.value.automatic_backup_retention_days | ||
backup_id = each.value.backup_id | ||
daily_automatic_backup_start_time = each.value.daily_automatic_backup_start_time | ||
deployment_type = each.value.deployment_type | ||
kms_key_id = each.value.kms_key_id | ||
preferred_subnet_id = each.value.preferred_subnet_id | ||
security_group_ids = each.value.security_group_ids | ||
self_managed_active_directory = each.value.self_managed_active_directory | ||
skip_final_backup = each.value.skip_final_backup | ||
storage_capacity = each.value.storage_capacity | ||
storage_type = each.value.storage_type | ||
subnet_ids = each.value.subnet_ids | ||
throughput_capacity = each.value.throughput_capacity | ||
weekly_maintenance_start_time = each.value.weekly_maintenance_start_time | ||
|
||
tags = merge(local.tags, each.value.tags) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# FSX Windows File System Module | ||
|
||
Pretty much a straight wrapper for the fsx resource but retrieves credentials for domain join. | ||
|
||
## Example Usage | ||
|
||
See https://github.com/ministryofjustice/modernisation-platform-configuration-management repo | ||
for ansible code for mounting on linux server (filesystems role). | ||
|
||
If joining on Windows server, example powershell: | ||
``` | ||
NB: if manually testing, don't run this command under Administrator. | ||
New-PSDrive -Name "D" -PSProvider "FileSystem" -Root "\\amznfsxf09lugmi.azure.noms.root\share" -Persist -Scope Global | ||
``` | ||
|
||
NOTES: | ||
- Use Single-AZ solution for non-production environments to save cost. | ||
- Multi-AZ can only include 2 availability zones. | ||
- Set `skip_final_backup true` to avoid issues deleting the resource | ||
|
||
## Security Groups | ||
|
||
The module does not create security groups. Unlike EFS, there is | ||
authentication, but still good practice to limit network access. | ||
|
||
### Example 1 - Same security group as EC2 | ||
|
||
Use the same security group as the EC2 mounting the Windows File System. | ||
Just ensure there is an internal rule allowing internal traffic | ||
like this: | ||
|
||
``` | ||
resource "aws_security_group_rule" "all_from_self" { | ||
security_group_id = aws_security_group.ec2.id | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = -1 | ||
self = true | ||
} | ||
``` | ||
|
||
### Example 2 - Separate security group | ||
|
||
Create a separate security group and allow inbound traffic | ||
only from the security groups that the EC2s belong to. | ||
|
||
``` | ||
resource "aws_security_group" "fsx" { | ||
name = "fsx" | ||
vpc_id = data.aws_vpc.shared.id | ||
} | ||
resource "aws_security_group_rule" "fsx_ingress" { | ||
security_group_id = aws_security_group.fsx.id | ||
type = "ingress" | ||
from_port = 445 | ||
to_port = 445 | ||
protocol = "tcp" | ||
source_security_group_id = aws_security_group.ec2.id | ||
} | ||
``` | ||
|
||
## Multi-AZ example | ||
|
||
This: | ||
- creates multi-AZ solution with mount points in eu-west-2a and eu-west-2b | ||
- joins on-prem AD | ||
- associates the mount point with a `aws_security_group.ec2` resource, see Security Groups - Example 1 | ||
|
||
``` | ||
module "fsx_windows1" { | ||
source = "../../modules/fsx_windows" | ||
preferred_subnet_id = data.aws_subnet.private_subnets_a.id | ||
deployment_type = "MULTI_AZ_1" | ||
name = "fsx_windows1" | ||
security_groups = [aws_security_group.ec2.id] | ||
skip_final_backup = true | ||
storage_capacity = 32 | ||
throughput_capacity = 8 | ||
subnet_ids = [ | ||
data.aws_subnet.private_subnets_a.id, | ||
data.aws_subnet.private_subnets_b.id | ||
] | ||
self_managed_active_directory = { | ||
dns_ips = [ | ||
module.ip_addresses.mp_ip.ad-azure-dc-a, | ||
module.ip_addresses.mp_ip.ad-azure-dc-b, | ||
] | ||
domain_name = "azure.noms.root" | ||
username = "svc_join_domain" | ||
password_secret_name = "/microsoft/AD/azure.noms.root/shared-passwords" | ||
} | ||
tags = local.tags | ||
} | ||
output "fsx_windows1_dns_name" { | ||
description = "FSX Windows DNS name" | ||
value = module.fsx_windows1.windows_file_system.dns_name | ||
} | ||
``` | ||
|
||
## Single-AZ example | ||
|
||
This: | ||
- creates single-AZ solution with mount points in zone A only | ||
- joins existing AWS AD (created outside of this module) | ||
|
||
``` | ||
module "fsx_windows2" { | ||
source = "../../modules/fsx_windows" | ||
active_directory_id = aws_directory_service_directory.this.id | ||
deployment_type = "SINGLE_AZ_1" | ||
name = "fsx_windows2" | ||
security_groups = ["aws_security_group.fsx.id"] | ||
skip_final_backup = true | ||
storage_capacity = 32 | ||
subnet_ids = [ data.aws_subnet.private_subnets_a.id] | ||
throughput_capacity = 8 | ||
tags = local.tags | ||
} | ||
output "fsx_windows2_dns_name" { | ||
description = "FSX Windows DNS name" | ||
value = module.fsx_windows2.windows_file_system.dns_name | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
data "aws_secretsmanager_secret" "this" { | ||
count = try(var.self_managed_active_directory, null) != null ? 1 : 0 | ||
|
||
name = var.self_managed_active_directory.password_secret_name | ||
} | ||
|
||
data "aws_secretsmanager_secret_version" "this" { | ||
count = length(data.aws_secretsmanager_secret.this) != 0 ? 1 : 0 | ||
secret_id = data.aws_secretsmanager_secret.this[0].id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
locals { | ||
# expecting the secret to be json key/pair with username as key, e.g. `{"svc_join_domain":"mypassword"}` | ||
domain_join_secret_string = var.self_managed_active_directory != null ? data.aws_secretsmanager_secret_version.this[0].secret_string : null | ||
domain_join_secret_json = var.self_managed_active_directory != null ? jsondecode(local.domain_join_secret_string) : null | ||
domain_join_password = var.self_managed_active_directory != null ? local.domain_join_secret_json[var.self_managed_active_directory.username] : null | ||
} |
Oops, something went wrong.