From 2b4f13410c27e1b2ab0388801582ea9ed3915dea Mon Sep 17 00:00:00 2001 From: Robert Hoppe Date: Mon, 8 Jul 2024 16:24:43 +0200 Subject: [PATCH] Introduce Actions for enablement (#247) Co-authored-by: Robert Hoppe --- go.mod | 2 +- go.sum | 4 ++-- .../resources/kubernetes/cluster/actions.go | 19 +++++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index a64d88bd..c992a51f 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/Masterminds/semver v1.5.0 - github.com/SchwarzIT/community-stackit-go-client v1.29.11 + github.com/SchwarzIT/community-stackit-go-client v1.30.1 github.com/go-test/deep v1.0.3 github.com/google/uuid v1.3.0 github.com/hashicorp/terraform-plugin-framework v1.2.0 diff --git a/go.sum b/go.sum index 8fcff0a3..8997e41d 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,8 @@ github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugX github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= -github.com/SchwarzIT/community-stackit-go-client v1.29.11 h1:Y4VZuSn6BwEyUDRQxj/sx6C7+eO6R5IO3R4VPYeM0Hs= -github.com/SchwarzIT/community-stackit-go-client v1.29.11/go.mod h1:hlTfBNOKE1fokWE8g3KrI0AHo0SqzTKkS+LrIdhH8Qg= +github.com/SchwarzIT/community-stackit-go-client v1.30.1 h1:pD+CvhC4qACvPboT/flp92edD/hdEPAyn02apmYXjgs= +github.com/SchwarzIT/community-stackit-go-client v1.30.1/go.mod h1:hlTfBNOKE1fokWE8g3KrI0AHo0SqzTKkS+LrIdhH8Qg= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= diff --git a/stackit/internal/resources/kubernetes/cluster/actions.go b/stackit/internal/resources/kubernetes/cluster/actions.go index ad4688a9..76b25447 100644 --- a/stackit/internal/resources/kubernetes/cluster/actions.go +++ b/stackit/internal/resources/kubernetes/cluster/actions.go @@ -4,12 +4,12 @@ import ( "context" "fmt" "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/credentials" + serviceenablement "github.com/SchwarzIT/community-stackit-go-client/pkg/services/service-enablement/v1" "net/http" "strings" "time" "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/cluster" - "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/project" "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" clientValidate "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" "github.com/SchwarzIT/terraform-provider-stackit/stackit/internal/common" @@ -83,10 +83,12 @@ func (r Resource) preProcessConfig(diags *diag.Diagnostics, cl *Cluster) { func (r Resource) enableProject(ctx context.Context, diags *diag.Diagnostics, cl *Cluster, timeout time.Duration) { projectID := cl.ProjectID.ValueString() - c := r.client.Kubernetes.Project + c := r.client.ServiceEnablement + + serviceID := "cloud.stackit.ske" found := true - status, err := c.Get(ctx, projectID) + status, err := c.GetService(ctx, projectID, serviceID) if agg := common.Validate(&diag.Diagnostics{}, status, err, "JSON200.State"); agg != nil { if status == nil || status.StatusCode() != http.StatusNotFound { diags.AddError("failed to fetch SKE project status", agg.Error()) @@ -96,18 +98,19 @@ func (r Resource) enableProject(ctx context.Context, diags *diag.Diagnostics, cl } // check if project already enabled - if found && *status.JSON200.State == project.STATE_CREATED { + if found && *status.JSON200.State == serviceenablement.ENABLED { return } - res, err := c.Create(ctx, projectID) + res, err := c.EnableService(ctx, projectID, serviceID) if agg := common.Validate(diags, res, err); agg != nil { - diags.AddError("failed during SKE project init", agg.Error()) + diags.AddError("failed during SKE service enablement", agg.Error()) return } - process := res.WaitHandler(ctx, c, projectID).SetTimeout(timeout) + + process := res.WaitHandler(ctx, c, projectID, serviceID).SetTimeout(timeout) if _, err := process.WaitWithContext(ctx); err != nil { - diags.AddError("failed to verify SKE project init", err.Error()) + diags.AddError("failed to verify SKE service enablement", err.Error()) return } }