Skip to content

Commit 46f1272

Browse files
Tf pipeline (#21)
* update of pipeline * adding manual trigger * Reformat terraform files (#22) * terraform fmt * add newline at EOF * add newline at EOF --------- Co-authored-by: steled <steled@users.noreply.github.com> Co-authored-by: steled <steled@gmx.net> * tflint fix * working-dir fix * adding tf docs section * terraform-docs: automated action * Reformat terraform files (#23) * terraform fmt * add newline at EOF * add newline at EOF * terraform fmt --------- Co-authored-by: steled <steled@users.noreply.github.com> Co-authored-by: steled <steled@gmx.net> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: steled <steled@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5cb7cbf commit 46f1272

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+466
-357
lines changed

.github/workflows/terraform.yml

Lines changed: 69 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,90 @@
11
name: 'Terraform'
22

3+
# Controls when the workflow will run
34
on:
5+
workflow_dispatch:
6+
# Triggers the workflow on push (only for the "main" branch) or pull request events
47
push:
58
branches:
69
- main
710
pull_request:
811

9-
# env:
10-
# TF_VER: 1.2.8
12+
# if a new commit is pushed to the main branch while a previous run is still in progress, the previous run will be cancelled and the new one will start
13+
concurrency:
14+
group: ci-${{ github.ref }}
15+
cancel-in-progress: true
1116

1217
jobs:
13-
terraform:
14-
name: 'Terraform'
15-
runs-on: ubuntu-latest
18+
tffmt:
1619
permissions:
20+
contents: write
1721
pull-requests: write
22+
runs-on: ubuntu-latest
1823

1924
steps:
20-
- name: Checkout
21-
uses: actions/checkout@v4
25+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26+
- name: Checkout
27+
uses: actions/checkout@v4
2228

23-
- name: Setup Terraform
24-
uses: hashicorp/setup-terraform@v3
25-
# with:
26-
# terraform_version: $TF_VER
29+
- name: terraform fmt
30+
uses: dflook/terraform-fmt@v1
31+
with:
32+
path: .
2733

28-
- name: Terraform Format
29-
id: fmt
30-
run: terraform fmt -check -recursive
31-
continue-on-error: true
34+
- name: Create Pull Request
35+
uses: peter-evans/create-pull-request@v5
36+
with:
37+
commit-message: terraform fmt
38+
title: Reformat terraform files
39+
body: Update Terraform files to canonical format using `terraform fmt`
40+
branch: automated-terraform-fmt
41+
base: ${{ github.head_ref }}
42+
43+
tflint:
44+
runs-on: ubuntu-latest
3245

33-
# - name: Terraform Init
34-
# id: init
35-
# run: terraform init
46+
steps:
47+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
48+
- name: Checkout source code
49+
uses: actions/checkout@v4
3650

37-
- uses: actions/github-script@v7
38-
if: github.event_name == 'pull_request'
51+
- name: Cache plugin dir
52+
uses: actions/cache@v4
3953
with:
40-
github-token: ${{ secrets.GITHUB_TOKEN }}
41-
script: |
42-
// 1. Retrieve existing bot comments for the PR
43-
const { data: comments } = await github.rest.issues.listComments({
44-
owner: context.repo.owner,
45-
repo: context.repo.repo,
46-
issue_number: context.issue.number,
47-
})
48-
const botComment = comments.find(comment => {
49-
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
50-
})
51-
52-
// 2. Prepare format of the comment
53-
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
54+
path: ~/.tflint.d/plugins
55+
key: tflint-${{ hashFiles('.tflint.hcl') }}
56+
57+
- name: Setup TFLint
58+
uses: terraform-linters/setup-tflint@v4
59+
60+
- name: Show version
61+
run: tflint --version
5462

55-
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
63+
- name: Init TFLint
64+
env:
65+
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting
66+
GITHUB_TOKEN: ${{ github.token }}
67+
run: tflint --recursive --init
5668

57-
// 3. If we have a comment, update it, otherwise create a new one
58-
if (botComment) {
59-
github.rest.issues.updateComment({
60-
owner: context.repo.owner,
61-
repo: context.repo.repo,
62-
comment_id: botComment.id,
63-
body: output
64-
})
65-
} else {
66-
github.rest.issues.createComment({
67-
issue_number: context.issue.number,
68-
owner: context.repo.owner,
69-
repo: context.repo.repo,
70-
body: output
71-
})
72-
}
69+
- name: Run TFLint
70+
run: tflint --recursive --call-module-type=all
71+
72+
tfdocs:
73+
permissions:
74+
contents: write
75+
runs-on: ubuntu-latest
76+
77+
steps:
78+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
79+
- name: Checkout source code
80+
uses: actions/checkout@v4
81+
with:
82+
ref: ${{ github.event.pull_request.head.ref }}
83+
84+
- name: Render terraform docs inside the README.md and push changes back to PR branch
85+
uses: terraform-docs/gh-actions@v1.3.0
86+
with:
87+
working-dir: .
88+
output-file: README.md
89+
output-method: inject
90+
git-push: "true"

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
11
# terraformmodules
2+
3+
4+
# TF Docs
5+
6+
<!-- BEGIN_TF_DOCS -->
7+
## Requirements
8+
9+
No requirements.
10+
11+
## Providers
12+
13+
No providers.
14+
15+
## Modules
16+
17+
No modules.
18+
19+
## Resources
20+
21+
No resources.
22+
23+
## Inputs
24+
25+
No inputs.
26+
27+
## Outputs
28+
29+
No outputs.
30+
<!-- END_TF_DOCS -->

cert-manager_cloudflare/cert-manager.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ resource "kubernetes_namespace" "certmanager" {
55
}
66

77
resource "helm_release" "certmanager" {
8-
name = "cert-manager"
9-
namespace = kubernetes_namespace.certmanager.metadata[0].name
8+
name = "cert-manager"
9+
namespace = kubernetes_namespace.certmanager.metadata[0].name
1010

1111
repository = "https://charts.jetstack.io"
1212
chart = "cert-manager"
1313
version = var.cert_manager_version # check version here: https://artifacthub.io/packages/helm/cert-manager/cert-manager/
1414

1515
set {
16-
name = "installCRDs"
16+
name = "installCRDs"
1717
value = "true"
1818
}
1919

@@ -22,5 +22,5 @@ resource "helm_release" "certmanager" {
2222
command = "kubectl delete crd certificaterequests.cert-manager.io certificates.cert-manager.io challenges.acme.cert-manager.io clusterissuers.cert-manager.io issuers.cert-manager.io orders.acme.cert-manager.io"
2323
}
2424

25-
depends_on = [ kubernetes_secret.cloudflare_api_token_secret ]
25+
depends_on = [kubernetes_secret.cloudflare_api_token_secret]
2626
}

cert-manager_cloudflare/clusterissuer_selfsigned.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spec:
88
selfSigned: {}
99
YAML
1010

11-
depends_on = [ helm_release.certmanager ]
11+
depends_on = [helm_release.certmanager]
1212
}
1313

1414
resource "kubectl_manifest" "cert_manager_certificate_steled_selfsigned_ca" {

cert-manager_cloudflare/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ terraform {
77
version = "~> 2.16.1"
88
}
99
kubernetes = {
10-
source = "hashicorp/kubernetes"
10+
source = "hashicorp/kubernetes"
1111
version = "~> 2.35.0"
1212
}
1313
kubectl = {

cert-manager_cloudflare/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
variable "cert_manager_version" {
2-
type = string
2+
type = string
33
description = "Set the version of cert-manager"
44
}
55

@@ -12,6 +12,6 @@ variable "cert_manager_email" {
1212
}
1313

1414
variable "namespace" {
15-
type = string
15+
type = string
1616
description = "Name of the kubernetes namespace"
1717
}

cert-manager_duckdns/cert-manager.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ resource "kubernetes_namespace" "certmanager" {
55
}
66

77
resource "helm_release" "certmanager" {
8-
name = "cert-manager"
9-
namespace = kubernetes_namespace.certmanager.metadata[0].name
8+
name = "cert-manager"
9+
namespace = kubernetes_namespace.certmanager.metadata[0].name
1010

1111
repository = "https://charts.jetstack.io"
1212
chart = "cert-manager"
1313
version = var.cert_manager_version # check version here: https://artifacthub.io/packages/helm/cert-manager/cert-manager/
1414

1515
set {
16-
name = "installCRDs"
16+
name = "installCRDs"
1717
value = "true"
1818
}
1919
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
resource "helm_release" "duckdns_webhook" {
22
# name = "cert-manager-webhook-duckdns"
3-
name = "cert-manager-duckdns-webhook"
4-
namespace = kubernetes_namespace.certmanager.metadata[0].name
3+
name = "cert-manager-duckdns-webhook"
4+
namespace = kubernetes_namespace.certmanager.metadata[0].name
55

66
# repository = "https://steled.github.io/cert-manager-webhook-duckdns/"
77
repository = "https://csp33.github.io/cert-manager-duckdns-webhook"
88
# chart = "cert-manager-webhook-duckdns"
9-
chart = "cert-manager-duckdns-webhook"
10-
version = var.duckdns_webhook_version # check version here: https://github.com/steled/cert-manager-webhook-duckdns/blob/master/charts/cert-manager-webhook-duckdns/Chart.yaml#L4
9+
chart = "cert-manager-duckdns-webhook"
10+
version = var.duckdns_webhook_version # check version here: https://github.com/steled/cert-manager-webhook-duckdns/blob/master/charts/cert-manager-webhook-duckdns/Chart.yaml#L4
1111

1212
# values = [ templatefile(var.duckdns_webhook_values_yaml, {
1313
# duckdns_webhook_ip_address = var.duckdns_webhook_ip_address
1414
# })]
1515

16-
values = [ file(var.duckdns_webhook_values_yaml) ]
16+
values = [file(var.duckdns_webhook_values_yaml)]
1717

18-
depends_on = [ helm_release.certmanager ]
18+
depends_on = [helm_release.certmanager]
1919
}

cert-manager_duckdns/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ terraform {
77
version = ">= 2.9.0"
88
}
99
kubernetes = {
10-
source = "hashicorp/kubernetes"
10+
source = "hashicorp/kubernetes"
1111
version = "~> 2.35.0"
1212
}
1313
}

cert-manager_duckdns/variables.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
variable "namespace" {
2-
type = string
2+
type = string
33
description = "Name of the kubernetes namespace"
44
}
55

66
variable "cert_manager_version" {
7-
type = string
7+
type = string
88
description = "Set the version of cert-manager"
99
}
1010

1111
variable "duckdns_webhook_version" {
12-
type = string
12+
type = string
1313
description = "Set the version of duckdns webhook"
1414
}
1515

1616
variable "duckdns_webhook_values_yaml" {
17-
type = string
17+
type = string
1818
description = "Path to the duckdns webhook values.yml file, relative to the root module"
1919
}
2020

21-
variable "duckdns_webhook_ip_address" {
22-
type = string
23-
description = "IP address for duckdns webhook service"
24-
}
21+
# variable "duckdns_webhook_ip_address" {
22+
# type = string
23+
# description = "IP address for duckdns webhook service"
24+
# }

0 commit comments

Comments
 (0)