diff --git a/.github/workflows b/.github/workflows index e69de29..f2ea17e 100644 --- a/.github/workflows +++ b/.github/workflows @@ -0,0 +1,24 @@ +name: YAML Syntax Check + +on: [push, pull_request] + +jobs: + lint-yaml: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + + - name: Install yamllint + run: | + python -m pip install --upgrade pip + pip install yamllint + + - name: Run yamllint + run: yamllint . diff --git a/README.md b/README.md index 7d3d046..2530392 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ actions/ │ └── README.md ``` -### Terraform Action 🌍 +### Terraform Actions 🌍 **Location:** `actions/terraform` @@ -27,18 +27,17 @@ actions/ ### How to Use ```yaml +name: Terraform Check + +on: [push, pull_request] + jobs: - terraform-job: + example-job: runs-on: ubuntu-latest + steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Run Terraform Action + - name: Run Terraform Action from oak-terraform-actions uses: oaknational/oak-actions/actions/terraform@main - with: - example_input: "value" ``` -> **Note:** Replace `example_input` with the required parameters as specified in the action's `README.md`. - For more details, visit the [oaknational/oak-actions repository](https://github.com/oaknational/oak-actions). diff --git a/actions/terraform/action.yml b/actions/terraform/action.yml index e02f2ea..f5d040a 100644 --- a/actions/terraform/action.yml +++ b/actions/terraform/action.yml @@ -1,31 +1,40 @@ -name: Common Terraform Checks -run-name: 🔍 Terraform Checks - triggered by @${{ github.actor }} -on: [push] -jobs: - terraform-checks: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: hashicorp/setup-terraform@v2 - with: - terraform_version: 1.5.7 # See upgrading docs regarding tfenv: https://www.notion.so/oaknationalacademy/Terraform-The-Oak-Guide-to-b3930c13433f48fa890968636f495098?pvs=4#4dee54a2e4714f55957b047c1d94c62a - - name: "INFO: Acertain Terraform Version" - shell: bash - run: terraform --version - - name: "INFO: Linting Terraform Files" - shell: bash - run: | - cd infrastructure - terraform fmt -check $(find . -name '*tf') - - name: "INFO: Validate terraform configs" - shell: bash - run: | - cd infrastructure - for d in $(find . -type d -mindepth 1 -maxdepth 1) - do - echo "Validating the $d config" - cd $d - terraform init -backend=false - terraform validate - cd .. - done +name: "Terraform Checks" +description: "Perform common Terraform checks" +inputs: + terraform_version: + description: "Terraform version to use" + required: false + default: "1.5.7" +runs: + using: "composite" + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + with: + terraform_version: ${{ inputs.terraform_version }} + + - name: "INFO: Ascertain Terraform Version" + shell: bash + run: terraform --version + + - name: "INFO: Linting Terraform Files" + shell: bash + run: | + cd infrastructure + terraform fmt -check $(find . -name '*tf') + + - name: "INFO: Validate Terraform Configs" + shell: bash + run: | + cd infrastructure + for d in $(find . -type d -mindepth 1 -maxdepth 1) + do + echo "Validating the $d config" + cd $d + terraform init -backend=false + terraform validate + cd .. + done diff --git a/examples/define-version/action.yml b/examples/define-version/action.yml new file mode 100644 index 0000000..5b594c8 --- /dev/null +++ b/examples/define-version/action.yml @@ -0,0 +1,12 @@ +name: Terraform Check - With Defined Version + +on: [push, pull_request] + +jobs: + terraform-checks: + runs-on: ubuntu-latest + steps: + - name: Run Terraform Checks Action from oak-terraform-actions + uses: oaknational/oak-actions/actions/terraform-checks@main + with: + terraform_version: 1.5.7 # or any other version as needed diff --git a/examples/terraform/README.md b/examples/general-use/README.md similarity index 100% rename from examples/terraform/README.md rename to examples/general-use/README.md diff --git a/examples/general-use/action.yml b/examples/general-use/action.yml new file mode 100644 index 0000000..818b502 --- /dev/null +++ b/examples/general-use/action.yml @@ -0,0 +1,13 @@ +name: Terraform Check + +on: [push, pull_request] + +jobs: + example-job: + runs-on: ubuntu-latest + + steps: + - name: Run Terraform Action from oak-terraform-actions + uses: oaknational/oak-actions/actions/terraform@main + with: + example_input: "value" diff --git a/examples/terraform/action.yml b/examples/terraform/action.yml deleted file mode 100644 index 1596ebe..0000000 --- a/examples/terraform/action.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Example Workflow - -on: - push: - branches: - - main - -jobs: - example-job: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Run Terraform Action from oak-actions - uses: oaknational/oak-actions/actions/terraform@main - with: - example_input: "value"