|
3 | 3 | [](https://github.com/stackbuilders/nixpkgs-terraform/actions/workflows/ci.yml)
|
4 | 4 | [](https://github.com/stackbuilders/nixpkgs-terraform/actions/workflows/update.yml)
|
5 | 5 |
|
6 |
| -## Available Versions |
| 6 | +A collection of Terraform versions that are automatically updated. |
7 | 7 |
|
8 |
| -Terraform versions greater than 1.5.0 are kept up to date via a weekly |
9 |
| -scheduled [CI workflow](.github/workflows/update.yaml). |
| 8 | +## How it works |
10 | 9 |
|
11 |
| -## Inspired By |
| 10 | +This flake provides a set of Terraform versions in the form of: |
| 11 | + |
| 12 | +```nix |
| 13 | +nixpkgs-terraform.packages.${system}.${version} |
| 14 | +``` |
| 15 | + |
| 16 | +Terraform versions >= 1.5.0 are kept up to date via a weekly scheduled [CI |
| 17 | +workflow](.github/workflows/update.yml). |
12 | 18 |
|
13 | 19 | The current project structure as well as some components of the CI workflow are
|
14 | 20 | heavily inspired by the following projects:
|
15 | 21 |
|
16 | 22 | - [nixpkgs-python](https://github.com/cachix/nixpkgs-python)
|
17 | 23 | - [nixpkgs-ruby](https://github.com/bobvanderlinden/nixpkgs-ruby)
|
| 24 | + |
| 25 | +## Install |
| 26 | + |
| 27 | +The quickest way to get started with an empty project is to scaffold a new |
| 28 | +project using the [default](templates/default) template: |
| 29 | + |
| 30 | +```sh |
| 31 | +nix flake init -t github:stackbuilders/nixpkgs-terraform |
| 32 | +``` |
| 33 | + |
| 34 | +Alternatively, add the following input to an existing `flake.nix` file: |
| 35 | + |
| 36 | +```nix |
| 37 | +inputs.nixpkgs-terraform.url = "github:stackbuilders/nixpkgs-terraform"; |
| 38 | +``` |
| 39 | + |
| 40 | +Some extra inputs are required for the example provided in the [Usage](#usage) |
| 41 | +section: |
| 42 | + |
| 43 | +```nix |
| 44 | +inputs.flake-utils.url = "github:numtide/flake-utils"; |
| 45 | +inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; |
| 46 | +``` |
| 47 | + |
| 48 | +**Binary Cache** |
| 49 | + |
| 50 | +It is highly recommended to set up the |
| 51 | +[nixpkgs-terraform](https://nixpkgs-terraform.cachix.org) binary cache to |
| 52 | +download pre-compiled Terraform binaries rather than compiling them locally for |
| 53 | +a better user experience. Add the following configuration to the `flake.nix` |
| 54 | +file: |
| 55 | + |
| 56 | +```nix |
| 57 | +nixConfig = { |
| 58 | + extra-substituters = "https://nixpkgs-terraform.cachix.org"; |
| 59 | + extra-trusted-public-keys = "nixpkgs-terraform.cachix.org-1:8Sit092rIdAVENA3ZVeH9hzSiqI/jng6JiCrQ1Dmusw="; |
| 60 | +}; |
| 61 | +``` |
| 62 | + |
| 63 | +## Usage |
| 64 | + |
| 65 | +After configuring the inputs from the [Install](#install) section, a common use |
| 66 | +case for this flake could be spawning a [nix-shell] with a specific Terraform |
| 67 | +version, which could be accomplished by extracting the desired version from |
| 68 | +`nixpkgs-terraform.packages` as follows: |
| 69 | + |
| 70 | +```nix |
| 71 | +outputs = { self, flake-utils, nixpkgs-terraform, nixpkgs }: |
| 72 | + flake-utils.lib.eachDefaultSystem (system: |
| 73 | + let |
| 74 | + pkgs = nixpkgs.legacyPackages.${system}; |
| 75 | + terraform = nixpkgs-terraform.packages.${system}."1.6.3"; |
| 76 | + in |
| 77 | + { |
| 78 | + devShells.default = pkgs.mkShell { |
| 79 | + buildInputs = [ terraform ]; |
| 80 | + }; |
| 81 | + }); |
| 82 | +``` |
| 83 | + |
| 84 | +Start a new [nix-shell] with Terraform installed by running the following |
| 85 | +command: |
| 86 | + |
| 87 | +```sh |
| 88 | +env NIXPKGS_ALLOW_UNFREE=1 nix develop --impure |
| 89 | +``` |
| 90 | + |
| 91 | +**Note:** Due to Hashicorp’s most recent [license |
| 92 | +change](https://www.hashicorp.com/blog/hashicorp-adopts-business-source-license), |
| 93 | +the `NIXPKGS_ALLOW_UNFREE` flag is required for Terraform versions >= 1.6.0, |
| 94 | +`nix develop` should work out of the box for older versions. |
| 95 | + |
| 96 | +## License |
| 97 | + |
| 98 | +MIT, see [the LICENSE file](LICENSE). |
| 99 | + |
| 100 | +## Contributing |
| 101 | + |
| 102 | +Do you want to contribute to this project? Please take a look at our |
| 103 | +[contributing guideline](docs/CONTRIBUTING.md) to know how you can help us |
| 104 | +build it. |
| 105 | + |
| 106 | +--- |
| 107 | +<img src="https://www.stackbuilders.com/media/images/Sb-supports.original.png" |
| 108 | +alt="Stack Builders" width="50%"></img> |
| 109 | +[Check out our libraries](https://github.com/stackbuilders/) | [Join our |
| 110 | +team](https://www.stackbuilders.com/join-us/) |
| 111 | + |
| 112 | +[nix-shell]: https://nixos.wiki/wiki/Development_environment_with_nix-shell |
0 commit comments