Skip to content

Commit

Permalink
refactor: cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
caerulescens committed Sep 9, 2024
1 parent 9e78c95 commit 4cc7fcb
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 217 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/2-BUG-REPORT.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ body:
validations:
required: true

# Terraform Version
# Tofu Version
- type: textarea
id: terraform-version
id: tofu-version
attributes:
label: "Terraform version"
description: Which terraform version were you using?
label: "Tofu version"
description: Which tofu version were you using?
placeholder: e.g. '1.8.5'
validations:
required: true
Expand Down
64 changes: 0 additions & 64 deletions .github/actions/terraform-init/action.yaml

This file was deleted.

64 changes: 64 additions & 0 deletions .github/actions/tofu-init/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Tofu Init
description: Run `tofu init` with optional caching

inputs:
args:
description: Arguments for `tofu init`
tofu-version:
description: Desired semver compatible Tofu version
required: true
cache:
description: Enable caching tofu project files
default: 'true'

outputs:
tofu-version:
description: The Tofu version setup
value: ${{ steps.version-tofu.outputs.tofu-version }}
cache-hit:
description: Whether an exact cache hit occurred
value: ${{ steps.cache.outputs.cache-hit }}

runs:
using: composite
steps:
- name: Setup Tofu
id: setup-tofu
uses: opentofu/setup-opentofu@v1
with:
tofu_version: ${{ inputs.tofu-version }}

- name: Get Version
id: version-tofu
run: printf 'tofu-version=%s\n' "$(tofu version -json | jq -r '.opentofu_version')" >> $GITHUB_OUTPUT
shell: bash

- run: printf 'date=%s\n' "$(date -I)" >> $GITHUB_OUTPUT
id: get-date
if: inputs.cache == 'true'
shell: bash

- name: Configure Plugin Cache Directory
id: cache-config
if: inputs.cache == 'true'
run: |
echo 'plugin_cache_dir="~/.terraform.d/plugin-cache"' > ~/.terraformrc
mkdir -p ~/.terraform.d/plugin-cache
shell: bash

- uses: actions/cache@v4
name: Cache Tofu Plugins
id: cache-tofu
if: inputs.cache == 'true'
with:
path: |
~/.terraform.d/plugin-cache
key: tofu-${{ steps.get-date.outputs.date }}-${{ runner.os }}-${{ hashFiles('.terraform.lock.hcl') }}
restore-keys: |
tofu-${{ steps.get-date.outputs.date }}-${{ runner.os }}-
tofu-${{ steps.get-date.outputs.date }}-
- name: Init Tofu
id: init-tofu
run: tofu init ${{ inputs.args }}
shell: bash
14 changes: 7 additions & 7 deletions .github/workflows/.tests-matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
runner:
required: true
type: string
terraform-version:
tofu-version:
required: true
type: string
tflint-version:
Expand All @@ -24,7 +24,7 @@ defaults:
jobs:

tflint:
name: Lint Terraform
name: Lint Tofu
runs-on: ${{ inputs.runner }}
if: inputs.run-tflint
steps:
Expand All @@ -36,7 +36,7 @@ jobs:
restore-keys: |
tflint-${{ inputs.runner }}-
- uses: terraform-linters/setup-tflint@v4
- uses: Tofu-linters/setup-tflint@v4
name: Setup TFLint
with:
tflint_version: ${{ inputs.tflint-version }}
Expand All @@ -50,14 +50,14 @@ jobs:
run: tflint -f compact

tftest:
name: Test Terraform
name: Test Tofu
runs-on: ${{ inputs.runner }}
if: inputs.run-tftest
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/terraform-init
- uses: ./.github/actions/tofu-init
with:
terraform-version: ${{ inputs.terraform-version }}
tofu-version: ${{ inputs.tofu-version }}

- run: terraform test
- run: tofu test
14 changes: 7 additions & 7 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ jobs:
name: Validate Configuration
runs-on: ubuntu-latest
outputs:
terraform-version: ${{ steps.terraform-init.outputs.terraform-version }}
tofu-version: ${{ steps.tofu-init.outputs.tofu-version }}
if: needs.changes.outputs.project == 'true'
needs:
- changes
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/terraform-init
id: terraform-init
- uses: ./.github/actions/tofu-init
id: tofu-init
with:
args: '-backend=false'
terraform-version: "latest"
tofu-version: "latest"

- run: terraform validate
- run: tofu validate

tests-matrix:
uses: ./.github/workflows/.tests-matrix.yaml
name: "${{ matrix.os.name }} (Terraform ${{ needs.validate.outputs.terraform-version }})"
name: "${{ matrix.os.name }} (Tofu ${{ needs.validate.outputs.tofu-version }})"
if: '!failure()'
needs:
- changes
Expand All @@ -83,7 +83,7 @@ jobs:
fail-fast: false
with:
runner: ${{ matrix.os.image }}
terraform-version: "latest"
tofu-version: "latest"
tflint-version: "latest"
run-tflint: ${{ needs.changes.outputs.tests == 'true' }}
run-tftest: ${{ needs.changes.outputs.tests == 'true' }}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
rev: v0.17.0
hooks:
- id: terraform-docs-docker
args: ["--output-file", "README.terraform.md", "."]
args: ["--output-file", "README.tofu.md", "."]

- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.22
Expand Down
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# tofu-module-minikube
# Demo: tofu-module-minikube

A [`tofu`](https://github.com/opentofu/opentofu) module for [`minikube`](https://github.com/kubernetes/minikube).

## Install

| Name |
|----------------------------------------------------|
| [minikube](https://github.com/kubernetes/minikube) |
| [tofu](https://github.com/opentofu/opentofu) |

## Usage

Configure:
```shell
cat <<EOF > terraform.tfvars
minikube_clusters = {
"minikube": {
"driver": "docker",
}
}
EOF
```

Run:
```shell
tofu init
tofu plan
tofu apply
```

Test:
```shell
tofu test
```

Check:
```shell
pre-commit run
```
1 change: 0 additions & 1 deletion modules/minikube_cluster/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions modules/minikube_cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ terraform {
}
}

# todo: 'auto_pause_interval' missing completions?
# todo: 'gpus' missing completions?
# todo: 'output' missing completion?
resource "minikube_cluster" "default" {
addons = var.addons
apiserver_ips = var.apiserver_ips
Expand Down
10 changes: 5 additions & 5 deletions modules/minikube_cluster/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
output "client_certificate" {
value = minikube_cluster.default.client_certificate
description = "Cluster client certificate"
description = "Client certificate used in cluster"
sensitive = true
}

output "client_key" {
value = minikube_cluster.default.client_key
description = "Cluster client key"
description = "Client key for cluster"
sensitive = true
}

output "cluster_ca_certificate" {
value = minikube_cluster.default.cluster_ca_certificate
description = "Cluster certificate authority certificate"
description = "Certificate authority for cluster"
sensitive = true
}

output "host" {
value = minikube_cluster.default.host
description = "Cluster host"
description = "The host name for the cluster"
}

output "id" {
value = minikube_cluster.default.id
description = "Cluster resource ID"
description = "The ID of this resource"
}
Loading

0 comments on commit 4cc7fcb

Please sign in to comment.