diff options
| author | Franck Cuny <franck@fcuny.net> | 2025-07-07 16:04:59 -0700 |
|---|---|---|
| committer | Franck Cuny <franck@fcuny.net> | 2025-07-07 16:04:59 -0700 |
| commit | f83e36ca1aab723276193eb29a47bd9d59abb1df (patch) | |
| tree | 5cb60fc4b8519ca4911b730044e53e8e5d4e8323 /nix/scripts/common.nix | |
| parent | move scripts managed by nix out of the flake (diff) | |
| download | infra-f83e36ca1aab723276193eb29a47bd9d59abb1df.tar.gz | |
add scripts related to terraform
Diffstat (limited to '')
| -rw-r--r-- | nix/scripts/common.nix | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/nix/scripts/common.nix b/nix/scripts/common.nix index 931480c..6aa73c2 100644 --- a/nix/scripts/common.nix +++ b/nix/scripts/common.nix @@ -1,4 +1,42 @@ { pkgs }: [ (pkgs.writeScriptBin "update-deps" "nix flake update --commit-lock-file") + + (pkgs.writeShellScriptBin "gcloud-auth" '' + set -xeuo pipefail + ${pkgs.google-cloud-sdk}/bin/gcloud auth print-identity-token > /dev/null 2>&1 || \ + ${pkgs.google-cloud-sdk}/bin/gcloud auth login --quiet + ${pkgs.google-cloud-sdk}/bin/gcloud auth application-default print-access-token > /dev/null 2>&1 || \ + ${pkgs.google-cloud-sdk}/bin/gcloud auth application-default login --quiet + '') + + (pkgs.writeShellScriptBin "tofu-apply" '' + set -xeuo pipefail + ${pkgs.google-cloud-sdk}/bin/gcloud storage buckets describe \ + gs://fcuny-infra-tofu-state \ + --project=fcuny-infra \ + --quiet || \ + ${pkgs.google-cloud-sdk}/bin/gcloud storage buckets create \ + gs://fcuny-infra-tofu-state \ + --project=fcuny-infra \ + --uniform-bucket-level-access \ + --public-access-prevention \ + --location=us-west1 \ + --default-storage-class=STANDARD \ + --quiet + + TMPDIR=$(mktemp -d) + trap 'rm -rf "$TMPDIR"' EXIT + + ${pkgs.coreutils}/bin/install -Dm 0644 ${ + import ../tofu/backups.nix { + inherit + pkgs + ; + } + } "$TMPDIR/backups/backups.tf.json" + + ${pkgs.opentofu}/bin/tofu -chdir="$TMPDIR/backups" init + ${pkgs.opentofu}/bin/tofu -chdir="$TMPDIR/backups" apply -auto-approve + '') ] |
