-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added terraform-module template
- Loading branch information
1 parent
a85aa33
commit e3f48c0
Showing
9 changed files
with
234 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/ALT-F4-LLC/build-configs/internal/templates" | ||
) | ||
|
||
const TerraformModuleName = "terraform-module" | ||
|
||
type TerraformModuleConfig struct { | ||
Config | ||
Nix NixConfig `json:"nix,omitempty" yaml:"nix,omitempty"` | ||
Providers []string `json:"providers,omitempty" yaml:"providers,omitempty"` | ||
} | ||
|
||
func NewTerraformModuleConfig(c Config) TerraformModuleConfig { | ||
return TerraformModuleConfig{ | ||
Config: c, | ||
Nix: NewNixConfig(), | ||
} | ||
} | ||
|
||
func (c TerraformModuleConfig) Render() error { | ||
renderMap := templates.RenderMap{ | ||
templates.AllCommonTemplates: { | ||
".envrc", | ||
".github/renovate.json", | ||
}, | ||
templates.TerraformModuleTemplates: { | ||
".github/workflows/terraform.yaml", | ||
".gitignore", | ||
"flake.nix", | ||
"justfile", | ||
}, | ||
} | ||
|
||
files, err := templates.RenderTemplates(renderMap, c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return templates.WriteFiles(files) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
internal/templates/templates/terraform-module/.github__workflows__terraform.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: terraform | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
env: | ||
CACHIX_BINARY_CACHE: {{ .Nix.Cachix.BinaryCache }} | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: cachix/install-nix-action@v27 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
- uses: cachix/cachix-action@v15 | ||
with: | ||
authToken: ${{"{{"}} secrets.CACHIX_AUTH_TOKEN {{"}}"}} | ||
name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} | ||
- uses: actions/checkout@v4 | ||
- run: nix develop -c just check | ||
|
||
package: | ||
needs: | ||
- check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: cachix/install-nix-action@v27 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
- uses: cachix/cachix-action@v15 | ||
with: | ||
authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} | ||
name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} | ||
- uses: actions/checkout@v4 | ||
- run: nix develop -c just package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.direnv | ||
*.tfplan | ||
|
||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
crash.*.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
# password, private keys, and other secrets. These should not be part of version | ||
# control as they are data points which are potentially sensitive and subject | ||
# to change depending on the environment. | ||
*.tfvars | ||
*.tfvars.json | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc | ||
.terraform.lock.hcl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; | ||
|
||
outputs = inputs @ { | ||
flake-parts, | ||
nixpkgs, | ||
... | ||
}: | ||
flake-parts.lib.mkFlake {inherit inputs;} { | ||
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; | ||
|
||
perSystem = { | ||
config, | ||
pkgs, | ||
system, | ||
... | ||
}: let | ||
inherit (pkgs) just mkShell terraform-docs; | ||
terraform = pkgs.terraform.withPlugins (ps: [ | ||
{{- range $p := .Providers }} | ||
ps.{{ $p }} | ||
{{- end }} | ||
]); | ||
in { | ||
_module.args.pkgs = import nixpkgs { | ||
inherit system; | ||
config.allowUnfree = true; | ||
}; | ||
|
||
devShells = { | ||
default = mkShell { | ||
inputsFrom = [config.packages.default]; | ||
nativeBuildInputs = [ | ||
just | ||
terraform-docs | ||
]; | ||
}; | ||
}; | ||
|
||
packages = { | ||
default = | ||
pkgs.runCommand "default" | ||
{ | ||
src = ./.; | ||
} '' | ||
mkdir -p $out | ||
cp -R $src/*.tf $out | ||
${terraform}/bin/terraform -chdir="$out" init | ||
${terraform}/bin/terraform -chdir="$out" validate | ||
''; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
_default: | ||
just --list | ||
|
||
check: | ||
nix flake check | ||
|
||
docs: | ||
terraform-docs markdown table \ | ||
--output-file README.md \ | ||
--output-mode inject . | ||
|
||
init: | ||
terraform init | ||
|
||
package: | ||
nix build --json --no-link --print-build-logs . | ||
|
||
validate: | ||
terraform validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters