Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add GitHub workflows #1

Merged
merged 3 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{ range .Versions }}
<a name="{{ .Tag.Name }}">Release {{ .Tag.Name }}</a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})

{{ range .CommitGroups -}}
### {{ .Title }}

{{ range .Commits -}}
* {{ .Subject }}
{{ end }}
{{ end -}}

{{- if .RevertCommits -}}
### Reverts

{{ range .RevertCommits -}}
* {{ .Revert.Header }}
{{ end }}
{{ end -}}

{{- if .MergeCommits -}}
### Pull Requests

{{ range .MergeCommits -}}
* {{ .Header }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}

{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}
30 changes: 30 additions & 0 deletions .chglog/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/rendler-denis/tf-mod-netbox
options:
commits:
filters:
Type:
- feat
- fix
- perf
- refactor
- docs
commit_groups:
title_maps:
feat: Features
fix: Bug Fixes
perf: Performance Improvements
refactor: Code Refactoring
docs: Documentation
header:
pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
pattern_maps:
- Type
- Scope
- Subject
notes:
keywords:
- BREAKING CHANGE
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE/00-bug-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Bug Issue
about: Use this template for reporting a bug
labels: 'type:bug'

---

<em>Please first make sure that this is a bug in the module and not an issue
with the provider used.</em>

**System information**
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
- Terraform/OpenTofu version:
- Provider name and version:

**Describe the current behavior**

**Describe the expected behavior**

**Steps to reproduce the issue**

**Other info / logs**
Include any logs or source code that would be helpful to
diagnose the problem.
Since this is an open forum please make sure to obfuscate any sensitive information.
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/01-feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Feature Request
about: Use this template for raising a feature request
labels: 'type:feature'

---

<em>Please make sure that this is a feature request.</em>

**Basic information**
- Terraform/OpenTofu version you are using:
- Are you willing to develop and contribute the feature (Yes/No):

**Describe the feature and the current behavior/state.**

**Who will benefit with this feature?**

**Any Other info.**
51 changes: 51 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Module Changelog

on:
push:
branches: [ main ]

# it is required to be able to push back to the repository
permissions:
contents: write

jobs:
create-changelog:
runs-on: ubuntu-latest
# Add this condition to prevent an infinite loop
if: ${{ !contains(github.event.head_commit.message, 'Add changelog') }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Extract version from PR title
id: version
run: |
PR_TITLE="${{ github.event.head_commit.message }}"
echo "Processing PR title: $PR_TITLE"

# Take only the first version number found
VERSION=$(echo "$PR_TITLE" | grep -oE "version: [0-9]+\.[0-9]+\.[0-9]+" | head -n 1 | cut -d' ' -f2)

if [ ! -z "$VERSION" ]; then
echo "Found version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
else
echo "No version found in PR title"
exit 0
fi

- name: Generate changelog
if: steps.version.outputs.version != ''
run: "docker run --rm -v ${GITHUB_WORKSPACE}:/workdir -w /workdir quay.io/git-chglog/git-chglog:latest --next-tag ${{ steps.version.outputs.version }} -o CHANGELOG.md"

- name: Create commit with changelog
if: steps.version.outputs.version != ''
run: |
git config user.name "Denis Rendler (GitHub Actions)"
git config user.email "connect@rendler.net"
git add CHANGELOG.md
git commit -m "Add changelog"
git push origin main
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Create Release Package

on:
push:
tags:
- '*' # Triggers on version tags like 1.0.0

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write # Needed for creating releases

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetches complete history for accurate changelog

# Create release archive
- name: Create release archive
run: |
# Exclude unnecessary files from the archive
mkdir release && \
tar --exclude='.git' \
--exclude='.github' \
--exclude='test' \
--exclude='.gitignore' \
--exclude='.chglog' \
--exclude='release' \
-czf release/release-${{ github.ref_name }}.tar.gz .

# Create the GitHub release
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body_path: CHANGELOG.md
files: |
release-${{ github.ref_name }}.tar.gz
draft: false
prerelease: false
55 changes: 55 additions & 0 deletions .github/workflows/tflint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'TFLint Check'

on:
push:
paths:
- '**.tf'
- '.github/workflows/tflint.yml'
pull_request:
paths:
- '**.tf'
- '.github/workflows/tflint.yml'

jobs:
tflint:
name: 'TFLint'
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup TFLint
uses: terraform-linters/setup-tflint@v4
with:
tflint_version: latest

- name: Initialize TFLint
run: tflint --init

- name: Find Terraform directories
id: find_dirs
run: |
echo "terraform_dirs<<EOF" >> $GITHUB_OUTPUT
find . -type f -name "*.tf" -exec dirname {} \; | sort -u >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Run TFLint recursively
run: |
EXIT_CODE=0
while IFS= read -r dir; do
echo "Running TFLint in directory: $dir"
pushd "$dir" > /dev/null

# Initialize TFLint in each directory
tflint --init

# Run TFLint and store its exit code
if ! tflint --format compact -c ../.tflint.hcl; then
EXIT_CODE=1
fi

popd > /dev/null
done <<< "$(echo "${{ steps.find_dirs.outputs.terraform_dirs }}")"

exit $EXIT_CODE
3 changes: 3 additions & 0 deletions .tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

// disable terraform required version
rule "terraform_required_version" { enabled = false }
7 changes: 4 additions & 3 deletions netbox-customization/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
terraform {
required_providers {
netbox = {
source = "e-breuninger/netbox"
source = "e-breuninger/netbox"
version = "= 3.9.2"
}
}
}
Expand Down Expand Up @@ -57,14 +58,14 @@ resource "netbox_custom_field" "custom_fields" {
resource "netbox_tag" "custom_tags" {
for_each = var.custom_tags

name = each.value.name
name = each.value.name

color_hex = try(each.value.color_hex, "9e9e9e")
slug = try(each.value.slug, null)
description = try(each.value.description, null)

lifecycle {
ignore_changes = [ tags ]
ignore_changes = [tags]
}
}

Expand Down
2 changes: 1 addition & 1 deletion netbox-customization/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

output "managed_customizations" {
description = "Managed customizations"
value = {
value = {
custom_fields = {
for custom_field in netbox_custom_field.custom_fields :
custom_field.name => {
Expand Down
23 changes: 12 additions & 11 deletions netbox-data-org/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
terraform {
required_providers {
netbox = {
source = "e-breuninger/netbox"
source = "e-breuninger/netbox"
version = "=3.9.2"
}
}
}
Expand All @@ -18,25 +19,25 @@ data "netbox_site" "sites" {
}

data "netbox_tenant" "tenants" {
for_each = toset(var.tenants)
name = each.value
for_each = toset(var.tenants)
name = each.value
}

data "netbox_location" "locations" {
for_each = toset(var.locations)
name = each.value
for_each = toset(var.locations)
name = each.value
}

data "netbox_region" "regions" {
for_each = toset(var.regions)
for_each = toset(var.regions)

filter {
name = each.value
}
filter {
name = each.value
}
}

data "netbox_site_group" "site_groups" {
for_each = toset(var.site_groups)
name = each.value
for_each = toset(var.site_groups)
name = each.value
}
# ######## END LOOKUPS ############
10 changes: 5 additions & 5 deletions netbox-data-org/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@

output "sites_map" {
description = "Map of site names to their IDs"
value = {
value = {
for name, site in data.netbox_site.sites : name => site.id
}
}

output "tenants_map" {
description = "Map of tenant names to their IDs"
value = {
value = {
for name, tenant in data.netbox_tenant.tenants : name => tenant.id
}
}

output "locations_map" {
description = "Map of location names to their IDs"
value = {
value = {
for name, location in data.netbox_location.locations : name => location.id
}
}

output "regions_map" {
description = "Map of region names to their IDs"
value = {
value = {
for name, region in data.netbox_region.regions : name => region.id
}
}

output "site_groups_map" {
description = "Map of site group names to their IDs"
value = {
value = {
for name, site_group in data.netbox_site_group.site_groups : name => site_group.id
}
}
Loading
Loading