Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update Terraform example and template #1249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/terraform/.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
set -ex
terraform --version | grep "1.5.6"
terraform --version | grep "1.8.4"
5 changes: 1 addition & 4 deletions examples/terraform/devenv.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{ pkgs, ... }:

{
# For versions >= 1.6.0 open a shell by running the following command:
#
# env NIXPKGS_ALLOW_UNFREE=1 devenv --impure shell
Copy link
Contributor Author

@sestrella sestrella Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer an issue with the latest version of nixpkgs-terraform

languages.terraform = {
enable = true;
version = "1.5.6";
version = "1.8.4";
};
}
5 changes: 2 additions & 3 deletions templates/terraform/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

nix_direnv_watch_file devenv.nix
nix_direnv_watch_file devenv.lock
nix_direnv_watch_file devenv.yaml
nix_direnv_watch_file flake.nix
nix_direnv_watch_file flake.lock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating this file based on the simple template.

if ! use flake . --impure
then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
Expand Down
45 changes: 28 additions & 17 deletions templates/terraform/flake.nix
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
{
inputs = {
devenv.inputs.nixpkgs.follows = "nixpkgs";
devenv.url = "github:cachix/devenv";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/nixos-23.05";
nixpkgs-terraform.url = "github:stackbuilders/nixpkgs-terraform";
nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
systems.url = "github:nix-systems/default";
};

outputs = { self, devenv, flake-utils, nixpkgs }@inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [{
env.AWS_PROFILE = "<profile>";
nixConfig = {
extra-substituters = "https://devenv.cachix.org https://nixpkgs-terraform.cachix.org";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding nixpkgs-terraform cache to improve the user experience.

extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw= nixpkgs-terraform.cachix.org-1:8Sit092rIdAVENA3ZVeH9hzSiqI/jng6JiCrQ1Dmusw=";
};

languages.terraform.enable = true;
outputs = { self, devenv, nixpkgs, systems, ... }@inputs:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
devShells = forEachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [{
languages.terraform.enable = true;
languages.terraform.version = "1.8.4";

pre-commit.hooks.terraform-format.enable = true;
}];
};
});
pre-commit.hooks.terraform-format.enable = true;
}];
};
});
};
}