Skip to content

Commit fbb371c

Browse files
rglfrezbo
authored andcommitted
fix: talos_version nil parsing
Fix talos_version validation code. Signed-off-by: Noel Georgi <git@frezbo.dev> (cherry picked from commit 2ff68ba)
1 parent fbb8ed3 commit fbb371c

File tree

9 files changed

+74
-19
lines changed

9 files changed

+74
-19
lines changed

.github/workflows/acceptance-tests.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
name: acceptance-tests
2+
concurrency:
3+
group: ${{ github.head_ref || github.run_id }}
4+
cancel-in-progress: true
25
on:
36
pull_request:
47
paths:
58
- 'go.mod'
69
- 'go.sum'
710
- '**.go'
811
jobs:
9-
run-tests:
10-
runs-on: ubuntu-latest
12+
acc-tests:
13+
runs-on:
14+
- self-hosted
15+
- generic
16+
env:
17+
GOTOOLCHAIN: local
1118
steps:
1219
- name: Checkout
1320
uses: actions/checkout@v3

.github/workflows/pull-request.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ name: check-dirty
22
on:
33
pull_request:
44
jobs:
5-
run-tests:
6-
runs-on: ubuntu-latest
5+
check-dirty:
6+
runs-on:
7+
- self-hosted
8+
- generic
9+
env:
10+
GOTOOLCHAIN: local
711
steps:
812
- name: Checkout
913
uses: actions/checkout@v3

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ permissions:
1818
contents: write
1919
jobs:
2020
goreleaser:
21-
runs-on: ubuntu-latest
21+
runs-on:
22+
- self-hosted
23+
- generic
2224
steps:
2325
- name: Checkout
2426
uses: actions/checkout@v3

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug Talos Terraform Provider",
6+
"type": "go",
7+
"request": "launch",
8+
"mode": "debug",
9+
// this assumes your workspace is the root of the repo
10+
"program": "${workspaceFolder}",
11+
"env": {},
12+
"args": [
13+
"-debug",
14+
]
15+
}
16+
]
17+
}

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ testacc:
2424
check-dirty: generate ## Verifies that source tree is not dirty
2525
@if test -n "`git status --porcelain`"; then echo "Source tree is dirty"; git status; exit 1 ; fi
2626

27+
build-debug:
28+
go build -gcflags='all=-N -l'
29+
2730
install:
2831
go install .
2932

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
# terraform-provider-talos
22

3-
TODO: Validate after patching
4-
TODO: Ability to have variations of the baseline configuration (i.e. needing unique configuration files per machine)
3+
## Debugging
4+
5+
In a bash shell, build a debug version of this provider binary:
6+
7+
```bash
8+
make build-debug
9+
```
10+
11+
In Visual Studio Code, [start the provider in a debug session](https://developer.hashicorp.com/terraform/plugin/debugging#starting-a-provider-in-debug-mode).
12+
13+
In a new bash shell, go into your terraform project directory, and run
14+
terraform with `TF_REATTACH_PROVIDERS` set to the value printed in the VSCode debug windows.

internal/talos/talos_machine_configuration_data_source.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func (d talosMachineConfigurationDataSource) ValidateConfig(ctx context.Context,
343343
return
344344
}
345345

346-
if !state.KubernetesVersion.IsUnknown() && !state.KubernetesVersion.IsNull() {
346+
if !state.KubernetesVersion.IsUnknown() && !state.KubernetesVersion.IsNull() && !state.TalosVersion.IsUnknown() {
347347
k8sVersionCompatibility, err := compatibility.ParseKubernetesVersion(strings.TrimPrefix(state.KubernetesVersion.ValueString(), "v"))
348348
if err != nil {
349349
resp.Diagnostics.AddError(
@@ -354,18 +354,14 @@ func (d talosMachineConfigurationDataSource) ValidateConfig(ctx context.Context,
354354
return
355355
}
356356

357-
var talosVersionInfo *machineapi.VersionInfo
357+
talosVersionInfo := &machineapi.VersionInfo{}
358358

359-
if !state.TalosVersion.IsUnknown() && state.TalosVersion.IsNull() {
360-
talosVersionInfo = &machineapi.VersionInfo{
361-
Tag: gendata.VersionTag,
362-
}
359+
if state.TalosVersion.IsNull() {
360+
talosVersionInfo.Tag = gendata.VersionTag
363361
}
364362

365-
if !state.TalosVersion.IsUnknown() && !state.TalosVersion.IsNull() {
366-
talosVersionInfo = &machineapi.VersionInfo{
367-
Tag: state.TalosVersion.ValueString(),
368-
}
363+
if !state.TalosVersion.IsNull() {
364+
talosVersionInfo.Tag = state.TalosVersion.ValueString()
369365
}
370366

371367
talosVersionCompatibility, err := compatibility.ParseTalosVersion(talosVersionInfo)

internal/talos/talos_machine_configuration_data_source_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ func TestAccTalosMachineConfigurationDataSource(t *testing.T) {
207207
Config: testAccTalosMachineConfigurationDataSourceConfig("v1.3", "example-cluster-8", "controlplane", "https://cluster.local", "v1.23.0", true, true, true, true),
208208
ExpectError: regexp.MustCompile("unknown keys found during decoding:"),
209209
},
210+
{ // this is just added so that the plan only test above doesn't fail
211+
PlanOnly: true,
212+
Config: testAccTalosMachineConfigurationDataSourceConfig("v1.3", "example-cluster-8", "controlplane", "https://cluster.local", "", false, false, true, true),
213+
},
210214
},
211215
})
212216
}
@@ -247,16 +251,21 @@ func testAccTalosMachineConfigurationDataSourceConfig(
247251
}
248252

249253
configTemplate := `
254+
variable "talos_version" {
255+
type = string
256+
default = "{{ .TalosVersion }}"
257+
}
258+
250259
resource "talos_machine_secrets" "this" {
251-
{{ if .TalosVersion }}talos_version = "{{ .TalosVersion }}"{{ end }}
260+
{{ if .TalosVersion }}talos_version = var.talos_version{{ end }}
252261
}
253262
254263
data "talos_machine_configuration" "this" {
255264
cluster_name = "{{ .ClusterName }}"
256265
cluster_endpoint = "{{ .ClusterEndpoint }}"
257266
machine_type = "{{ .MachineType }}"
258267
machine_secrets = talos_machine_secrets.this.machine_secrets
259-
{{ if .TalosVersion }}talos_version = "{{ .TalosVersion }}"{{ end }}
268+
{{ if .TalosVersion }}talos_version = var.talos_version{{ end }}
260269
{{ if .ConfigPatches }}config_patches = [
261270
yamlencode({
262271
machine = {

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77

88
import (
99
"context"
10+
"flag"
1011
"log"
1112

1213
"github.com/hashicorp/terraform-plugin-framework/providerserver"
@@ -24,8 +25,14 @@ import (
2425
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate --provider-name talos
2526

2627
func main() {
28+
var debug bool
29+
30+
flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve")
31+
flag.Parse()
32+
2733
opts := providerserver.ServeOpts{
2834
Address: "registry.terraform.io/siderolabs/talos",
35+
Debug: debug,
2936
}
3037

3138
err := providerserver.Serve(context.Background(), talos.New, opts)

0 commit comments

Comments
 (0)