From 3b1553b6b81668b1a04f19bb2fa4afd3ebd7fed4 Mon Sep 17 00:00:00 2001 From: Van Thong Nguyen Date: Tue, 7 Jan 2025 15:12:38 +0100 Subject: [PATCH] Fix update k8s resource always trigger upgrade v1 (#412) * Revert "Fix cannot retry upgrade gsk when previous upgrade fails v1 (#410)" This reverts commit a9def41145d9afdb7443eb98c7ebba38892e9909. * set the correct gsk version/release at resource read --- gridscale/resource_gridscale_k8s.go | 32 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/gridscale/resource_gridscale_k8s.go b/gridscale/resource_gridscale_k8s.go index bfdefa9d..df36cdfc 100644 --- a/gridscale/resource_gridscale_k8s.go +++ b/gridscale/resource_gridscale_k8s.go @@ -374,18 +374,30 @@ func deriveK8sTemplateFromResourceData(client *gsclient.Client, d *schema.Resour releaseInterface, isReleaseSet := d.GetOk("release") release := releaseInterface.(string) - if isVersionSet { - derivationTypesRequested += 1 - derivationType = "version" - } + if !d.IsNewResource() { // case if update of resource is requested + if isVersionSet && d.HasChange("version") { + derivationTypesRequested += 1 + derivationType = "version" + } - if isReleaseSet { - derivationTypesRequested += 1 - derivationType = "release" - } + if isReleaseSet && d.HasChange("release") { + derivationTypesRequested += 1 + derivationType = "release" + } + } else { // case if creation of resource is requested + if isVersionSet { + derivationTypesRequested += 1 + derivationType = "version" + } - if derivationTypesRequested == 0 { - return nil, errors.New("either \"release\" or \"gsk_version\" has to be defined") + if isReleaseSet { + derivationTypesRequested += 1 + derivationType = "release" + } + + if derivationTypesRequested == 0 { + return nil, errors.New("either \"release\" or \"gsk_version\" has to be defined") + } } if derivationTypesRequested > 1 {