Skip to content

Commit 31f1dcf

Browse files
authored
Added pre-commit hook (#11)
* Added pre-commit hook pre-commit fixes * pre-commit run fixes
1 parent d199a70 commit 31f1dcf

15 files changed

+91
-160
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ about: If something isn't working as expected.
2121
...version and build of the project, OS and runtime versions, virtualised environment (if any), etc. ...
2222

2323
### Additional Context:
24-
...add any other context about the problem here. If applicable, add screenshots to help explain...
24+
...add any other context about the problem here. If applicable, add screenshots to help explain...

.github/workflows/ci.yaml

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,19 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13+
pre-commit:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-python@v3
18+
- uses: terraform-linters/setup-tflint@v3
19+
- uses: pre-commit/action@v3.0.0
20+
with:
21+
extra_args: "-a"
22+
1323
validate:
1424
name: Validate
25+
needs: [pre-commit]
1526
runs-on: ubuntu-latest
1627
permissions:
1728
pull-requests: write
@@ -50,50 +61,26 @@ jobs:
5061
terraform init -backend=false -upgrade -reconfigure
5162
terraform validate
5263
53-
tflint:
54-
name: tflint
55-
runs-on: ubuntu-latest
56-
permissions:
57-
pull-requests: write
58-
needs: [validate]
59-
steps:
60-
- name: Checkout code
61-
uses: actions/checkout@v3
62-
- uses: actions/cache@v3
63-
name: Cache plugin dir
64-
with:
65-
path: ~/.tflint.d/plugins
66-
key: ${{ runner.os }}-tflint
67-
- uses: terraform-linters/setup-tflint@v3
68-
name: Setup TFLint
69-
with:
70-
github_token: ${{ github.token }}
71-
tflint_version: latest
72-
- name: Run TFLint
73-
run: |
74-
tflint --init
75-
tflint -f compact
76-
7764
tfsec:
7865
name: tfsec
7966
runs-on: ubuntu-latest
8067
permissions:
8168
pull-requests: write
8269
needs: [validate]
8370
steps:
84-
- name: Checkout code
85-
uses: actions/checkout@v3
86-
- name: tfsec
87-
uses: aquasecurity/tfsec-action@v1.0.2
88-
with:
89-
additional_args: "--force-all-dirs --concise-output --code-theme=dark"
90-
version: "latest"
71+
- name: Checkout code
72+
uses: actions/checkout@v3
73+
- name: tfsec
74+
uses: aquasecurity/tfsec-action@v1.0.2
75+
with:
76+
additional_args: "--force-all-dirs --concise-output --code-theme=dark"
77+
version: "latest"
9178

9279
caller-identity-check:
9380
if: contains(github.event_name, 'pull_request')
9481
runs-on: ubuntu-latest
9582
name: Return the IAM user
96-
needs: [validate, tflint, tfsec]
83+
needs: [validate, tfsec]
9784
permissions:
9885
contents: read
9986
id-token: write

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
repos:
2+
- repo: https://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.77.0
4+
hooks:
5+
- id: terraform_fmt
6+
- id: terraform_tflint
7+
- id: terraform_validate
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.4.0
10+
hooks:
11+
- id: check-case-conflict
12+
- id: check-merge-conflict
13+
- id: check-vcs-permalinks
14+
- id: check-yaml
15+
- id: end-of-file-fixer
16+
- id: trailing-whitespace

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ Project maintainers who do not follow or enforce the Code of Conduct in good fai
6262
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
6363

6464
[homepage]: http://contributor-covenant.org
65-
[version]: http://contributor-covenant.org/version/1/4/
65+
[version]: http://contributor-covenant.org/version/1/4/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This Terraform module enables you to configure GitLab Actions as an AWS IAM OIDC
77

88
- AWS Account(s) and credentials
99
- GitLab repository
10-
- Terraform >= 1.0.x
10+
- Terraform >= 1.x
1111
- Profit?
1212

1313
## Deployment / Usage

TERRAFORM.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
| Name | Version |
44
|------|---------|
5-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.0 |
5+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1 |
66
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4 |
77
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 4 |
88

99
## Providers
1010

1111
| Name | Version |
1212
|------|---------|
13-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.46.0 |
13+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.47.0 |
1414
| <a name="provider_tls"></a> [tls](#provider\_tls) | 4.0.4 |
1515

1616
## Modules

exmaples/complete/main.tf

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ provider "aws" {
55
module "gitlab_oidc" {
66
source = "../../"
77

8-
attach_admin_policy = true
9-
attach_read_only_policy = true
10-
create_oidc_provider = true
11-
enabled = true
12-
force_detach_policies = false
8+
attach_admin_policy = var.attach_admin_policy
9+
attach_read_only_policy = var.attach_read_only_policy
10+
create_oidc_provider = var.create_oidc_provider
11+
enabled = var.enabled
12+
force_detach_policies = var.force_detach_policies
1313
gitlab_organisation = var.gitlab_organisation
14-
gitlab_repositories = [{ name = "terraform-aws-gitlab-oidc", branches = ["main", "pr-*", "*pull*", "*"] }]
15-
iam_role_name = "gitlab-runner"
16-
iam_role_path = "/"
17-
iam_role_permissions_boundary = ""
18-
iam_role_policy_arns = []
19-
max_session_duration = 3600
20-
tags = {}
21-
url = "gitlab.com"
22-
}
14+
gitlab_repositories = var.gitlab_repositories
15+
iam_role_name = var.iam_role_name
16+
iam_role_path = var.iam_role_path
17+
iam_role_permissions_boundary = var.iam_role_permissions_boundary
18+
iam_role_policy_arns = var.iam_role_policy_arns
19+
max_session_duration = var.max_session_duration
20+
tags = var.tags
21+
url = var.url
22+
}

exmaples/complete/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ output "thumbprint" {
88
description = "GitLab certificates thumbprint"
99
value = module.gitlab_oidc.thumbprint
1010
sensitive = false
11-
}
11+
}

exmaples/complete/terraform.tfvars

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ enabled = true
55
force_detach_policies = false
66
gitlab_organisation = "saidsef"
77
gitlab_repositories = [
8-
{
9-
"branches" : null,
10-
"name" : null
8+
{ name = "terraform-aws-gitlab-oidc",
9+
branches = ["main", "pr-*", "*pull*", "*"]
1110
}
1211
]
1312
iam_role_name = "gitlab-runner"

exmaples/complete/versions.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = ">= 4"
6+
}
7+
8+
tls = {
9+
source = "hashicorp/tls"
10+
version = ">= 4"
11+
}
12+
}
13+
14+
required_version = "~> 1"
15+
}

exmaples/remote/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module "gitlab_oidc" {
1111
create_oidc_provider = true
1212
enabled = true
1313
force_detach_policies = false
14-
gitlab_organisation = var.gitlab_organisation
14+
gitlab_organisation = "saidsef"
1515
gitlab_repositories = [{ name = "terraform-aws-gitlab-oidc", branches = ["main", "pr-*", "*pull*", "*"] }]
1616
iam_role_name = "gitlab-runner"
1717
iam_role_path = "/"
@@ -20,4 +20,4 @@ module "gitlab_oidc" {
2020
max_session_duration = 3600
2121
tags = {}
2222
url = "gitlab.com"
23-
}
23+
}

exmaples/remote/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ output "thumbprint" {
88
description = "GitLab certificates thumbprint"
99
value = module.gitlab_oidc.thumbprint
1010
sensitive = false
11-
}
11+
}

exmaples/remote/variables.tf

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,104 +3,3 @@ variable "region" {
33
description = "AWS Region name"
44
type = string
55
}
6-
7-
variable "attach_admin_policy" {
8-
default = false
9-
description = "Enable attachment of the AdministratorAccess policy"
10-
type = bool
11-
}
12-
13-
variable "attach_read_only_policy" {
14-
default = true
15-
description = "Enable attachment of the ReadOnly policy"
16-
type = bool
17-
}
18-
19-
variable "create_oidc_provider" {
20-
default = true
21-
description = "Enable creation of the GitLab OIDC provider"
22-
type = bool
23-
}
24-
25-
variable "enabled" {
26-
default = true
27-
description = "Enable creation of resources"
28-
type = bool
29-
}
30-
31-
variable "force_detach_policies" {
32-
default = false
33-
description = "Force detachment of policies attached to the IAM role"
34-
type = string
35-
}
36-
37-
variable "gitlab_organisation" {
38-
default = "saidsef"
39-
description = "GitLab organisation name"
40-
type = string
41-
}
42-
43-
variable "gitlab_repositories" {
44-
type = list(object({
45-
name = string
46-
branches = list(string)
47-
}))
48-
default = [{
49-
branches = null
50-
name = null
51-
}]
52-
description = "List of GitLab repository name(s) and branche names or patterns"
53-
}
54-
55-
variable "iam_role_name" {
56-
default = "gitlab-runner"
57-
description = "Name of the IAM role"
58-
type = string
59-
}
60-
61-
variable "iam_role_path" {
62-
default = "/"
63-
description = "Path to the IAM role"
64-
type = string
65-
sensitive = false
66-
}
67-
68-
variable "iam_role_permissions_boundary" {
69-
default = ""
70-
description = "ARN of the permissions boundary to be used by the IAM role"
71-
type = string
72-
sensitive = false
73-
}
74-
75-
variable "iam_role_policy_arns" {
76-
default = []
77-
description = "List of IAM policy ARNs to attach to the IAM role"
78-
type = list(string)
79-
sensitive = false
80-
}
81-
82-
variable "max_session_duration" {
83-
default = 3600
84-
description = "Maximum session duration in seconds"
85-
type = number
86-
sensitive = false
87-
88-
validation {
89-
condition = var.max_session_duration >= 3600 && var.max_session_duration <= 43200
90-
error_message = "Session duration must be between 3600 and 43200 seconds."
91-
}
92-
}
93-
94-
variable "url" {
95-
type = string
96-
description = "URL of identity provider"
97-
default = "gitlab.com"
98-
sensitive = false
99-
}
100-
101-
variable "tags" {
102-
default = {}
103-
description = "Map of tags to be applied to all resources"
104-
type = map(string)
105-
sensitive = false
106-
}

exmaples/remote/versions.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = ">= 4"
6+
}
7+
8+
tls = {
9+
source = "hashicorp/tls"
10+
version = ">= 4"
11+
}
12+
}
13+
14+
required_version = "~> 1"
15+
}

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ terraform {
1212
}
1313

1414
required_version = "~> 1"
15-
}
15+
}

0 commit comments

Comments
 (0)