SHCHERBANV - 11/merge #67
Workflow file for this run
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
name: Terraform Validate | |
run-name: ${{ github.actor }} - ${{ github.ref_name }} | |
on: | |
pull_request: | |
branches: ["main"] | |
workflow_dispatch: | |
jobs: | |
terraform_validate: | |
name: "Format and Validate Code" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v3 | |
- name: Check count function | |
run: | | |
if ! grep -Eq 'count\s+=' ./*.tf; then | |
echo "Count function not found in network.tf!" | |
exit 1 | |
fi | |
echo "Count function is present." | |
- name: Check for_each meta-argument for network interfaces | |
run: | | |
if ! grep -Eq 'for_each\s+=' *.tf || ! grep -q 'azurerm_network_interface' *.tf; then | |
echo "For_each meta-argument for network interfaces not found!" | |
exit 1 | |
fi | |
echo "For_each meta-argument for network interfaces is present." | |
- name: Check local value for network interface names | |
run: | | |
if ! grep -q 'locals {' *.tf || ! grep -Eq '(nic_names|network_interface_names)' *.tf; then | |
echo "Local value for network interface names not found!" | |
exit 1 | |
fi | |
echo "Local value for network interface names is present." | |
- name: Check lifecycle block | |
run: | | |
if ! grep -q 'lifecycle {' *.tf || ! grep -q 'prevent_destroy = true' *.tf; then | |
echo "Lifecycle block to prevent accidental deletion not found!" | |
exit 1 | |
fi | |
echo "Lifecycle block is present." | |
- name: Check dynamic blocks for security rules | |
run: | | |
if ! grep -q 'dynamic "security_rule"' *.tf; then | |
echo "Dynamic blocks for network security rules not found!" | |
exit 1 | |
fi | |
echo "Dynamic blocks for security rules are present." | |
- name: Check local value for security rules | |
run: | | |
if ! grep -q 'locals {' *.tf || ! grep -Eq '(security_rules|nsg_rules)' *.tf; then | |
echo "Local value for security rules not found!" | |
exit 1 | |
fi | |
echo "Local value for security rules is present." | |
- name: Check built-in functions usage | |
run: | | |
if ! grep -q 'upper(' *.tf || ! grep -q 'join(' *.tf || ! grep -Eq '\[for.*:' *.tf; then | |
echo "Required built-in functions not used correctly!" | |
exit 1 | |
fi | |
echo "Required built-in functions are present." | |
- name: Terraform Fmt | |
run: terraform fmt -check -recursive -diff | |
- name: Terraform Init | |
run: terraform init -backend=false | |
- name: Terraform Validate | |
run: terraform validate |