Skip to content

Commit af5558d

Browse files
authored
Initial commit
0 parents  commit af5558d

Some content is hidden

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

41 files changed

+2250
-0
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AVM core team owns key files
2+
.github/policies/ @Azure/avm-core-team-technical
3+
.github/CODEOWNERS @Azure/avm-core-team-technical
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
author: AVM
2+
name: Docs check
3+
description: Checks that documentation has been updated on PR
4+
runs:
5+
using: composite
6+
steps:
7+
- name: setup go
8+
uses: actions/setup-go@v4
9+
with:
10+
go-version: "1.21.x"
11+
# cache-dependency-path: tests/go.sum
12+
13+
- name: setup Terraform
14+
uses: hashicorp/setup-terraform@v2
15+
with:
16+
terraform_wrapper: false
17+
18+
- name: install tools
19+
shell: bash
20+
run: |
21+
go install github.com/katbyte/terrafmt@latest
22+
go install github.com/terraform-docs/terraform-docs@latest
23+
24+
- name: fmt check
25+
shell: bash
26+
run: |
27+
echo "==> Fixing Terraform code with terraform fmt..."
28+
terraform fmt -recursive
29+
echo "==> Fixing embedded Terraform with terrafmt..."
30+
find . | egrep ".md|.tf" | grep -v README.md | sort | while read f; do terrafmt fmt $f; done
31+
32+
- name: docs check
33+
shell: bash
34+
run: |
35+
echo "==> Generating module documentation..."
36+
terraform-docs -c .terraform-docs.yml .
37+
echo "==> Generating examples documentation..."
38+
cd examples && for d in $(ls -d */); do terraform-docs $d; done
39+
40+
- name: check for changes
41+
shell: bash
42+
run: |
43+
echo "==> Testing for changes to tracked files"
44+
CHANGES=$(git status -suno)
45+
if [ "$CHANGES" ]; then
46+
echo "Repository formatting or documentation is not correct."
47+
echo
48+
git diff
49+
echo
50+
echo "Run 'make fmt && make docs' locally and commit the changes to fix."
51+
exit 1
52+
fi
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
author: AVM
2+
name: e2e - getexamples
3+
description: Gets example directories from `examples/` and outputs them to the next step
4+
inputs:
5+
github-token:
6+
description: The GitHub token to use for the API calls
7+
required: true
8+
outputs:
9+
examples:
10+
description: The examples to test
11+
value: ${{ steps.getexamples.outputs.examples }}
12+
runs:
13+
using: composite
14+
steps:
15+
- name: get examples
16+
id: getexamples
17+
run: |
18+
# Get latest release from GitHub API and get download URL for the Linux x64 binary
19+
URL=$(curl -sL -H "Authorization: Bearer ${{ inputs.github-token }}" https://api.github.com/repos/matt-FFFFFF/jsonls/releases/latest \
20+
| jq -r '.assets[] | select( .name | test("linux_amd64")) | .browser_download_url')
21+
22+
# Download the binary and extract
23+
curl -sL "$URL" | tar -xvz jsonls
24+
25+
# Ensure exec bit set
26+
sudo chmod a+x jsonls
27+
28+
# Move binary to path
29+
sudo mv jsonls /usr/local/bin/jsonls
30+
31+
# Get the examples
32+
echo examples="$(jsonls -d)" >> "$GITHUB_OUTPUT"
33+
working-directory: examples
34+
shell: bash
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
author: AVM
2+
name: e2e - testexamples
3+
description: Tests the example supplied in the input. Needs checkout and Azure login prior.
4+
inputs:
5+
example:
6+
description: The example directory to test
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- uses: hashicorp/setup-terraform@v2
13+
with:
14+
terraform_version: ">=1.5.0"
15+
16+
- name: terraform init
17+
run: terraform init
18+
working-directory: examples/${{ inputs.example }}
19+
shell: bash
20+
21+
- name: terraform apply
22+
run: terraform apply -auto-approve
23+
working-directory: examples/${{ inputs.example }}
24+
shell: bash
25+
26+
- name: terraform plan
27+
id: plan
28+
run: |
29+
terraform plan -detailed-exitcode
30+
echo PLANCODE="$?" >> "$GITHUB_OUTPUT"
31+
continue-on-error: true
32+
working-directory: examples/${{ inputs.example }}
33+
shell: bash
34+
35+
- name: check idempotent
36+
run: |
37+
echo Error: terraform plan code is ${{ steps.plan.outputs.PLANCODE }}
38+
exit 1
39+
working-directory: examples/${{ inputs.example }}
40+
shell: bash
41+
if: steps.plan.outputs.PLANCODE != 0
42+
43+
- name: terraform destroy
44+
run: terraform destroy -auto-approve
45+
working-directory: examples/${{ inputs.example }}
46+
shell: bash
47+
if: always()

.github/actions/linting/action.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
author: AVM
2+
name: linting
3+
description: Tests the example supplied in the input. Needs checkout and Azure login prior.
4+
inputs:
5+
github-token:
6+
description: The GitHub token
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- uses: hashicorp/setup-terraform@v2
13+
with:
14+
terraform_version: ">=1.5.0"
15+
16+
- name: terraform init
17+
run: terraform init
18+
shell: bash
19+
20+
- name: terraform validate
21+
run: terraform validate
22+
shell: bash
23+
24+
- uses: terraform-linters/setup-tflint@v3
25+
name: Setup TFLint
26+
with:
27+
tflint_version: v0.48.0
28+
env:
29+
GITHUB_TOKEN: ${{ inputs.github-token }}
30+
31+
- name: get tflint config
32+
run: |
33+
curl --header "Authorization: Bearer ${{ inputs.github-token }}" https://raw.githubusercontent.com/Azure/terraform-azurerm-avm-template/main/.tflint.hcl -o .tflint.hcl
34+
shell: bash
35+
36+
- name: tflint init
37+
run: tflint --init
38+
shell: bash
39+
40+
- name: tflint
41+
run: tflint
42+
shell: bash
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
author: AVM
2+
name: Module version check
3+
description: Checks that module version has been updated on PR
4+
inputs:
5+
version-file-name:
6+
description: Terraform JSON file containing module version
7+
required: false
8+
default: locals.version.tf.json
9+
jq-query:
10+
description: jq query to extract module version
11+
required: false
12+
default: .locals.module_version
13+
github_token:
14+
description: GitHub token
15+
required: true
16+
runs:
17+
using: composite
18+
steps:
19+
- name: semver regex
20+
shell: bash
21+
run: |
22+
echo SEMVER_REGEX="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" >> "$GITHUB_ENV"
23+
24+
- name: Get latest release version
25+
shell: bash
26+
run: |
27+
VER=$(curl --silent -L -H "Authorization: Bearer ${{ inputs.github_token }}" -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .name | sed s/^v//)
28+
if [ "$VER" == "null" ]; then
29+
echo "No releases found"
30+
echo LATEST_RELEASE="0.0.0" >> "$GITHUB_ENV"
31+
exit 0
32+
fi
33+
if echo "$VER" | grep -P -qv "$SEMVER_REGEX"; then
34+
echo "Release version $VER is not a valid semantic version"
35+
exit 1
36+
fi
37+
echo LATEST_RELEASE="$VER" >> "$GITHUB_ENV"
38+
39+
- name: Get current module version
40+
shell: bash
41+
run: |
42+
VER=$(jq -r '${{ inputs.jq-query }}' < ${{ inputs.version-file-name }})
43+
if echo "$VER" | grep -P -qv "$SEMVER_REGEX"; then
44+
echo "Module version $VER is not a valid semantic version"
45+
exit 1
46+
fi
47+
echo MODULE_VERSION="$VER" >> "$GITHUB_ENV"
48+
49+
- name: Check module version is greater than latest release
50+
shell: bash
51+
run: |
52+
MODVERMAJOR=$(echo ${{ env.MODULE_VERSION }} | cut -d. -f1)
53+
MODVERMINOR=$(echo ${{ env.MODULE_VERSION }} | cut -d. -f2)
54+
MODVERPATCH=$(echo ${{ env.MODULE_VERSION }} | cut -d. -f3)
55+
56+
RELVERMAJOR=$(echo ${{ env.LATEST_RELEASE }} | cut -d. -f1)
57+
RELVERMINOR=$(echo ${{ env.LATEST_RELEASE }} | cut -d. -f2)
58+
RELVERPATCH=$(echo ${{ env.LATEST_RELEASE }} | cut -d. -f3)
59+
60+
if [ "$MODVERMAJOR" -lt "$RELVERMAJOR" ]; then
61+
echo "Module version ${{ env.MODULE_VERSION }} is less than latest release ${{ env.LATEST_RELEASE }}"
62+
exit 1
63+
fi
64+
65+
if [ "$MODVERMAJOR" -eq "$RELVERMAJOR" ] && [ "$MODVERMINOR" -lt "$RELVERMINOR" ]; then
66+
echo "Module version ${{ env.MODULE_VERSION }} is less than latest release ${{ env.LATEST_RELEASE }}"
67+
exit 1
68+
fi
69+
70+
if [ "$MODVERMAJOR" -eq "$RELVERMAJOR" ] && [ "$MODVERMINOR" -eq "$RELVERMINOR" ] && [ "$MODVERPATCH" -lt "$RELVERPATCH" ]; then
71+
echo "Module version ${{ env.MODULE_VERSION }} is less than latest release ${{ env.LATEST_RELEASE }}"
72+
exit 1
73+
fi

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
version: 2
3+
4+
updates:
5+
- package-ecosystem: gomod
6+
directory: /tests
7+
schedule:
8+
interval: daily
9+
- package-ecosystem: "github-actions"
10+
directory: "/.github/workflows"
11+
schedule:
12+
interval: daily
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: AVM Mandatory Files Policy
2+
description: This policy will ensure the presence of AVM mandatory files into the repos
3+
4+
resource: repository
5+
where:
6+
# criteria can be provided to limit the repositories the policy is applied to
7+
configuration:
8+
mandatoryFiles:
9+
issueTitle: This repo is missing mandatory files
10+
issueBody: |
11+
There are several mandatory files we require in this
12+
repository. A pull request has been opened to add the
13+
missing files. When the pr is merged this issue will be
14+
closed automatically.
15+
prTitle: "feat: add AVM mandatory file(s) to this repo"
16+
prBody: |
17+
This repository needs the standard workflow and policy files to ensure compliance.
18+
file:
19+
- path: .github/workflows/version-check.yml
20+
prContentLink: https://raw.githubusercontent.com/Azure/terraform-azurerm-avm-template/main/.github/workflows/version-check.yml
21+
- path: .github/workflows/linting.yml
22+
prContentLink: https://raw.githubusercontent.com/Azure/terraform-azurerm-avm-template/main/.github/workflows/linting.yml
23+
- path: Makefile
24+
prContentLink: https://raw.githubusercontent.com/Azure/terraform-azurerm-avm-template/main/Makefile
25+
- path: .github/policies/avmrequiredfiles.yml
26+
prContentLink: https://raw.githubusercontent.com/Azure/terraform-azurerm-avm-template/main/.github/policies/avmrequiredfiles.yml
27+
- path: .github/policies/branchprotection.yml
28+
prContentLink: https://raw.githubusercontent.com/Azure/terraform-azurerm-avm-template/main/.github/policies/branchprotection.yml
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: avm_required
2+
description: AVM minimum required branch protection policy
3+
resource: repository
4+
where:
5+
configuration:
6+
branchProtectionRules:
7+
- branchNamePattern: "~default~"
8+
requiresPullRequestBeforeMerging: true
9+
requiredApprovingReviewsCount: 0
10+
isAdminEnforced: true
11+
allowsForcePushes: false
12+
allowsDeletions: false
13+
requiresLinearHistory: true
14+
requireCodeOwnersReview: true

.github/workflows/e2e.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
name: e2e test
3+
4+
on:
5+
pull_request:
6+
types: ['opened', 'reopened', 'synchronize']
7+
merge_group:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
jobs:
15+
getexamples:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
examples: ${{ steps.getexamples.outputs.examples }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: get examples
22+
id: getexamples
23+
uses: Azure/terraform-azurerm-avm-template/.github/actions/e2e-getexamples@main
24+
with:
25+
github-token: ${{ secrets.GITHUB_TOKEN }}
26+
27+
testexamples:
28+
runs-on: ubuntu-latest
29+
needs: getexamples
30+
environment: test
31+
env:
32+
TF_IN_AUTOMATION: 1
33+
TF_VAR_enable_telemetry: false
34+
strategy:
35+
matrix:
36+
example: ${{ fromJson(needs.getexamples.outputs.examples) }}
37+
max-parallel: 5
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- uses: Azure/login@v1
42+
with:
43+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
44+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
45+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
46+
47+
- name: Test example
48+
uses: Azure/terraform-azurerm-avm-template/.github/actions/e2e-testexamples@main
49+
with:
50+
example: ${{ matrix.example }}
51+
52+
# This job is only run when all the previous jobs are successful.
53+
# We can use it for PR validation to ensure all examples have completed.
54+
testexamplescomplete:
55+
runs-on: ubuntu-latest
56+
needs: testexamples
57+
steps:
58+
- run: echo "All tests passed"

0 commit comments

Comments
 (0)