Skip to content

Commit c97052e

Browse files
Add Northeastern University tags to AWS resources
1 parent c754df8 commit c97052e

9 files changed

Lines changed: 70 additions & 17 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ on:
1212

1313
concurrency:
1414
group: infra-${{ github.ref }}
15-
cancel-in-progress: true
15+
# Cancelling terraform deployments will screw up terraform's own locking mechanism
16+
cancel-in-progress: false
1617

1718
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1819
jobs:

terraform/auth.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
username_attributes = [ "email" ];
88
auto_verified_attributes = [ "email" ];
99
admin_create_user_config.allow_admin_create_user_only = true;
10+
tags = config.setup.global_tags;
1011
};
1112

1213
aws_cognito_user_pool_client.main = {

terraform/bootstrap.nix

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ with lib; {
55
bucket = mkOption { type = str; };
66
table = mkOption { type = str; };
77
};
8-
stage = mkOption { type = str; };
8+
stage = mkOption { type = enum [ "dev" "prod" ]; };
99
vpc = mkOption { type = str; };
1010
subnets = mkOption { type = attrsOf str; };
11+
global_tags = mkOption {
12+
type = attrsOf str;
13+
default = { };
14+
};
1115
};
1216

1317
config = {
@@ -22,7 +26,7 @@ with lib; {
2226
sse_algorithm = "AES256";
2327
};
2428
versioning.enabled = true;
25-
tags."Terraform" = "true";
29+
tags = { "Terraform" = "true"; } // config.setup.global_tags;
2630
lifecycle.prevent_destroy = true;
2731
};
2832

@@ -39,7 +43,7 @@ with lib; {
3943
tags = {
4044
Name = config.setup.state.table;
4145
BuiltBy = "Terraform";
42-
};
46+
} // config.setup.global_tags;
4347
lifecycle.prevent_destroy = true;
4448
};
4549

terraform/database-nixos.nix

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ in {
2626
type = listOf attrs;
2727
default = [ ];
2828
};
29+
instance_tags = mkOption {
30+
type = attrsOf str;
31+
default = { };
32+
};
33+
storage_tags = mkOption {
34+
type = attrsOf str;
35+
default = { };
36+
};
2937
};
3038

3139
config.resource = let
@@ -39,7 +47,9 @@ in {
3947
volume.iops
4048
else
4149
null;
42-
tags = { Name = "dailp-${toKebabCase volume.name}"; };
50+
tags = {
51+
Name = "dailp-${toKebabCase volume.name}";
52+
} // config.setup.global_tags // config.servers.mongodb.storage_tags;
4353
lifecycle.prevent_destroy = true;
4454
};
4555

@@ -67,7 +77,10 @@ in {
6777
volume_size = root_volume_size;
6878
volume_type = "gp3";
6979
};
70-
tags = { Name = "dailp-${toKebabCase name}"; };
80+
tags = {
81+
Name = "dailp-${toKebabCase name}";
82+
} // config.setup.global_tags
83+
// config.servers.mongodb.instance_tags;
7184
lifecycle.prevent_destroy = true;
7285
};
7386

@@ -244,9 +257,11 @@ in {
244257
target_host = "\${aws_instance.${name}.public_ip}";
245258
ssh_agent = false;
246259
ssh_private_key = getEnv "AWS_SSH_KEY";
247-
arguments = mkMerge ([{ primaryAddress = primaryIp; }]
248-
++ (imap0 (i: addr: { "secondary${toString i}Address" = addr; })
249-
secondaryAddrs));
260+
arguments = mkMerge ([{
261+
hostName = config.resource.aws_instance."${name}".tags.Name;
262+
primaryAddress = primaryIp;
263+
}] ++ (imap0 (i: addr: { "secondary${toString i}Address" = addr; })
264+
secondaryAddrs));
250265
# extra_eval_args = [
251266
# # HACK: Force the deployment to wait for all volumes to be attached
252267
# # first. This helps prevent wonky MongoDB logging errors.

terraform/functions.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ let
5151
security_group_ids = config.functions.security_group_ids;
5252
};
5353
environment.variables = env;
54+
tags = config.setup.global_tags // config.functions.tags;
5455
};
5556
aws_lambda_permission."${id}" = {
5657
statement_id = "AllowAPIGatewayInvoke";
@@ -73,6 +74,10 @@ in {
7374
security_group_ids = mkOption { type = listOf str; };
7475
package_path = mkOption { type = str; };
7576
functions = mkOption { type = listOf attrs; };
77+
tags = mkOption {
78+
type = attrsOf str;
79+
default = { };
80+
};
7681
};
7782

7883
config.resource = mkMerge (map mkLambda config.functions.functions);

terraform/main.nix

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ in {
2121
./database-nixos.nix
2222
./auth.nix
2323
./website.nix
24+
./nu-tags.nix
2425
];
2526

2627
# Gives all modules access to which stage we're deploying to, while also
@@ -35,14 +36,13 @@ in {
3536
version = "~> 3.44";
3637
};
3738

38-
# Setup the S3 bucket and DynamoDB table that store and manage Terraform state
39-
# for the current environment.
40-
setup.state = {
41-
bucket = "dailp-${config.setup.stage}-terraform-state-bucket";
42-
table = "dailp-${config.setup.stage}-terraform-state-locks";
43-
};
44-
4539
setup = {
40+
# Setup the S3 bucket and DynamoDB table that store and manage Terraform state
41+
# for the current environment.
42+
state = {
43+
bucket = "dailp-${config.setup.stage}-terraform-state-bucket";
44+
table = "dailp-${config.setup.stage}-terraform-state-locks";
45+
};
4646
vpc = getEnv "AWS_VPC_ID";
4747
subnets = {
4848
primary = getEnv "AWS_SUBNET_PRIMARY";

terraform/mongodb-configuration.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#
1212
# The secondary benefit is that you guard the `nixpkgs` you use, with
1313
# an integrity hash.
14-
{ primaryAddress, secondary0Address ? null, secondary1Address ? null, ... }:
14+
{ hostName, primaryAddress, secondary0Address ? null, secondary1Address ? null
15+
, ... }:
1516
let
1617
nixpkgs = let
1718
rev = "cd63096d6d887d689543a0b97743d28995bc9bc3";
@@ -28,6 +29,7 @@ in import "${nixpkgs}/nixos" {
2829

2930
ec2.hvm = true;
3031

32+
networking.hostName = hostName;
3133
# Only allow SSH and certain MongoDB ports.
3234
networking.firewall.allowedTCPPorts = [ 22 27017 27030 ];
3335

terraform/nu-tags.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ config, lib, pkgs, ... }:
2+
3+
{
4+
setup.global_tags = {
5+
# Placeholder values, these should be sourced from secrets.
6+
"nu:account-code" = "0000000";
7+
"nu:index-division" = "0000000";
8+
"nu:owner" = "dsg";
9+
"nu:creator" = "dailp-deployment";
10+
"nu:environment" =
11+
if config.setup.stage == "dev" then "library-dev" else "library-prod";
12+
"nu:application" = "dailp";
13+
};
14+
servers.mongodb.instance_tags = {
15+
"nu:function" = "database";
16+
"nu:os" = "nixos";
17+
"nu:backups" = "no";
18+
};
19+
servers.mongodb.storage_tags = {
20+
"nu:function" = "database";
21+
"nu:backups" = "no";
22+
};
23+
functions.tags = { "nu:function" = "application-server"; };
24+
}

terraform/website.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ with builtins; {
3030
in {
3131
lifecycle.prevent_destroy = true;
3232
name = "dailp";
33+
tags = config.setup.global_tags;
3334
description =
3435
"Digital Archive of American Indian Languages Preservation and Perseverance";
3536
repository = lib.toLower (getEnv "GIT_REPOSITORY_URL");

0 commit comments

Comments
 (0)