Skip to content

Commit

Permalink
Merge pull request #85 from serokell/sereja/refactor-instances
Browse files Browse the repository at this point in the history
[Chore] Refactor aws instances and hcloud servers
  • Loading branch information
Sereja313 authored Apr 19, 2023
2 parents 332f320 + 5e19296 commit b47f28e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 35 deletions.
2 changes: 1 addition & 1 deletion terraform/alhena.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs, lib, ... }:
let
inherit (import ./common.nix) mkAWS;
inherit (import ./common.nix pkgs) mkAWS;
inherit (pkgs.lib) mkAddressRecords;
in {
resource.aws_instance.alhena = mkAWS {
Expand Down
2 changes: 1 addition & 1 deletion terraform/castor.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs, lib, ... }:
let
inherit (import ./common.nix) mkAWS;
inherit (import ./common.nix pkgs) mkAWS;
inherit (pkgs.lib) mkAddressRecords;
in {
resource.aws_instance.castor = mkAWS {
Expand Down
39 changes: 10 additions & 29 deletions terraform/common.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
{
mkAWS = let
security-group = [
"\${aws_security_group.egress_all.id}"
"\${aws_security_group.http.id}"
"\${aws_security_group.ssh.id}"
"\${aws_security_group.wireguard.id}"
]; in {key_name, volume_size, tags, vpc_security_group_ids ? security-group}: {
# Networking
availability_zone = "\${module.vpc.azs[2]}";
subnet_id = "\${module.vpc.public_subnets[2]}";
associate_public_ip_address = true;
inherit key_name tags vpc_security_group_ids;
{ pkgs, ... }:
let
inherit (pkgs.lib) mkAWS mkHcloud;
in {
mkAWS = {key_name, volume_size, tags, vpc_security_group_ids ? null}@args: mkAWS ({
availability_zone = "\${module.vpc.azs[2]}";
subnet_id = "\${module.vpc.public_subnets[2]}";
instance_type = "t3a.micro";
} // args);

# Instance parameters
instance_type = "t3a.micro";
monitoring = true;

# Disk type, size, and contents
lifecycle.ignore_changes = [ "ami" ];
ami = "\${data.aws_ami.nixos.id}";
root_block_device = {
volume_type = "gp2";
inherit volume_size;
};
};

mkHcloud = {name, ssh_keys}: {
mkHcloud = {name, ssh_keys}: mkHcloud {
inherit name ssh_keys;
image = "ubuntu-20.04";
server_type = "cx11";
lifecycle.ignore_changes = [ "user_data" ];
# Install NixOS 20.09
user_data = ''
#cloud-config
Expand Down
2 changes: 1 addition & 1 deletion terraform/jishui.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs, lib, ... }:
let
inherit (import ./common.nix) mkAWS;
inherit (import ./common.nix pkgs) mkAWS;
inherit (pkgs.lib) mkAddressRecords;
in {
resource.aws_instance.jishui = mkAWS {
Expand Down
2 changes: 1 addition & 1 deletion terraform/mebsuta.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs, lib, ... }:
let
inherit (import ./common.nix) mkHcloud;
inherit (import ./common.nix pkgs) mkHcloud;
inherit (pkgs.lib) mkAddressRecords;
in {
resource.hcloud_server.mebsuta = mkHcloud {
Expand Down
2 changes: 1 addition & 1 deletion terraform/tejat-prior.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs, lib, ... }:
let
inherit (import ./common.nix) mkAWS;
inherit (import ./common.nix pkgs) mkAWS;
inherit (pkgs.lib) mkAddressRecords;
in {
resource.aws_instance.tejat-prior = mkAWS {
Expand Down
2 changes: 1 addition & 1 deletion terraform/wasat.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs, lib, ... }:
let
inherit (import ./common.nix) mkHcloud;
inherit (import ./common.nix pkgs) mkHcloud;
inherit (pkgs.lib) mkAddressRecords;
in {
resource.hcloud_server.wasat = mkHcloud {
Expand Down

0 comments on commit b47f28e

Please sign in to comment.