Skip to content

Commit d963d6f

Browse files
committed
chore: add pre-commit workflow for Terraform validation
Signed-off-by: Ghislain Cheng <ghislain.cheng@zama.ai>
1 parent ea0f1de commit d963d6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+278
-437
lines changed

.github/workflows/pre-commit.yaml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Pre-Commit
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- master
8+
9+
env:
10+
TERRAFORM_DOCS_VERSION: v0.20.0
11+
TFLINT_VERSION: v0.59.1
12+
13+
jobs:
14+
collectInputs:
15+
name: Collect workflow inputs
16+
runs-on: ubuntu-latest
17+
outputs:
18+
directories: ${{ steps.dirs.outputs.directories }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Get root directories
24+
id: dirs
25+
uses: clowdhaus/terraform-composite-actions/directories@v1.9.0
26+
27+
preCommitMinVersions:
28+
name: Min TF pre-commit
29+
needs: collectInputs
30+
runs-on: ubuntu-latest
31+
strategy:
32+
matrix:
33+
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
34+
steps:
35+
# https://github.com/orgs/community/discussions/25678#discussioncomment-5242449
36+
- name: Delete huge unnecessary tools folder
37+
run: |
38+
rm -rf /opt/hostedtoolcache/CodeQL
39+
rm -rf /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk
40+
rm -rf /opt/hostedtoolcache/Ruby
41+
rm -rf /opt/hostedtoolcache/go
42+
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
46+
- name: Terraform min/max versions
47+
id: minMax
48+
uses: clowdhaus/terraform-min-max@v1.3.1
49+
with:
50+
directory: ${{ matrix.directory }}
51+
52+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
53+
# Run only validate pre-commit check on min version supported
54+
if: ${{ matrix.directory != '.' }}
55+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.11.1
56+
with:
57+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
58+
tflint-version: ${{ env.TFLINT_VERSION }}
59+
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
60+
61+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
62+
# Run only validate pre-commit check on min version supported
63+
if: ${{ matrix.directory == '.' }}
64+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.11.1
65+
with:
66+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
67+
tflint-version: ${{ env.TFLINT_VERSION }}
68+
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
69+
70+
preCommitMaxVersion:
71+
name: Max TF pre-commit
72+
runs-on: ubuntu-latest
73+
needs: collectInputs
74+
steps:
75+
# https://github.com/orgs/community/discussions/25678#discussioncomment-5242449
76+
- name: Delete huge unnecessary tools folder
77+
run: |
78+
rm -rf /opt/hostedtoolcache/CodeQL
79+
rm -rf /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk
80+
rm -rf /opt/hostedtoolcache/Ruby
81+
rm -rf /opt/hostedtoolcache/go
82+
83+
- name: Checkout
84+
uses: actions/checkout@v4
85+
with:
86+
ref: ${{ github.event.pull_request.head.ref }}
87+
repository: ${{github.event.pull_request.head.repo.full_name}}
88+
89+
- name: Terraform min/max versions
90+
id: minMax
91+
uses: clowdhaus/terraform-min-max@v1.3.1
92+
93+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
94+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.11.1
95+
with:
96+
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
97+
tflint-version: ${{ env.TFLINT_VERSION }}
98+
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
99+
install-hcledit: true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ dev-cluster-config
3838

3939
# Ignore files
4040
_*.go
41-
_*.yaml
41+
_*.yaml

.pre-commit-config.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
repos:
2+
- repo: https://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.100.0
4+
hooks:
5+
- id: terraform_fmt
6+
- id: terraform_docs
7+
args:
8+
- '--args=--lockfile=false'
9+
- id: terraform_tflint
10+
args:
11+
- '--args=--only=terraform_deprecated_interpolation'
12+
- '--args=--only=terraform_deprecated_index'
13+
- '--args=--only=terraform_unused_declarations'
14+
- '--args=--only=terraform_comment_syntax'
15+
- '--args=--only=terraform_documented_outputs'
16+
- '--args=--only=terraform_documented_variables'
17+
- '--args=--only=terraform_typed_variables'
18+
- '--args=--only=terraform_module_pinned_source'
19+
- '--args=--only=terraform_naming_convention'
20+
- '--args=--only=terraform_required_version'
21+
- '--args=--only=terraform_required_providers'
22+
- '--args=--only=terraform_standard_module_structure'
23+
- '--args=--only=terraform_workspace_remote'
24+
- id: terraform_validate
25+
- repo: https://github.com/pre-commit/pre-commit-hooks
26+
rev: v6.0.0
27+
hooks:
28+
- id: check-merge-conflict
29+
- id: end-of-file-fixer
30+
- id: trailing-whitespace
31+
- id: mixed-line-ending
32+
args: [--fix=lf]

.terraform-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ settings:
4646
required: true
4747
sensitive: true
4848
type: true
49-
wrap-word: false
49+
wrap-word: false

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,64 +48,64 @@ graph TB
4848
A_MPC["🔐 MPC Node<br/>Kubernetes Pod"]
4949
A_EXT_SVC["🔗 ExternalName Service<br/>bob-mpc-service<br/>DNS: bob-mpc-service.mpc-network.svc.cluster.local"]
5050
A_K8S_SVC["⚖️ LoadBalancer Service<br/>alice-mpc-lb-service<br/>Type: LoadBalancer"]
51-
51+
5252
A_MPC --> A_K8S_SVC
5353
A_MPC --> A_EXT_SVC
5454
end
55-
55+
5656
A_NLB["⚖️ Network LB<br/>(AWS Managed)"]
5757
A_S3["🗄️ S3 Storage<br/>Key Materials"]
5858
A_PROVIDER["🌉 VPC Endpoint Service<br/>(Expose to Bob)"]
5959
A_CONSUMER["🔌 VPC Endpoint Interface<br/>(Connect to Bob)"]
60-
60+
6161
A_K8S_SVC --> A_NLB
6262
A_NLB --> A_PROVIDER
6363
A_EXT_SVC --> A_CONSUMER
6464
A_MPC -.-> A_S3
6565
end
6666
end
67-
67+
6868
subgraph "Bob (eu-west-1)"
6969
subgraph "Bob Infrastructure"
7070
subgraph "EKS Cluster (bob-mpc-cluster)"
7171
B_MPC["🔐 MPC Node<br/>Kubernetes Pod"]
7272
B_EXT_SVC["🔗 ExternalName Service<br/>alice-mpc-service<br/>DNS: alice-mpc-service.mpc-network.svc.cluster.local"]
7373
B_K8S_SVC["⚖️ LoadBalancer Service<br/>bob-mpc-lb-service<br/>Type: LoadBalancer"]
74-
74+
7575
B_MPC --> B_K8S_SVC
7676
B_MPC --> B_EXT_SVC
7777
end
78-
78+
7979
B_NLB["⚖️ Network LB<br/>(AWS Managed)"]
8080
B_S3["🗄️ S3 Storage<br/>Key Materials"]
8181
B_PROVIDER["🌉 VPC Endpoint Service<br/>(Expose to Alice)"]
8282
B_CONSUMER["🔌 VPC Endpoint Interface<br/>(Connect to Alice)"]
83-
83+
8484
B_K8S_SVC --> B_NLB
8585
B_NLB --> B_PROVIDER
8686
B_EXT_SVC --> B_CONSUMER
8787
B_MPC -.-> B_S3
8888
end
8989
end
90-
90+
9191
subgraph "AWS PrivateLink"
9292
PL["🔒 Cross-Region<br/>Private Network"]
9393
end
94-
94+
9595
%% Bidirectional connections
9696
A_PROVIDER -.-> PL
9797
B_PROVIDER -.-> PL
9898
PL -.-> A_CONSUMER
9999
PL -.-> B_CONSUMER
100-
101100
102-
101+
102+
103103
%% Styling
104104
classDef alice fill:#e3f2fd,stroke:#000000,stroke-width:2px,color:#000000
105105
classDef bob fill:#f3e5f5,stroke:#000000,stroke-width:2px,color:#000000
106106
classDef network fill:#e8f5e8,stroke:#000000,stroke-width:2px,color:#000000
107107
classDef benefit fill:#f5f5f5,stroke:#000000,stroke-width:2px,color:#000000
108-
108+
109109
class A_MPC,A_EXT_SVC,A_K8S_SVC,A_NLB,A_S3,A_PROVIDER,A_CONSUMER alice
110110
class B_MPC,B_EXT_SVC,B_K8S_SVC,B_NLB,B_S3,B_PROVIDER,B_CONSUMER bob
111111
class PL network

examples/mpc-network-consumer/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
output "vpc_endpoint_consumer" {
44
description = "Outputs from the mpc-endpoint-consumer module"
55
value = module.vpc_endpoint_consumer
6-
}
6+
}

examples/mpc-network-consumer/providers.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.10"
33

44
required_providers {
55
aws = {
@@ -40,4 +40,4 @@ provider "kubernetes" {
4040
args = ["eks", "get-token", "--cluster-name", var.cluster_name, "--region", var.aws_region]
4141
command = "aws"
4242
}
43-
}
43+
}

examples/mpc-network-consumer/terraform.tfvars.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ common_tags = {
7676

7777
additional_tags = {
7878
"Project" = "mpc-connectivity"
79-
}
79+
}

examples/mpc-network-consumer/variables.tf

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,7 @@ variable "namespace" {
4141
default = "mpc-partners"
4242
}
4343

44-
variable "environment" {
45-
description = "Environment name (e.g., dev, staging, prod)"
46-
type = string
47-
default = "dev"
48-
}
4944

50-
variable "owner" {
51-
description = "Owner of the resources for tagging purposes"
52-
type = string
53-
default = "mpc-consumer-team"
54-
}
5545

5646
# Kubernetes Provider Configuration
5747
variable "kubeconfig_path" {
@@ -72,18 +62,6 @@ variable "use_eks_cluster_authentication" {
7262
default = false
7363
}
7464

75-
variable "aws_region_for_eks" {
76-
description = "AWS region where the EKS cluster is located (for provider configuration)"
77-
type = string
78-
default = null
79-
}
80-
81-
variable "use_eks_cluster_lookup" {
82-
description = "Whether to automatically find the vpc/subnet/secg from the cluster name"
83-
type = bool
84-
default = false
85-
}
86-
8765
# Direct VPC Configuration (Mode 2)
8866
variable "vpc_id" {
8967
description = "VPC ID where VPC interface endpoints will be created (required when use_eks_cluster_lookup is false)"
@@ -182,9 +160,3 @@ variable "common_tags" {
182160
"terraform" = "true"
183161
}
184162
}
185-
186-
variable "additional_tags" {
187-
description = "Additional tags to apply to resources"
188-
type = map(string)
189-
default = {}
190-
}

examples/mpc-network-provider/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
output "vpc_endpoint_provider" {
44
description = "Outputs from the vpc-endpoint-provider module"
55
value = module.vpc_endpoint_provider
6-
}
6+
}

0 commit comments

Comments
 (0)