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

feat: Using tfmod-scaffold for avm's pull request check #53

Merged
merged 4 commits into from
Dec 18, 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
41 changes: 2 additions & 39 deletions .github/actions/docs-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,12 @@ description: Checks that documentation has been updated on PR
runs:
using: composite
steps:
- name: setup go
uses: actions/setup-go@v4
with:
go-version: "1.21.x"
# cache-dependency-path: tests/go.sum

- name: setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false

- name: install tools
shell: bash
run: |
go install github.com/katbyte/terrafmt@latest
go install github.com/terraform-docs/terraform-docs@latest

- name: fmt check
shell: bash
run: |
echo "==> Fixing Terraform code with terraform fmt..."
terraform fmt -recursive
echo "==> Fixing embedded Terraform with terrafmt..."
find . | egrep ".md|.tf" | grep -v README.md | sort | while read f; do terrafmt fmt $f; done
docker run --rm -v $(pwd):/src -w /src mcr.microsoft.com/azterraform make fmtcheck

- name: docs check
shell: bash
run: |
echo "==> Generating module documentation..."
terraform-docs -c .terraform-docs.yml .
echo "==> Generating examples documentation..."
cd examples && for d in $(ls -d */); do terraform-docs $d; done

- name: check for changes
shell: bash
run: |
echo "==> Testing for changes to tracked files"
CHANGES=$(git status -suno)
if [ "$CHANGES" ]; then
echo "Repository formatting or documentation is not correct."
echo
git diff
echo
echo "Run 'make fmt && make docs' locally and commit the changes to fix."
exit 1
fi
docker run --rm -v $(pwd):/src -w /src mcr.microsoft.com/azterraform make docscheck
47 changes: 0 additions & 47 deletions .github/actions/e2e-testexamples/action.yml

This file was deleted.

34 changes: 14 additions & 20 deletions .github/actions/linting/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,28 @@ inputs:
runs:
using: composite
steps:
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: ">=1.5.0"

- name: terraform init
run: terraform init
- name: terraform fmt check
shell: bash
run: |
docker run --rm -v $(pwd):/src -w /src mcr.microsoft.com/azterraform make tffmtcheck

- name: terraform validate
run: terraform validate
shell: bash

- uses: terraform-linters/setup-tflint@v3
name: Setup TFLint
with:
tflint_version: v0.48.0
env:
GITHUB_TOKEN: ${{ inputs.github-token }}

- name: get tflint config
run: |
curl --header "Authorization: Bearer ${{ inputs.github-token }}" https://raw.githubusercontent.com/Azure/terraform-azurerm-avm-template/main/.tflint.hcl -o .tflint.hcl
shell: bash
docker run --rm -v $(pwd):/src -w /src mcr.microsoft.com/azterraform make tfvalidatecheck

- name: tflint init
run: tflint --init
- name: terrafmt check
shell: bash
run: |
docker run --rm -v $(pwd):/src -w /src mcr.microsoft.com/azterraform make terrafmtcheck

- name: tflint
run: tflint
shell: bash
run: |
docker run --rm -v $(pwd):/src -w /src mcr.microsoft.com/azterraform make tflint

- name: tfsec
shell: bash
run: |
echo "Bypass tfsec for now"
21 changes: 12 additions & 9 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ permissions:

jobs:
getexamples:
if: github.event.repository.name != 'terraform-azurerm-avm-template'
runs-on: ubuntu-latest
outputs:
examples: ${{ steps.getexamples.outputs.examples }}
Expand All @@ -25,7 +26,8 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}

testexamples:
runs-on: ubuntu-latest
if: github.event.repository.name != 'terraform-azurerm-avm-template'
runs-on: [ self-hosted, 1ES.Pool=terraform-azurerm-container-apps ]
needs: getexamples
environment: test
env:
Expand All @@ -36,22 +38,23 @@ jobs:
example: ${{ fromJson(needs.getexamples.outputs.examples) }}
max-parallel: 5
steps:
- uses: actions/checkout@v4

- uses: Azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1

- name: Test example
uses: Azure/terraform-azurerm-avm-template/.github/actions/e2e-testexamples@main
shell: bash
run: |
set -e
az login --identity --username $MSI_ID > /dev/null
export ARM_SUBSCRIPTION_ID=$(az login --identity --username $MSI_ID | jq -r '.[0] | .id')
export ARM_TENANT_ID=$(az login --identity --username $MSI_ID | jq -r '.[0] | .tenantId')
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/src -w /src --network=host -e TF_IN_AUTOMATION -e TF_VAR_enable_telemetry -e AVM_MOD_PATH=/src -e AVM_EXAMPLE=${{ matrix.example }} -e MSI_ID -e ARM_SUBSCRIPTION_ID -e ARM_TENANT_ID -e ARM_USE_MSI=true mcr.microsoft.com/azterraform:latest make test-example
with:
example: ${{ matrix.example }}

# This job is only run when all the previous jobs are successful.
# We can use it for PR validation to ensure all examples have completed.
testexamplescomplete:
if: github.event.repository.name != 'terraform-azurerm-avm-template'
runs-on: ubuntu-latest
needs: testexamples
steps:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ concurrency:

jobs:
linting:
if: github.event.repository.name != 'terraform-azurerm-avm-template'
name: linting
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1

- name: check docs
uses: Azure/terraform-azurerm-avm-template/.github/actions/docs-check@main
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/version-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ permissions:

jobs:
version-check:
if: github.event.repository.name != 'terraform-azurerm-avm-template'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
- name: Check version
uses: Azure/terraform-azurerm-avm-template/.github/actions/version-check@main
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc
avmmakefile
README-generated.md
avm.tflint.hcl
avm.tflint_example.hcl
Loading