Skip to content

Commit

Permalink
Merge pull request #994 from totoroot/fix-aws-vault
Browse files Browse the repository at this point in the history
Add OpenTofu and use as default for aws-vault
  • Loading branch information
domenkozar authored Mar 5, 2024
2 parents f0319af + 0fb0752 commit 6824f2b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
10 changes: 7 additions & 3 deletions examples/aws-vault/devenv.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{ pkgs, ... }: {
languages.terraform.enable = true;
{ pkgs, ... }:

{
# Since Terraform adopted a non-free license (BSL 1.1) in August 2023,
# using terraform instead of opentofu now requires adding `allowUnfree: true` to `devenv.yaml`
languages.opentofu.enable = true;

aws-vault = {
enable = true;
profile = "aws-profile";
awscliWrapper.enable = true;
terraformWrapper.enable = true;
opentofuWrapper.enable = true;
};
}
25 changes: 25 additions & 0 deletions src/modules/integrations/aws-vault.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ in
description = "Attribute set of packages including awscli2";
};

opentofuWrapper = lib.mkOption {
type = lib.types.submodule {
options = {
enable = lib.mkEnableOption ''
Wraps opentofu binary as `aws-vault exec <profile> -- opentofu <args>`.
'';

package = lib.mkOption {
type = lib.types.package;
default = pkgs.opentofu;
defaultText = lib.literalExpression "pkgs.opentofu";
description = "The opentofu package to use.";
};
};
};
defaultText = lib.literalExpression "pkgs";
default = { };
description = "Attribute set of packages including opentofu";
};

terraformWrapper = lib.mkOption {
type = lib.types.submodule {
options = {
Expand Down Expand Up @@ -70,6 +90,11 @@ in
'')
];
})
(lib.mkIf (cfg.enable && cfg.opentofuWrapper.enable) {
languages.opentofu.package = pkgs.writeScriptBin "opentofu" ''
${cfg.package}/bin/aws-vault exec ${cfg.profile} -- ${cfg.opentofuWrapper.package}/bin/tofu "$@"
'';
})
(lib.mkIf (cfg.enable && cfg.terraformWrapper.enable) {
languages.terraform.package = pkgs.writeScriptBin "terraform" ''
${cfg.package}/bin/aws-vault exec ${cfg.profile} -- ${cfg.terraformWrapper.package}/bin/terraform "$@"
Expand Down
23 changes: 23 additions & 0 deletions src/modules/languages/opentofu.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ pkgs, config, lib, ... }:

let
cfg = config.languages.opentofu;
in
{
options.languages.opentofu = {
enable = lib.mkEnableOption "tools for OpenTofu development";

package = lib.mkOption {
type = lib.types.package;
default = pkgs.opentofu;
defaultText = lib.literalExpression "pkgs.opentofu";
description = "The OpenTofu package to use.";
};
};

config = lib.mkIf cfg.enable {
packages = with pkgs; [
cfg.package
];
};
}

0 comments on commit 6824f2b

Please sign in to comment.