Skip to content

Commit f827da1

Browse files
committed
feat(build): #232 deploy terraform
- Add /deployTerraform to makes.nix - Add arguments, docs, etc
1 parent 571cf05 commit f827da1

File tree

8 files changed

+173
-2
lines changed

8 files changed

+173
-2
lines changed

.github/workflows/dev.yml

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ jobs:
77
name: __all__
88
with:
99
args: sh -c "nix-env -if . && m . __all__"
10+
deployTerraform_module:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: docker://docker.io/nixos/nix:2.3.12
15+
name: /deployTerraform/module
16+
with:
17+
args: sh -c "nix-env -if . && m . /deployTerraform/module"
1018
formatBash:
1119
runs-on: ubuntu-latest
1220
steps:

README.md

+58-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ in just a few steps, in any technology.
4949
- [lintWithLizard](#lintwithlizard)
5050
- [Testing](#testing)
5151
- [testTerraform](#testterraform)
52+
- [Deployment](#deployment)
53+
- [deployTerraform](#deployterraform)
5254
- [Pinning](#pinning)
5355
- [inputs](#inputs)
5456
- [requiredMakesVersion](#requiredmakesversion)
@@ -949,7 +951,9 @@ Example `makes.nix`:
949951
}
950952
```
951953

952-
Example invocation: `$ m . /lintTerraform`
954+
Example invocation: `$ m . /lintTerraform/module1`
955+
956+
Example invocation: `$ m . /lintTerraform/module2`
953957

954958
### lintWithLizard
955959

@@ -1026,7 +1030,57 @@ Example `makes.nix`:
10261030
}
10271031
```
10281032

1029-
Example invocation: `$ m . /testTerraform`
1033+
Example invocation: `$ m . /testTerraform/module1`
1034+
1035+
Example invocation: `$ m . /testTerraform/module2`
1036+
1037+
## Deployment
1038+
1039+
### deployTerraform
1040+
1041+
Deploy [Terraform][TERRAFORM] code
1042+
by performing a `terraform apply`
1043+
over the specified [Terraform][TERRAFORM] modules.
1044+
1045+
Attributes:
1046+
1047+
- modules (`attrsOf moduleType`): Optional.
1048+
Path to [Terraform][TERRAFORM] modules to lint.
1049+
Defaults to `{ }`.
1050+
1051+
Custom Types:
1052+
1053+
- moduleType (`submodule`):
1054+
- authentication (`listOf package`): Optional.
1055+
[Makes Secrets][MAKES_SECRETS] to use (if required by your module).
1056+
Defaults to `[ ]`.
1057+
- src (`str`):
1058+
Path to the [Terraform][TERRAFORM] module.
1059+
- version (`enum [ "0.12" "0.13" "0.14" "0.15" "0.16" ]`):
1060+
[Terraform][TERRAFORM] version your module is built with.
1061+
1062+
Example `makes.nix`:
1063+
1064+
```nix
1065+
{
1066+
deployTerraform = {
1067+
modules = {
1068+
module1 = {
1069+
src = "/my/module1";
1070+
version = "0.12";
1071+
};
1072+
module2 = {
1073+
src = "/my/module2";
1074+
version = "0.16";
1075+
};
1076+
};
1077+
};
1078+
}
1079+
```
1080+
1081+
Example invocation: `$ m . /deployTerraform/module1`
1082+
1083+
Example invocation: `$ m . /deployTerraform/module2`
10301084

10311085
## Pinning
10321086

@@ -1766,6 +1820,8 @@ Examples:
17661820
https://github.com/fluidattacks/makes/commit/01fcd5790dd54b117da63bcc2480437135da8bb3)
17671821
- [feat(build): #232 lint terraform](
17681822
https://github.com/fluidattacks/makes/commit/081835b563c712b7650dbc5bf1e306d4aff159cf)
1823+
- [feat(build): #232 test terraform](
1824+
https://github.com/fluidattacks/makes/commit/571cf059b521cb97396210f9fe4659ee74f675b4)
17691825
- [feat(build): #252 aws secrets from env](
17701826
https://github.com/fluidattacks/makes/commit/1c9f06a809bd92d56939d5809ce46058856fdf0a)
17711827
- [feat(build): #232 make parallel utils](

makes.nix

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
};
3030
};
3131
};
32+
deployTerraform = {
33+
modules = {
34+
module = {
35+
src = "/test/terraform/module";
36+
version = "0.13";
37+
};
38+
};
39+
};
3240
formatBash = {
3341
enable = true;
3442
targets = [ "/" ];

src/args/default.nix

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let
1414
asBashArray = args: "( ${lib.strings.escapeShellArgs args} )";
1515
asContent = import ./as-content/default.nix;
1616
deployContainerImage = import ./deploy-container-image/default.nix args;
17+
deployTerraform = import ./deploy-terraform/default.nix args;
1718
fakeSha256 = lib.fakeSha256;
1819
fetchGithub = import ./fetchers/github.nix args;
1920
fetchNixpkgs = import ./fetchers/nixpkgs.nix args;

src/args/deploy-terraform/default.nix

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{ __nixpkgs__
2+
, makeScript
3+
, makeTerraformEnvironment
4+
, ...
5+
}:
6+
{ authentication
7+
, name
8+
, version
9+
, src
10+
, ...
11+
}:
12+
makeScript {
13+
entrypoint = ./entrypoint.sh;
14+
replace = {
15+
__argSrc__ = src;
16+
};
17+
name = "deploy-terraform-for-${name}";
18+
searchPaths = {
19+
source = [
20+
(makeTerraformEnvironment {
21+
inherit version;
22+
})
23+
] ++ authentication;
24+
};
25+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# shellcheck shell=bash
2+
3+
function main {
4+
local args=(
5+
-refresh=true
6+
)
7+
8+
cd "$(mktemp -d)" \
9+
&& copy '__argSrc__' . \
10+
&& info Initializing '__argSrc__' \
11+
&& terraform init \
12+
&& info Applying '__argSrc__' \
13+
&& if running_in_ci_cd_provider; then
14+
args+=(-auto-approve)
15+
fi \
16+
&& terraform apply "${args[@]}"
17+
}
18+
19+
main "${@}"

src/evaluator/modules/outputs/builtins/default.nix

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ args:
33
imports = [
44
(import ./__all__/default.nix args)
55
(import ./deploy-container-image/default.nix args)
6+
(import ./deploy-terraform/default.nix args)
67
(import ./format-bash/default.nix args)
78
(import ./format-markdown/default.nix args)
89
(import ./format-nix/default.nix args)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{ __nixpkgs__
2+
, __toModuleOutputs__
3+
, deployTerraform
4+
, path
5+
, ...
6+
}:
7+
{ config
8+
, lib
9+
, ...
10+
}:
11+
let
12+
makeOutput = name: { authentication, src, version }: {
13+
name = "/deployTerraform/${name}";
14+
value = deployTerraform {
15+
inherit authentication;
16+
inherit name;
17+
src = path src;
18+
inherit version;
19+
};
20+
};
21+
in
22+
{
23+
options = {
24+
deployTerraform = {
25+
modules = lib.mkOption {
26+
default = { };
27+
type = lib.types.attrsOf (lib.types.submodule (_: {
28+
options = {
29+
authentication = lib.mkOption {
30+
default = [ ];
31+
type = lib.types.listOf lib.types.package;
32+
};
33+
src = lib.mkOption {
34+
type = lib.types.str;
35+
};
36+
version = lib.mkOption {
37+
type = lib.types.enum [
38+
"0.12"
39+
"0.13"
40+
"0.14"
41+
"0.15"
42+
"0.16"
43+
];
44+
};
45+
};
46+
}));
47+
};
48+
};
49+
};
50+
config = {
51+
outputs = __toModuleOutputs__ makeOutput config.deployTerraform.modules;
52+
};
53+
}

0 commit comments

Comments
 (0)