Skip to content

Commit

Permalink
AZURE: start support
Browse files Browse the repository at this point in the history
  • Loading branch information
zbioe committed Aug 18, 2022
1 parent fd6cb61 commit b4f6cbb
Show file tree
Hide file tree
Showing 5 changed files with 363 additions and 29 deletions.
22 changes: 20 additions & 2 deletions devShell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ let
build-gce = writeScriptBin "build-gce" ''
build gce
'';
build-azure = writeScriptBin "build-azure" ''
build azure
'';

# Apply using terraform
apply = writeScriptBin "apply" ''
Expand All @@ -31,6 +34,9 @@ let
apply-gcp = writeScriptBin "apply-gcp" ''
apply gcp
'';
apply-azure = writeScriptBin "apply-azure" ''
apply azure
'';

# Destroy using terraform
destroy = writeScriptBin "destroy" ''
Expand All @@ -44,6 +50,9 @@ let
destroy-gcp = writeScriptBin "destroy-gcp" ''
destroy gcp
'';
destroy-azure = writeScriptBin "destroy-azure" ''
destroy azure
'';

# Deploy nix using colmena
deploy = writeScriptBin "deploy" ''
Expand All @@ -56,6 +65,9 @@ let
deploy-gcp = writeScriptBin "deploy-gcp" ''
deploy gcp
'';
deploy-azure = writeScriptBin "deploy-azure" ''
deploy azure
'';

# Clean SSH authorized keys
clean-ssh = writeScriptBin "clean-ssh" ''
Expand All @@ -69,43 +81,49 @@ let
clean-ssh-gcp = writeScriptBin "clean-ssh-gcp" ''
nix run .#clean-ssh-gcp
'';
clean-ssh-azure = writeScriptBin "clean-ssh-azure" ''
nix run .#clean-ssh-azure
'';

# Up and Running local vault using docker-compose by arion
local-vault = writeScriptBin "local-vault" ''
nix run .#local-vault
'';

# Up and running local k8s using k3d
local-k8s = writeScriptBin "local-k8s" ''
nix run .#local-k8s
'';

in mkShell {
packages = [
# build images
build
build-qcow
build-gce
build-azure

# provision apply
apply
apply-libvirt
apply-gcp
apply-azure

# provision destroy
destroy
destroy-libvirt
destroy-gcp
destroy-azure

# deploy nix
deploy
deploy-libvirt
deploy-gcp
deploy-azure

# clean ssh authorized keys
clean-ssh
clean-ssh-libvirt
clean-ssh-gcp
clean-ssh-azure

# start local vault
local-vault
Expand Down
57 changes: 57 additions & 0 deletions env/azure/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{ config, lib, pkgs, ... }: {
provision.azure = {
enable = true;
project = "bornlogic-consul";

# images = {
# nixos = {
# location = "US";
# source = toString
# ../../images/gce/nixos-image-22.05.20220728.9370544-x86_64-linux.raw.tar.gz;
# };
# };

# networks = {
# prod = { description = "production network"; };
# stag = { description = "staging network"; };

# test = {
# description = "testing network";
# subnetworks = {
# n1 = {
# cidr_range = "10.3.0.0/16";
# description = "n1 network";
# secondary_ranges = [{
# range_name = "test-second-range";
# cidr_range = "10.4.0.0/16";
# }];
# };
# };
# };
# };

# replicas = {
# c2r1 = {
# tags = [ "consul" "server" "nixos" "test" ];
# network = "test";
# subnetwork = "n1";
# machine_type = "e2-medium";
# zone = "us-east1-b";
# };
# c2r2 = {
# tags = [ "consul" "server" "nixos" "test" ];
# network = "test";
# subnetwork = "n1";
# machine_type = "e2-medium";
# zone = "us-east1-c";
# };
# c2r3 = {
# tags = [ "consul" "server" "nixos" "test" ];
# network = "test";
# subnetwork = "n1";
# machine_type = "e2-medium";
# zone = "us-east1-d";
# };
# };
};
}
87 changes: 60 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

libvirtConfig = genConfig "libvirt";
gcpConfig = genConfig "gcp";
azureConfig = genConfig "azure";
in {
# overlay
overlays = import ./overlays;
Expand All @@ -55,91 +56,97 @@
];
format = "gce";
};
# nix build .#azure
azure = nixos-generators.nixosGenerate {
inherit pkgs;
modules = [
# minimal gcp
./generators/minimal-azure.nix
];
format = "azure";
};
};
devShells.${system}.default = self.packages.${system}.devShell;

# Apps
apps.${system} = {

# nix run
default = self.apps.${system}.apply;
# nix run ".#apply"
# defaults to libvirt
apply = self.apps.${system}.apply-libvirt;

# nix run ".#apply-libvirt"
apply-libvirt = {
type = "app";
program = toString (pkgs.writers.writeBash "apply-libvirt" ''
scripts/terranix-apply.sh "libvirt" ${libvirtConfig}
'');
};

# nix run ".#apply-gcp"
apply-gcp = {
type = "app";
program = toString (pkgs.writers.writeBash "apply-gcp" ''
scripts/terranix-apply.sh "gcp" ${gcpConfig}
'');
};

# nix run ".#local-vault"
local-vault = {
type = "app";
program = toString (pkgs.writers.writeBash "local-vault" ''
set -euo pipefail
cd arion/
arion up
'');
};

# nix run ".#local-k8s"
local-k8s = {
# nix run ".#apply-azure"
apply-azure = {
type = "app";
program = toString (pkgs.writers.writeBash "local-k8s" ''
set -euo pipefail
scripts/k8s/local-k8s.sh
# scripts/k8s/configure.sh
program = toString (pkgs.writers.writeBash "apply-azure" ''
scripts/terranix-apply.sh "azure" ${azureConfig}
'');
};

# nix run ".#destroy"
# defaults to libvirt
destroy = self.apps.${system}.destroy-libvirt;

# nix run ".#destroy-libvirt"
destroy-libvirt = {
type = "app";
program = toString (pkgs.writers.writeBash "destroy-libvirt" ''
scripts/terranix-destroy.sh "libvirt" ${libvirtConfig}
'');
};

# nix run ".#destroy-gcp
destroy-gcp = {
type = "app";
program = toString (pkgs.writers.writeBash "destroy-gcp" ''
scripts/terranix-destroy.sh "gcp" ${gcpConfig}
'');
};
# nix run ".#destroy-azure
destroy-azure = {
type = "app";
program = toString (pkgs.writers.writeBash "destroy-azure" ''
scripts/terranix-destroy.sh "azure" ${gcpConfig}
'');
};

# nix run ".#clean-ssh"
# defaults to libvirt
clean-ssh = self.apps.${system}.clean-ssh-libvirt.program;

# nix run ".#clean-ssh-libvirt"
clean-ssh-libvirt = {
type = "app";
program = toString (pkgs.writers.writeBash "clean-ssh-libvirt" ''
./scripts/clean-ssh.sh libvirt
'');
};

# nix run ".#clean-ssh-gcp"
clean-ssh-gcp = {
type = "app";
program = toString (pkgs.writers.writeBash "clean-ssh-gcp" ''
./scripts/clean-ssh.sh gcp
'');
};
# nix run ".#clean-ssh-azure"
clean-ssh-azure = {
type = "app";
program = toString (pkgs.writers.writeBash "clean-ssh-azure" ''
./scripts/clean-ssh.sh azure
'');
};

# nix run ".#deploy"
# defaults to libvirt
deploy = {
Expand All @@ -164,8 +171,34 @@
${pkgs.colmena}/bin/colmena apply --on @gcp
'');
};
# nix run
default = self.apps.${system}.apply;
# nix run ".#deploy-azure"
deploy-azure = {
type = "app";
program = toString (pkgs.writers.writeBash "deploy-azure" ''
set -euo pipefail
./scripts/clean-ssh.sh gcp
${pkgs.colmena}/bin/colmena apply --on @azure
'');
};

# nix run ".#local-vault"
local-vault = {
type = "app";
program = toString (pkgs.writers.writeBash "local-vault" ''
set -euo pipefail
cd arion/
arion up
'');
};
# nix run ".#local-k8s"
local-k8s = {
type = "app";
program = toString (pkgs.writers.writeBash "local-k8s" ''
set -euo pipefail
scripts/k8s/local-k8s.sh
# scripts/k8s/configure.sh
'');
};
};

# deploy
Expand All @@ -191,6 +224,6 @@
in {
meta = { nixpkgs = pkgs; };
defaults = import ./deploys/consul;
} // (genOutput "libvirt") // (genOutput "gcp");
} // (genOutput "libvirt") // (genOutput "gcp") // (genOutput "azure");
};
}
4 changes: 4 additions & 0 deletions generators/minimal-azure.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ modulesPath, ... }: {
imports =
[ "${modulesPath}/virtualisation/azure-config.nix" ./minimal-default.nix ];
}
Loading

0 comments on commit b4f6cbb

Please sign in to comment.