use terranix flake parts module directly
This commit is contained in:
parent
90cdc7b8a5
commit
b75f9752d1
2 changed files with 12 additions and 80 deletions
|
|
@ -1,22 +1,17 @@
|
|||
{ inputs, ... }:
|
||||
|
||||
let
|
||||
lib = inputs.nixpkgs.lib;
|
||||
utils = import ./utils.nix { inherit inputs lib; };
|
||||
inherit (utils) mkTerranixDerivation;
|
||||
{
|
||||
imports = [
|
||||
inputs.terranix.flakeModule
|
||||
];
|
||||
|
||||
configs = {
|
||||
perSystem = {
|
||||
terranix.terranixConfigurations = {
|
||||
# Example:
|
||||
# myconfig = {
|
||||
# modules = [ ./terraform/myconfig.nix ];
|
||||
# extraArgs = { }; # optional
|
||||
# };
|
||||
};
|
||||
in
|
||||
|
||||
{
|
||||
perSystem =
|
||||
{ system, ... }:
|
||||
{
|
||||
packages = mkTerranixDerivation { inherit system configs; };
|
||||
};
|
||||
}
|
||||
|
|
|
|||
63
utils.nix
63
utils.nix
|
|
@ -7,7 +7,6 @@ let
|
|||
nixpkgs-stable
|
||||
home-manager
|
||||
agenix
|
||||
terranix
|
||||
;
|
||||
in
|
||||
|
||||
|
|
@ -191,66 +190,4 @@ in
|
|||
};
|
||||
in
|
||||
lib.mapAttrs (_: lib.recursiveUpdate commonVHostConfig) domains;
|
||||
|
||||
# Terranix configuration system
|
||||
mkTerranixDerivation =
|
||||
{
|
||||
system,
|
||||
configs,
|
||||
}:
|
||||
lib.mapAttrs (
|
||||
name: cfg:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
modules = cfg.modules;
|
||||
extraArgs = cfg.extraArgs or { };
|
||||
|
||||
terraformConfiguration = terranix.lib.terranixConfiguration {
|
||||
inherit system modules;
|
||||
extraArgs = {
|
||||
inherit lib pkgs;
|
||||
} // extraArgs;
|
||||
};
|
||||
|
||||
tf-json = pkgs.writeShellScriptBin "default" ''
|
||||
cat ${terraformConfiguration} | ${pkgs.jq}/bin/jq
|
||||
'';
|
||||
|
||||
apply = pkgs.writeShellScriptBin "apply" ''
|
||||
if [[ -e config.tf.json ]]; then rm -f config.tf.json; fi
|
||||
cp ${terraformConfiguration} config.tf.json \
|
||||
&& ${pkgs.terraform}/bin/terraform init \
|
||||
&& ${pkgs.terraform}/bin/terraform apply
|
||||
'';
|
||||
|
||||
plan = pkgs.writeShellScriptBin "plan" ''
|
||||
if [[ -e config.tf.json ]]; then rm -f config.tf.json; fi
|
||||
cp ${terraformConfiguration} config.tf.json \
|
||||
&& ${pkgs.terraform}/bin/terraform init \
|
||||
&& ${pkgs.terraform}/bin/terraform plan
|
||||
'';
|
||||
|
||||
destroy = pkgs.writeShellScriptBin "destroy" ''
|
||||
if [[ -e config.tf.json ]]; then rm -f config.tf.json; fi
|
||||
cp ${terraformConfiguration} config.tf.json \
|
||||
&& ${pkgs.terraform}/bin/terraform init \
|
||||
&& ${pkgs.terraform}/bin/terraform destroy
|
||||
'';
|
||||
|
||||
create-state-bucket = pkgs.writeShellScriptBin "create-state-bucket" ''
|
||||
BUCKET_NAME=''${1:-"terraform-state-bucket"}
|
||||
ACCOUNT_ID=''${2:?"Error: Cloudflare account ID required as second argument"}
|
||||
R2_ENDPOINT="https://$ACCOUNT_ID.r2.cloudflarestorage.com"
|
||||
|
||||
echo "Creating R2 bucket $BUCKET_NAME..."
|
||||
${pkgs.awscli}/bin/aws s3api create-bucket \
|
||||
--bucket "$BUCKET_NAME" \
|
||||
--endpoint-url "$R2_ENDPOINT"
|
||||
echo "Bucket created successfully at $R2_ENDPOINT"
|
||||
'';
|
||||
in
|
||||
tf-json // {
|
||||
inherit apply plan destroy create-state-bucket;
|
||||
}
|
||||
) configs;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue