Skip to content

Commit

Permalink
Add terraform fmt check to CI
Browse files Browse the repository at this point in the history
- Add terraform fmt check to CI
- Fix current terraform fmt issues

Signed-off-by: Henri Rosten <henri.rosten@unikie.com>
  • Loading branch information
henrirosten committed Nov 3, 2023
1 parent d1e7be6 commit bdad8b0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/test-ghaf-infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,3 @@ jobs:
- uses: cachix/install-nix-action@v22
- name: Run ghaf-infra CI tests
run: nix develop --command inv pre-push
- name: Run terraform fmt
run: |
TF_LOG="DEBUG" bash -c 'nix develop .#terraform --command terraform -chdir=terraform fmt'
TF_LOG="DEBUG" bash -c 'nix develop .#terraform --command terraform -chdir=terraform/azure-storage fmt'
# TODO: Enable the below check when 'terraform validate' passes:
# - name: Run terraform validate
# run: |
# TF_LOG="DEBUG" bash -c 'nix develop .#terraform --command terraform -chdir=terraform validate'
# TF_LOG="DEBUG" bash -c 'nix develop .#terraform --command terraform -chdir=terraform/azure-storage validate'
3 changes: 2 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ pkgs.mkShell {
python3.pkgs.invoke
python3.pkgs.pycodestyle
python3.pkgs.pylint
reuse
sops
ssh-to-age
reuse
terraform
];
}
8 changes: 7 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,19 @@ def pre_push(c: Any) -> None:
ret = exec_cmd(cmd, raise_on_error=False)
if not ret:
sys.exit(1)
LOG.info("Running terraform fmt")
cmd = "terraform fmt -check -recursive"
ret = exec_cmd(cmd, raise_on_error=False)
if not ret:
LOG.warning("Run `terraform fmt -recursive` locally to fix formatting")
sys.exit(1)
LOG.info("Running nix fmt")
cmd = "nix fmt"
ret = exec_cmd(cmd, raise_on_error=False)
if not ret:
sys.exit(1)
LOG.info("Running nix flake check")
cmd = "nix flake check"
cmd = "nix flake check -v --log-format raw"
ret = exec_cmd(cmd, raise_on_error=False)
if not ret:
sys.exit(1)
Expand Down
4 changes: 2 additions & 2 deletions terraform/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ provider "azurerm" {
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
source = "hashicorp/azurerm"
}
sops = {
source = "carlpett/sops"
source = "carlpett/sops"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ variable "resource_group_location" {

variable "resourcegroup" {
description = "The Azure Resource Group Name within your Subscription in which this resource will be created."
default = "ghaf-infra-swe"
default = "ghaf-infra-swe"
}

variable "resource_group_name_prefix" {
Expand Down

0 comments on commit bdad8b0

Please sign in to comment.