Skip to content

Commit

Permalink
feat: all modules and example and docs should pass pre commit lint (#26)
Browse files Browse the repository at this point in the history
* chore: add pre-commmit check

Signed-off-by: Kevin Lefevre <lefevre.kevin@gmail.com>

* chore: update workflow

Signed-off-by: Kevin Lefevre <lefevre.kevin@gmail.com>

* chore: update mergify

Signed-off-by: Kevin Lefevre <lefevre.kevin@gmail.com>

* fix: examples should pass validation

Signed-off-by: Kevin Lefevre <lefevre.kevin@gmail.com>

* chore: update latest docs

Signed-off-by: Kevin Lefevre <lefevre.kevin@gmail.com>

* chore: add pre commit README

Signed-off-by: Kevin Lefevre <lefevre.kevin@gmail.com>
  • Loading branch information
ArchiFleKs authored Feb 25, 2021
1 parent d2d3e00 commit f7bc99a
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 136 deletions.
123 changes: 16 additions & 107 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,86 +9,29 @@ on:
- main

jobs:
linter:
name: 'linter'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Lint Code Base
uses: github/super-linter@v3
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_STATES: false
VALIDATE_TERRAFORM_TERRASCAN: false
VALIDATE_JSCPD: false
- name: 'slack:failure'
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: ${{ secrets.SLACK_CHANNEL }}
status: failure
color: danger

terraform-generic:
name: 'terraform:generic'
terraform-pre-commit:
name: 'terraform:pre-commit'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
- uses: actions/setup-python@v2

- name: Terraform Init
run: terraform init -backend=false
- name: Install terraform tooling
run: |
# Get the download url of the latest version of terraform-docs
tf_docs_download_url=$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | jq -rc '.assets[] | select( .name | contains("linux-amd64")).browser_download_url')
mkdir -p $GITHUB_WORKSPACE/bin
curl -Lo $GITHUB_WORKSPACE/bin/terraform-docs $tf_docs_download_url
chmod +x $GITHUB_WORKSPACE/bin/terraform-docs
curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
- name: Terraform Format
run: terraform fmt -check

- name: Terraform Validate
run: terraform validate

- name: 'slack:failure'
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
- name: Check modules
uses: pre-commit/action@v2.0.0
with:
channel: ${{ secrets.SLACK_CHANNEL }}
status: failure
color: danger

terraform-aws:
name: 'terraform:aws'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1

- name: Terraform Init
run: terraform init -backend=false
working-directory: modules/aws

- name: Terraform Format
run: terraform fmt -check
working-directory: modules/aws

- name: Terraform Validate
run: terraform validate
working-directory: modules/aws
env:
AWS_REGION: eu-west-3
extra_args: --show-diff-on-failure --all-files

- name: 'slack:failure'
if: failure()
Expand All @@ -100,47 +43,13 @@ jobs:
status: failure
color: danger

terraform-scaleway:
name: 'terraform:scaleway'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1

- name: Terraform Init
run: terraform init -backend=false
working-directory: modules/scaleway

- name: Terraform Format
run: terraform fmt -check
working-directory: modules/scaleway

- name: Terraform Validate
run: terraform validate
working-directory: modules/scaleway

- name: 'slack:failure'
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: ${{ secrets.SLACK_CHANNEL }}
status: failure
color: danger

terraform-release:
if: github.ref == 'refs/heads/main'
name: 'terraform:release'
runs-on: ubuntu-latest
needs:
- linter
- terraform-generic
- terraform-aws
- terraform-scaleway
- terraform-pre-commit
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
7 changes: 2 additions & 5 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ pull_request_rules:
conditions:
- "approved-reviews-by>=1"
- "check-success=Semantic Pull Request"
- "check-success=linter"
- "check-success=terraform:generic"
- "check-success=terraform:aws"
- "check-success=terraform:scaleway"
- "check-success=terraform:pre-commit"
actions:
merge:
method: merge
method: squash
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.46.0
hooks:
- id: terraform_fmt
- id: terraform_docs
- id: terraform_validate
- id: terraform_tflint
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ Any contribution supporting a new cloud provider is welcomed.
* [GCP](./modules/gcp)
* [Azure](./modules/azure)

## Doc generation

Code formatting and documentation for variables and outputs is generated using
[pre-commit-terraform
hooks](https://github.com/antonbabenko/pre-commit-terraform) which uses
[terraform-docs](https://github.com/segmentio/terraform-docs).

Follow [these
instructions](https://github.com/antonbabenko/pre-commit-terraform#how-to-install)
to install pre-commit locally.

And install `terraform-docs` with `go get github.com/segmentio/terraform-docs`
or `brew install terraform-docs`.


<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
Expand All @@ -64,6 +80,25 @@ Any contribution supporting a new cloud provider is welcomed.
| random | n/a |
| time | n/a |

## Modules

No Modules.

## Resources

| Name |
|------|
| [helm_release](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) |
| [kubectl_manifest](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) |
| [kubectl_path_documents](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/data-sources/path_documents) |
| [kubernetes_namespace](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) |
| [kubernetes_network_policy](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/network_policy) |
| [kubernetes_priority_class](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/priority_class) |
| [kubernetes_role](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/role) |
| [kubernetes_role_binding](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/role_binding) |
| [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) |
| [time_sleep](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) |

## Inputs

| Name | Description | Type | Default | Required |
Expand Down Expand Up @@ -99,4 +134,4 @@ Any contribution supporting a new cloud provider is welcomed.
| Name | Description |
|------|-------------|
| grafana\_password | n/a |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
51 changes: 48 additions & 3 deletions modules/aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ User guides, feature documentation and examples are available [here](https://git

This module can uses [IRSA](https://aws.amazon.com/blogs/opensource/introducing-fine-grained-iam-roles-service-accounts/).

## Terraform docs

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
Expand All @@ -39,6 +38,52 @@ This module can uses [IRSA](https://aws.amazon.com/blogs/opensource/introducing-
| time | n/a |
| tls | n/a |

## Modules

| Name | Source | Version |
|------|--------|---------|
| iam_assumable_role_aws-ebs-csi-driver | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_aws-for-fluent-bit | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_aws-load-balancer-controller | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_cert-manager | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_cluster-autoscaler | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_cni-metrics-helper | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_external-dns | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_kube-prometheus-stack_grafana | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_kube-prometheus-stack_thanos | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_loki-stack | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_thanos | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| iam_assumable_role_thanos-storegateway | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | ~> 3.0 |
| kube-prometheus-stack_thanos_bucket | terraform-aws-modules/s3-bucket/aws | ~> 1.0 |
| loki_bucket | terraform-aws-modules/s3-bucket/aws | ~> 1.0 |
| thanos_bucket | terraform-aws-modules/s3-bucket/aws | ~> 1.0 |

## Resources

| Name |
|------|
| [aws_caller_identity](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) |
| [aws_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) |
| [aws_iam_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) |
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) |
| [aws_region](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) |
| [helm_release](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) |
| [kubectl_manifest](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) |
| [kubectl_path_documents](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/data-sources/path_documents) |
| [kubernetes_namespace](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) |
| [kubernetes_network_policy](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/network_policy) |
| [kubernetes_priority_class](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/priority_class) |
| [kubernetes_role](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/role) |
| [kubernetes_role_binding](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/role_binding) |
| [kubernetes_secret](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret) |
| [kubernetes_storage_class](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/storage_class) |
| [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) |
| [time_sleep](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) |
| [tls_cert_request](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/cert_request) |
| [tls_locally_signed_cert](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/locally_signed_cert) |
| [tls_private_key](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) |
| [tls_self_signed_cert](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/self_signed_cert) |

## Inputs

| Name | Description | Type | Default | Required |
Expand Down Expand Up @@ -87,4 +132,4 @@ This module can uses [IRSA](https://aws.amazon.com/blogs/opensource/introducing-
| promtail-cert | n/a |
| promtail-key | n/a |
| thanos\_ca | n/a |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
24 changes: 22 additions & 2 deletions modules/scaleway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ User guides, feature documentation and examples are available [here](https://git

## Terraform docs

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
Expand All @@ -22,7 +23,6 @@ User guides, feature documentation and examples are available [here](https://git
| helm | ~> 2.0 |
| kubectl | ~> 1.0 |
| kubernetes | ~> 2.0 |
| scaleway | >= 1.17.0 |

## Providers

Expand All @@ -34,6 +34,26 @@ User guides, feature documentation and examples are available [here](https://git
| random | n/a |
| time | n/a |

## Modules

No Modules.

## Resources

| Name |
|------|
| [helm_release](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) |
| [kubectl_manifest](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) |
| [kubectl_path_documents](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/data-sources/path_documents) |
| [kubernetes_namespace](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) |
| [kubernetes_network_policy](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/network_policy) |
| [kubernetes_priority_class](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/priority_class) |
| [kubernetes_role](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/role) |
| [kubernetes_role_binding](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/role_binding) |
| [kubernetes_secret](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret) |
| [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) |
| [time_sleep](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) |

## Inputs

| Name | Description | Type | Default | Required |
Expand Down Expand Up @@ -72,4 +92,4 @@ User guides, feature documentation and examples are available [here](https://git
| Name | Description |
|------|-------------|
| grafana\_password | n/a |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3 changes: 3 additions & 0 deletions modules/scaleway/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Examples

Examples are located in [tkap](https://github.com/particuleio/tkap) repository.
36 changes: 36 additions & 0 deletions modules/scaleway/examples/terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| terraform | >= 0.13 |
| helm | ~> 2.0 |
| kubectl | ~> 1.0 |
| kubernetes | ~> 2.0 |

## Providers

No provider.

## Modules

| Name | Source | Version |
|------|--------|---------|
| kapsule | particuleio/kapsule/scaleway | |
| kapsule-addons | ../.. | |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| cluster-name | n/a | `string` | `"cluster"` | no |
| scaleway | n/a | `any` | `{}` | no |

## Outputs

No output.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Loading

0 comments on commit f7bc99a

Please sign in to comment.