Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick terraform checks #1962

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ env:
GOTESTSUM_VERSION: 1.8.1 # You cannot use environment variables with workflows. The gotestsum version is hardcoded in the reusable workflows too.

jobs:
terraform-fmt-check:
name: "Terraform format check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: TERRAFORM_VERSION
terraform_wrapper: false
- name: Run Terraform checks
run: |
make terraform-fmt-check TERRAFORM_DIR="${{ github.workspace }}"

get-go-version:
name: "Determine Go toolchain version"
runs-on: ubuntu-latest
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ kind-cni:
kind create cluster --config=$(CURDIR)/acceptance/framework/environment/cni-kind/kind.config --name dc2 --image kindest/node:v1.23.6
make kind-cni-calico

# Perform a terraform fmt check but don't change anything
terraform-fmt-check:
@$(CURDIR)/control-plane/build-support/scripts/terraformfmtcheck.sh $(TERRAFORM_DIR)
.PHONY: terraform-fmt-check

# Format all terraform files according to terraform fmt
terraform-fmt:
@terraform fmt -recursive
.PHONY: terraform-fmt


# ===========> CLI Targets

Expand Down
2 changes: 1 addition & 1 deletion charts/consul/test/terraform/aks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ variable "cluster_count" {
}

variable "tags" {
type = map
type = map(any)
default = {}
description = "Tags to attach to the created resources."
}
2 changes: 1 addition & 1 deletion charts/consul/test/terraform/eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ variable "role_arn" {
}

variable "tags" {
type = map
type = map(any)
default = {}
description = "Tags to attach to the created resources."
}
2 changes: 1 addition & 1 deletion charts/consul/test/terraform/gke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variable "cluster_count" {
}

variable "labels" {
type = map
type = map(any)
default = {}
description = "Labels to attach to the created resources."
}
2 changes: 1 addition & 1 deletion charts/consul/test/terraform/openshift/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variable "cluster_count" {
}

variable "tags" {
type = map
type = map(any)
default = {}
description = "Tags to attach to the created resources."
}
14 changes: 14 additions & 0 deletions control-plane/build-support/scripts/terraformfmtcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# Check terraform fmt
echo "==> Checking that code complies with terraform fmt requirements..."
tffmt_files=$(terraform fmt -check -recursive "$1")
if [[ -n ${tffmt_files} ]]; then
echo 'terraform fmt needs to be run on the following files:'
echo "${tffmt_files}"
echo "You can use the command: \`make terraform-fmt\` to reformat all terraform code."
exit 1
fi

echo "==> Check code compile completed successfully"
exit 0