Skip to content

Commit 7a6088d

Browse files
committed
adding pre-commit file
1 parent 587f17b commit 7a6088d

File tree

15 files changed

+254
-152
lines changed

15 files changed

+254
-152
lines changed

.github/workflows/pre-commit.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Pre-Commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- develop
9+
10+
jobs:
11+
# Min Terraform version(s)
12+
getDirectories:
13+
name: Get root directories
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Install Python
20+
uses: actions/setup-python@v2
21+
22+
- name: Build matrix
23+
id: matrix
24+
run: |
25+
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
26+
echo "::set-output name=directories::$DIRS"
27+
outputs:
28+
directories: ${{ steps.matrix.outputs.directories }}
29+
30+
preCommitMinVersions:
31+
name: Min TF validate
32+
needs: getDirectories
33+
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
directory: ${{ fromJson(needs.getDirectories.outputs.directories) }}
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v2
40+
41+
- name: Install Python
42+
uses: actions/setup-python@v2
43+
44+
- name: Terraform min/max versions
45+
id: minMax
46+
uses: clowdhaus/terraform-min-max@v1.0.1
47+
with:
48+
directory: ${{ matrix.directory }}
49+
50+
- name: Install Terraform v${{ steps.minMax.outputs.minVersion }}
51+
uses: hashicorp/setup-terraform@v1
52+
with:
53+
terraform_version: ${{ steps.minMax.outputs.minVersion }}
54+
55+
- name: Install pre-commit dependencies
56+
run: pip install pre-commit
57+
58+
# - name: Execute pre-commit
59+
# # Run only validate pre-commit check on min version supported
60+
# if: ${{ matrix.directory != '.' }}
61+
# run:
62+
# pre-commit run terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*
63+
#
64+
# - name: Execute pre-commit
65+
# # Run only validate pre-commit check on min version supported
66+
# if: ${{ matrix.directory == '.' }}
67+
# run:
68+
# pre-commit run terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)
69+
70+
71+
# Max Terraform version
72+
getBaseVersion:
73+
name: Module max TF version
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@v2
78+
79+
- name: Terraform min/max versions
80+
id: minMax
81+
uses: clowdhaus/terraform-min-max@v1.0.1
82+
outputs:
83+
minVersion: ${{ steps.minMax.outputs.minVersion }}
84+
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
85+
86+
preCommitMaxVersion:
87+
name: Max TF pre-commit
88+
runs-on: ubuntu-latest
89+
needs: getBaseVersion
90+
strategy:
91+
fail-fast: false
92+
matrix:
93+
version:
94+
- ${{ needs.getBaseVersion.outputs.maxVersion }}
95+
steps:
96+
- name: Checkout
97+
uses: actions/checkout@v2
98+
99+
- name: Install Python
100+
uses: actions/setup-python@v2
101+
102+
- name: Install Terraform v${{ matrix.version }}
103+
uses: hashicorp/setup-terraform@v1
104+
with:
105+
terraform_version: ${{ matrix.version }}
106+
107+
- name: Install pre-commit dependencies
108+
run: |
109+
pip install pre-commit
110+
pip install checkov
111+
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v0.12.1-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
112+
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/
113+
114+
- name: Execute pre-commit
115+
# Run all pre-commit checks on max version supported
116+
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
117+
run: pre-commit run --color=always --show-diff-on-failure --all-files

.github/workflows/security_scans.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ _testmain.go
8080
/test/times.out
8181

8282
# ignore test file(s)
83-
**test**
83+
**test**

.pre-commit-config.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
repos:
2+
- repo: git://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.48.0
4+
hooks:
5+
- id: terraform_fmt
6+
# - id: terraform_validate
7+
- id: terraform_tflint
8+
args:
9+
- '--args=--only=terraform_deprecated_interpolation'
10+
- '--args=--only=terraform_deprecated_index'
11+
# - '--args=--only=terraform_unused_declarations'
12+
- '--args=--only=terraform_comment_syntax'
13+
- '--args=--only=terraform_documented_outputs'
14+
- '--args=--only=terraform_documented_variables'
15+
- '--args=--only=terraform_typed_variables'
16+
- '--args=--only=terraform_module_pinned_source'
17+
- '--args=--only=terraform_naming_convention'
18+
- '--args=--only=terraform_required_providers'
19+
# - '--args=--only=terraform_standard_module_structure'
20+
- '--args=--only=terraform_workspace_remote'
21+
22+
- repo: https://github.com/pre-commit/pre-commit-hooks
23+
rev: v3.2.0
24+
hooks:
25+
- id: trailing-whitespace
26+
- id: check-merge-conflict
27+
- id: end-of-file-fixer
28+
- id: check-yaml
29+
30+
- repo: https://github.com/bridgecrewio/checkov.git
31+
rev: '1.0.864' # change to tag or sha
32+
hooks:
33+
- id: checkov
34+
verbose: true
35+
args:
36+
- -d . --framework terraform -o output_format json

README.md

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<p align="center">
2-
<a href="https://github.com/tomarv2/terraform-databricks-workspace/actions/workflows/security_scans.yml" alt="Security Scans">
3-
<img src="https://github.com/tomarv2/terraform-databricks-workspace/actions/workflows/security_scans.yml/badge.svg?branch=main" /></a>
2+
<a href="https://github.com/tomarv2/terraform-databricks-aws-workspace/actions/workflows/pre-commit.yml" alt="Precommit">
3+
<img src="https://github.com/tomarv2/terraform-databricks-aws-workspace/actions/workflows/pre-commit.yml/badge.svg?branch=main" /></a>
44
<a href="https://www.apache.org/licenses/LICENSE-2.0" alt="license">
5-
<img src="https://img.shields.io/github/license/tomarv2/terraform-databricks-workspace" /></a>
6-
<a href="https://github.com/tomarv2/terraform-databricks-workspace/tags" alt="GitHub tag">
7-
<img src="https://img.shields.io/github/v/tag/tomarv2/terraform-databricks-workspace" /></a>
8-
<a href="https://github.com/tomarv2/terraform-databricks-workspace/pulse" alt="Activity">
9-
<img src="https://img.shields.io/github/commit-activity/m/tomarv2/terraform-databricks-workspace" /></a>
5+
<img src="https://img.shields.io/github/license/tomarv2/terraform-databricks-aws-workspace" /></a>
6+
<a href="https://github.com/tomarv2/terraform-databricks-aws-workspace/tags" alt="GitHub tag">
7+
<img src="https://img.shields.io/github/v/tag/tomarv2/terraform-databricks-aws-workspace" /></a>
8+
<a href="https://github.com/tomarv2/terraform-databricks-aws-workspace/pulse" alt="Activity">
9+
<img src="https://img.shields.io/github/commit-activity/m/tomarv2/terraform-databricks-aws-workspace" /></a>
1010
<a href="https://stackoverflow.com/users/6679867/tomarv2" alt="Stack Exchange reputation">
1111
<img src="https://img.shields.io/stackexchange/stackoverflow/r/6679867"></a>
1212
<a href="https://discord.gg/XH975bzN" alt="chat on Discord">
@@ -15,38 +15,38 @@
1515
<img src="https://img.shields.io/twitter/follow/varuntomar2019?style=social&logo=twitter"></a>
1616
</p>
1717

18-
# Terraform module for Databricks Workspace E2 (Part 1)
18+
# Terraform module for [Databricks AWS Workspace E2 (Part 1)](https://registry.terraform.io/providers/databrickslabs/databricks/latest/docs/guides/aws-workspace)
1919

20-
> ❗️ **Important**
21-
>
20+
> ❗️ **Important**
21+
>
2222
> :point_right: This Terraform module assumes you have, access to: [https://accounts.cloud.databricks.com](https://accounts.cloud.databricks.com)
23-
>
23+
>
2424
> :point_right: Databricks account username: `databricks_account_username`
2525
>
26-
> :point_right: Databricks account password: `databricks_account_password`
27-
>
26+
> :point_right: Databricks account password: `databricks_account_password`
27+
>
2828
> :point_right: Databricks account id, `databricks_account_id` can be found on the top right corner of the page, once you're logged in.
2929
>
30-
> :point_right: Part 2: Terraform module for [Databricks Workspace management](https://github.com/tomarv2/terraform-databricks-workspace-management)
30+
> :point_right: Part 2: Terraform module for [Databricks Workspace management](https://github.com/tomarv2/terraform-databricks-aws-workspace-management)
3131
3232
## Versions
3333

3434
- Module tested for Terraform 0.14.
3535
- `databrickslabs/databricks` provider version [0.3.1](https://registry.terraform.io/providers/databrickslabs/databricks/latest)
3636
- AWS provider version [3.29.0](https://registry.terraform.io/providers/hashicorp/aws/latest)
3737
- `main` branch: Provider versions not pinned to keep up with Terraform releases
38-
- `tags` releases: Tags are pinned with versions (use <a href="https://github.com/tomarv2/terraform-databricks-workspace/tags" alt="GitHub tag">
39-
<img src="https://img.shields.io/github/v/tag/tomarv2/terraform-databricks-workspace" /></a> in your releases)
38+
- `tags` releases: Tags are pinned with versions (use <a href="https://github.com/tomarv2/terraform-databricks-aws-workspace/tags" alt="GitHub tag">
39+
<img src="https://img.shields.io/github/v/tag/tomarv2/terraform-databricks-aws-workspace" /></a> in your releases)
4040

41-
**NOTE:**
41+
**NOTE:**
4242

4343
- Read more on [tfremote](https://github.com/tomarv2/tfremote)
4444

4545
## Usage
4646

4747
Recommended method:
4848

49-
- Create python 3.6+ virtual environment
49+
- Create python 3.6+ virtual environment
5050
```
5151
python3 -m venv <venv name>
5252
```
@@ -61,9 +61,9 @@ pip install tfremote
6161
export TF_AWS_BUCKET=<remote state bucket name>
6262
export TF_AWS_PROFILE=default
6363
export TF_AWS_BUCKET_REGION=us-west-2
64-
```
64+
```
6565

66-
- Updated `examples` directory to required values.
66+
- Updated `examples` directory to required values.
6767

6868
- Run and verify the output before deploying:
6969
```
@@ -95,7 +95,7 @@ tf -cloud aws destroy -var='teamid=foo' -var='prjid=bar'
9595
9696
```
9797
module "databricks_workspace" {
98-
source = "git::git@github.com:tomarv2/terraform-databricks-workspace.git?ref=v0.0.1"
98+
source = "git::git@github.com:tomarv2/terraform-databricks-aws-workspace.git?ref=v0.0.1"
9999
100100
profile_for_iam = "iam-admin"
101101
databricks_account_username = "example@example.com"
@@ -110,8 +110,6 @@ module "databricks_workspace" {
110110

111111
Please refer to examples directory [link](examples) for references.
112112

113-
### Read more: [link](https://registry.terraform.io/providers/databrickslabs/databricks/latest/docs/guides/aws-workspace)
114-
115113
## Troubleshooting:
116114

117115
### IAM policy error
@@ -124,10 +122,8 @@ Error: MALFORMED_REQUEST: Failed credentials validation checks: Spot Cancellatio
124122

125123
- Try creating workspace from UI:
126124

127-
![create_workspace_error](https://github.com/tomarv2/terraform-databricks-workspace/raw/main/docs/images/create_workspace_error.png)
125+
![create_workspace_error](https://github.com/tomarv2/terraform-databricks-aws-workspace/raw/main/docs/images/create_workspace_error.png)
128126

129127
- Verify if the role and policy exists (assume role should allow external id)
130128

131-
![iam_role_trust_error](https://github.com/tomarv2/terraform-databricks-workspace/raw/main/docs/images/iam_role_trust_error.png)
132-
133-
129+
![iam_role_trust_error](https://github.com/tomarv2/terraform-databricks-aws-workspace/raw/main/docs/images/iam_role_trust_error.png)

examples/sample/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ module "databricks_workspace" {
99
# Do not change the teamid, prjid once set.
1010
teamid = var.teamid
1111
prjid = var.prjid
12-
}
12+
}
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,17 @@ output "storage_configuration_id" {
2323
value = module.databricks_workspace.databricks_mws_storage_id
2424
}
2525

26-
//output "databricks_dapi" {
27-
// description = "databricks dapi"
28-
// value = module.databricks_workspace.databricks_dapi
29-
//}
30-
3126
output "databricks_host" {
32-
value = module.databricks_workspace.workspace_url
27+
description = "databricks workspace url"
28+
value = module.databricks_workspace.workspace_url
3329
}
3430

3531
output "databricks_credentials_id" {
36-
value = module.databricks_workspace.databricks_credentials_id
32+
description = "databricks credentials id"
33+
value = module.databricks_workspace.databricks_credentials_id
3734
}
3835

3936
output "databricks_deployment_name" {
40-
value = module.databricks_workspace.databricks_deployment_name
37+
description = "databricks deployment name"
38+
value = module.databricks_workspace.databricks_deployment_name
4139
}

examples/sample/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
variable "teamid" {
22
description = "(Required) Name of the team/group e.g. devops, dataengineering. Should not be changed after running 'tf apply'"
3+
type = string
34
}
45

56
variable "prjid" {
67
description = "(Required) Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply'"
8+
type = string
79
}

examples/test/output.tf

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)