Skip to content

Commit f44a6d6

Browse files
slonkaAutomaat
andauthored
ci(build): run terraform init to check if tf code works (#390)
* ci(build): run terraform init to check if tf code works Signed-off-by: slonka <[email protected]> * update aws-action * fix: add OIDC permissions for AWS auth * fix init step * add more terraform validation * fix validation * fix ci Signed-off-by: Marcin Skalski <[email protected]> * fix missing variable Signed-off-by: Marcin Skalski <[email protected]> --------- Signed-off-by: slonka <[email protected]> Signed-off-by: Marcin Skalski <[email protected]> Co-authored-by: Marcin Skalski <[email protected]>
1 parent c132876 commit f44a6d6

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

.github/workflows/build.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,35 @@ on:
88
branches:
99
- main
1010

11+
# Required for aws-actions/configure-aws-credentials to use OIDC authentication
12+
permissions:
13+
id-token: write
14+
contents: read
15+
1116
jobs:
1217
build:
1318
name: Build, check and test
1419
runs-on: ubuntu-latest
1520
steps:
1621
- name: Checkout repository
1722
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23+
- name: Configure AWS Credentials
24+
uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8 # v5.1.0
25+
with:
26+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/mesh-perf-ci
27+
role-duration-seconds: 7200
28+
aws-region: us-west-1
1829
- uses: jdx/mise-action@be3be2260bc02bc3fbf94c5e2fed8b7964baf074 # v3.4.0
1930
env:
2031
GITHUB_TOKEN: ${{ github.token }}
2132
- name: make check
2233
run: make check
34+
- name: make terraform/init
35+
run: make terraform/init
36+
- name: make terraform/validate
37+
run: make terraform/validate
38+
- name: make terraform/plan
39+
run: make terraform/plan
2340
- name: golangci-lint
2441
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
2542
with:

infrastructure/eks/terraform.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ provider "aws" {
3030
}
3131

3232
provider "helm" {
33-
kubernetes {
33+
kubernetes = {
3434
host = module.eks.cluster_endpoint
3535
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
36-
exec {
36+
exec = {
3737
api_version = "client.authentication.k8s.io/v1beta1"
3838
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
3939
command = "aws"

infrastructure/eks/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ variable "cluster_version" {
2525
variable "nodes_number" {
2626
description = "Number of worker nodes in the cluster"
2727
type = number
28+
default = 1
2829
}
2930

3031
variable "nodes_type" {

mk/infrastructure.mk

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ endif
3030
define MAKE_INFRA_TARGETS
3131
$(1)_DIR := infrastructure/$(1)
3232

33-
# Apply/destroy targets use $(1)_TF_VARS if defined.
34-
terraform/apply/$$($(1)_DIR) terraform/destroy/$$($(1)_DIR): VARS = $($(1)_TF_VARS)
33+
# Apply/destroy/plan/validate targets use $(1)_TF_VARS if defined.
34+
terraform/apply/$$($(1)_DIR) terraform/destroy/$$($(1)_DIR) terraform/plan/$$($(1)_DIR) terraform/validate/$$($(1)_DIR): VARS = $($(1)_TF_VARS)
3535

3636
.PHONY: infra/create/$(1) infra/destroy/$(1)
3737

@@ -76,6 +76,27 @@ terraform/init/%: CHDIR = $*
7676
terraform/init/%:
7777
$(TF_CMD) init$(if $(UPGRADE), -upgrade,)$(if $(RECONFIGURE), -reconfigure,)
7878

79+
.PHONY: terraform/init
80+
terraform/init: $(foreach component,$(notdir $(wildcard $(TOP)/infrastructure/*)),terraform/init/infrastructure/$(component))
81+
82+
# Validate Terraform configuration in the specified directory.
83+
.PHONY: terraform/validate/%
84+
terraform/validate/%: CHDIR = $*
85+
terraform/validate/%:
86+
$(TF_CMD) validate
87+
88+
.PHONY: terraform/validate
89+
terraform/validate: $(foreach component,$(notdir $(wildcard $(TOP)/infrastructure/*)),terraform/validate/infrastructure/$(component))
90+
91+
# Plan Terraform changes in the specified directory.
92+
.PHONY: terraform/plan/%
93+
terraform/plan/%: CHDIR = $*
94+
terraform/plan/%:
95+
$(TF_CMD) plan $(if $(VARS),$(VARS))
96+
97+
.PHONY: terraform/plan
98+
terraform/plan: $(foreach component,$(notdir $(wildcard $(TOP)/infrastructure/*)),terraform/plan/infrastructure/$(component))
99+
79100
# Generic rule to apply or destroy Terraform configurations.
80101
# - Uses $* to dynamically extract the directory path from the target.
81102
# - Extracts "apply" or "destroy" from the target name via $(word 2,$(subst /,,$@)).

0 commit comments

Comments
 (0)