54 lines
1.7 KiB
Nix
54 lines
1.7 KiB
Nix
|
{
|
||
|
inputs = {
|
||
|
nixpkgs.url = "github:nixos/nixpkgs";
|
||
|
flake-utils.url = "github:numtide/flake-utils";
|
||
|
terranix = {
|
||
|
url = "github:terranix/terranix";
|
||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||
|
};
|
||
|
};
|
||
|
|
||
|
outputs = { self, nixpkgs, flake-utils, terranix }:
|
||
|
flake-utils.lib.eachDefaultSystem (system:
|
||
|
let
|
||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||
|
terraform = pkgs.terraform_0_15;
|
||
|
terraformConfiguration = terranix.lib.terranixConfiguration {
|
||
|
inherit system;
|
||
|
modules = [ ./config.nix ];
|
||
|
};
|
||
|
in
|
||
|
{
|
||
|
defaultPackage = terraformConfiguration;
|
||
|
# nix develop
|
||
|
devShell = pkgs.mkShell {
|
||
|
buildInputs = [
|
||
|
pkgs.terraform_0_15
|
||
|
terranix.defaultPackage.${system}
|
||
|
];
|
||
|
};
|
||
|
# nix run ".#apply"
|
||
|
apps.apply = {
|
||
|
type = "app";
|
||
|
program = toString (pkgs.writers.writeBash "apply" ''
|
||
|
if [[ -e config.tf.json ]]; then rm -f config.tf.json; fi
|
||
|
cp ${terraformConfiguration} config.tf.json \
|
||
|
&& ${terraform}/bin/terraform init \
|
||
|
&& ${terraform}/bin/terraform apply
|
||
|
'');
|
||
|
};
|
||
|
# nix run ".#destroy"
|
||
|
apps.destroy = {
|
||
|
type = "app";
|
||
|
program = toString (pkgs.writers.writeBash "destroy" ''
|
||
|
if [[ -e config.tf.json ]]; then rm -f config.tf.json; fi
|
||
|
cp ${terraformConfiguration} config.tf.json \
|
||
|
&& ${terraform}/bin/terraform init \
|
||
|
&& ${terraform}/bin/terraform destroy
|
||
|
'');
|
||
|
};
|
||
|
# nix run
|
||
|
defaultApp = self.apps.${system}.apply;
|
||
|
});
|
||
|
}
|