Skip to content

Commit

Permalink
Add pre_commit configs and GH actions (#30)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Enright <jenright@cloudera.com>
  • Loading branch information
jimright authored May 31, 2024
1 parent ed56026 commit 1cf8448
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/check_terraform_fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Check Terraform Formatting

on:
pull_request:
push:
branches: [main]

jobs:
check-tf-fmt:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Validate with terraform fmt
uses: pre-commit/action@v3.0.0
with:
extra_args: terraform_fmt --all-files
38 changes: 38 additions & 0 deletions .github/workflows/check_tflint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Run Terraform Lint

on:
pull_request:
push:
branches: [main]

jobs:
check-tf-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install the tflint utility
run: |
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
- name: Validate with tflint
uses: pre-commit/action@v3.0.0
with:
extra_args: terraform_tflint --all-files
62 changes: 62 additions & 0 deletions .github/workflows/push-quickstart-script-to-s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Push quickstart scripts to S3
on:
push:
branches:
- eob-devel
tags:
- eob
jobs:
push-to-s3:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set location to push
id: s3-path
run: |
if [[ $GITHUB_REF_NAME == "eob" && $GITHUB_REF_TYPE == "tag" ]]; then
echo "TRIGGER=eob-tag" >> $GITHUB_ENV
echo "S3_FOLDER=latest" >> $GITHUB_ENV
fi
if [[ $GITHUB_REF_NAME == "eob-devel" && $GITHUB_REF_TYPE == "branch" ]]; then
echo "TRIGGER=eob-devel-branch" >> $GITHUB_ENV
echo "S3_FOLDER=dev" >> $GITHUB_ENV
fi
- name: Print the path
run: |
echo "Trigger is ${{ env.TRIGGER }}"
echo "S3 Bucket is ${{ vars.S3_BUCKET }}"
echo "S3 Path format is s3://${{ vars.S3_BUCKET }}/<CLOUD>/${{ env.S3_FOLDER }}"
- name: Authenticate with AWS
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Push quickstart scripts to S3
run: |
for csp in aws azure gcp
do
aws s3 cp ${csp}/quickstart.sh s3://${{ vars.S3_BUCKET }}/${csp}/${{ env.S3_FOLDER }}/
done
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2023 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.77.3
hooks:
# see https://github.com/antonbabenko/pre-commit-terraform#terraform_fmt
- id: terraform_fmt
args:
- --args=-diff

# see https://github.com/antonbabenko/pre-commit-terraform#terraform_validate
- id: terraform_validate
exclude: examples/.*

# see https://github.com/antonbabenko/pre-commit-terraform#terraform_providers_lock
- id: terraform_providers_lock

# see https://github.com/antonbabenko/pre-commit-terraform#terraform_tflint
- id: terraform_tflint
exclude: 'examples/.*'
args:
- '--args=--only=terraform_deprecated_interpolation'
- '--args=--only=terraform_deprecated_index'
- '--args=--only=terraform_unused_declarations'
- '--args=--only=terraform_comment_syntax'
- '--args=--only=terraform_documented_outputs'
- '--args=--only=terraform_documented_variables'
- '--args=--only=terraform_typed_variables'
- '--args=--only=terraform_module_pinned_source'
- '--args=--only=terraform_naming_convention'
- '--args=--only=terraform_required_version'
- '--args=--only=terraform_required_providers'
- '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote'

0 comments on commit 1cf8448

Please sign in to comment.