Skip to content
Open
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
9 changes: 9 additions & 0 deletions docs/data-sources/ske_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,17 @@ Read-Only:

Read-Only:

- `control_plane` (Attributes) Control plane for the cluster. (see [below for nested schema](#nestedatt--network--control_plane))
- `id` (String) ID of the STACKIT Network Area (SNA) network into which the cluster will be deployed.

<a id="nestedatt--network--control_plane"></a>
### Nested Schema for `network.control_plane`

Read-Only:

- `access_scope` (String) Access scope of the control plane. It defines if the Kubernetes control plane is public or only available inside a STACKIT Network Area.Possible values are: `PUBLIC`, `SNA`.



<a id="nestedatt--node_pools"></a>
### Nested Schema for `node_pools`
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/ske_kubernetes_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resource "stackit_ske_cluster" "example" {
### Optional

- `region` (String) Region override. If omitted, the provider’s region will be used.
- `version_state` (String) If specified, only returns Kubernetes versions with this version state. Possible values are: `UNSPECIFIED`, `SUPPORTED`.
- `version_state` (String) If specified, only returns Kubernetes versions with this version state. Possible values are: `SUPPORTED`.

### Read-Only

Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/ske_machine_image_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "stackit_ske_cluster" "example" {
### Optional

- `region` (String) Region override. If omitted, the provider’s region will be used.
- `version_state` (String) Filter returned machine image versions by their state. Possible values are: `UNSPECIFIED`, `SUPPORTED`.
- `version_state` (String) Filter returned machine image versions by their state. Possible values are: `SUPPORTED`.

### Read-Only

Expand Down
11 changes: 11 additions & 0 deletions docs/resources/ske_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ resource "stackit_ske_cluster" "example" {
start = "01:00:00Z"
end = "02:00:00Z"
}
network = {
access_scope = "PUBLIC"
}
}

# Only use the import statement, if you want to import an existing ske cluster
Expand Down Expand Up @@ -204,4 +207,12 @@ Optional:

Optional:

- `control_plane` (Attributes) Control plane for the cluster. (see [below for nested schema](#nestedatt--network--control_plane))
- `id` (String) ID of the STACKIT Network Area (SNA) network into which the cluster will be deployed.

<a id="nestedatt--network--control_plane"></a>
### Nested Schema for `network.control_plane`

Optional:

- `access_scope` (String) Access scope of the control plane. It defines if the Kubernetes control plane is public or only available inside a STACKIT Network Area.Possible values are: `PUBLIC`, `SNA`.
3 changes: 3 additions & 0 deletions examples/resources/stackit_ske_cluster/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ resource "stackit_ske_cluster" "example" {
start = "01:00:00Z"
end = "02:00:00Z"
}
network = {
access_scope = "PUBLIC"
}
}

# Only use the import statement, if you want to import an existing ske cluster
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.11.6
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.3.0
github.com/stackitcloud/stackit-sdk-go/services/ske v1.6.3
github.com/stackitcloud/stackit-sdk-go/services/ske v1.7.0
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3
github.com/teambition/rrule-go v1.8.2
golang.org/x/mod v0.32.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ github.com/stackitcloud/stackit-sdk-go/services/sfs v0.3.0 h1:4567q2dFp3Hw+5Kx+N
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.3.0/go.mod h1:r5lBwzJpJe2xBIYctkVIIpaZ41Y6vUEpkmsWR2VoQJs=
github.com/stackitcloud/stackit-sdk-go/services/ske v1.6.3 h1:c+nQMvSml08cdRF1kE24vCw0r/l56olP/svQyhcnKOs=
github.com/stackitcloud/stackit-sdk-go/services/ske v1.6.3/go.mod h1:1Jr+ImrmPERxbYnlTy6O2aSZYNnREf2qQyysv6YC1RY=
github.com/stackitcloud/stackit-sdk-go/services/ske v1.7.0 h1:l1QjxW7sdE/6B6BZtHxbmus8XJdI9KDuXX3fwUa5fog=
github.com/stackitcloud/stackit-sdk-go/services/ske v1.7.0/go.mod h1:1Jr+ImrmPERxbYnlTy6O2aSZYNnREf2qQyysv6YC1RY=
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3 h1:AQrcr+qeIuZob+3TT2q1L4WOPtpsu5SEpkTnOUHDqfE=
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.3/go.mod h1:8BBGC69WFXWWmKgzSjgE4HvsI7pEgO0RN2cASwuPJ18=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
11 changes: 11 additions & 0 deletions stackit/internal/services/ske/cluster/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"

sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
skeUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/ske/utils"

Expand Down Expand Up @@ -223,6 +224,16 @@ func (r *clusterDataSource) Schema(_ context.Context, _ datasource.SchemaRequest
validate.UUID(),
},
},
"control_plane": schema.SingleNestedAttribute{
Description: "Control plane for the cluster.",
Computed: true,
Attributes: map[string]schema.Attribute{
"access_scope": schema.StringAttribute{
Description: "Access scope of the control plane. It defines if the Kubernetes control plane is public or only available inside a STACKIT Network Area." + utils.FormatPossibleValues(sdkUtils.EnumSliceToStringSlice(ske.AllowedAccessScopeEnumValues)...),
Computed: true,
},
},
},
},
},

Expand Down
62 changes: 58 additions & 4 deletions stackit/internal/services/ske/cluster/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,23 @@ var maintenanceTypes = map[string]attr.Type{

// Struct corresponding to Model.Network
type network struct {
ID types.String `tfsdk:"id"`
ID types.String `tfsdk:"id"`
ControlPlane types.Object `tfsdk:"control_plane"`
}

// Types corresponding to network
var networkTypes = map[string]attr.Type{
"id": basetypes.StringType{},
"id": basetypes.StringType{},
"control_plane": types.ObjectType{AttrTypes: controlPlaneTypes},
}

type controlPlane struct {
AccessScope types.String `tfsdk:"access_scope"`
}

// Types corresponding to control plane
var controlPlaneTypes = map[string]attr.Type{
"access_scope": basetypes.StringType{},
}

// Struct corresponding to Model.Hibernations[i]
Expand Down Expand Up @@ -563,6 +574,16 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
stringplanmodifier.RequiresReplace(),
},
},
"control_plane": schema.SingleNestedAttribute{
Description: "Control plane for the cluster.",
Optional: true,
Attributes: map[string]schema.Attribute{
"access_scope": schema.StringAttribute{
Description: "Access scope of the control plane. It defines if the Kubernetes control plane is public or only available inside a STACKIT Network Area." + utils.FormatPossibleValues(sdkUtils.EnumSliceToStringSlice(ske.AllowedAccessScopeEnumValues)...),
Optional: true,
},
},
},
},
},
"hibernations": schema.ListNestedAttribute{
Expand Down Expand Up @@ -1352,8 +1373,21 @@ func toNetworkPayload(ctx context.Context, m *Model) (*ske.Network, error) {
return nil, fmt.Errorf("converting network object: %v", diags.Errors())
}

var networkControlPlane *ske.V2ControlPlaneNetwork
if !(network.ControlPlane.IsNull() || network.ControlPlane.IsUnknown()) {
networkControlPlaneModel := controlPlane{}
diags = network.ControlPlane.As(ctx, &networkControlPlaneModel, basetypes.ObjectAsOptions{})
if diags.HasError() {
return nil, fmt.Errorf("converting network control plane: %w", core.DiagsToError(diags))
}
networkControlPlane = &ske.V2ControlPlaneNetwork{
AccessScope: ske.V2ControlPlaneNetworkGetAccessScopeAttributeType(conversion.StringValueToPointer(networkControlPlaneModel.AccessScope)),
}
}

return &ske.Network{
Id: conversion.StringValueToPointer(network.ID),
Id: conversion.StringValueToPointer(network.ID),
ControlPlane: networkControlPlane,
}, nil
}

Expand Down Expand Up @@ -1657,12 +1691,32 @@ func mapNetwork(cl *ske.Cluster, m *Model) error {
return nil
}

var diags diag.Diagnostics
id := types.StringNull()
if cl.Network.Id != nil {
id = types.StringValue(*cl.Network.Id)
}

networkControlPlane := types.ObjectNull(controlPlaneTypes)
if cl.Network.ControlPlane != nil {
controlPlaneAccessScope := types.StringNull()
if cl.Network.ControlPlane.AccessScope != nil {
controlPlaneAccessScope = types.StringValue(string(cl.Network.ControlPlane.GetAccessScope()))
}

controlPlaneValues := map[string]attr.Value{
"access_scope": controlPlaneAccessScope,
}

networkControlPlane, diags = types.ObjectValue(controlPlaneTypes, controlPlaneValues)
if diags.HasError() {
return fmt.Errorf("creating network control plane: %w", core.DiagsToError(diags))
}
}

networkValues := map[string]attr.Value{
"id": id,
"id": id,
"control_plane": networkControlPlane,
}
networkObject, diags := types.ObjectValue(networkTypes, networkValues)
if diags.HasError() {
Expand Down
37 changes: 36 additions & 1 deletion stackit/internal/services/ske/cluster/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func TestMapFields(t *testing.T) {
},
Network: &ske.Network{
Id: utils.Ptr("nid"),
ControlPlane: &ske.V2ControlPlaneNetwork{
AccessScope: ske.V2ControlPlaneNetworkGetAccessScopeAttributeType(utils.Ptr("SNA")),
},
},
Name: utils.Ptr("name"),
Nodepools: &[]ske.Nodepool{
Expand Down Expand Up @@ -231,6 +234,9 @@ func TestMapFields(t *testing.T) {
}),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringValue("nid"),
"control_plane": types.ObjectValueMust(controlPlaneTypes, map[string]attr.Value{
"access_scope": types.StringValue("SNA"),
}),
}),
Hibernations: types.ListValueMust(
types.ObjectType{AttrTypes: hibernationTypes},
Expand Down Expand Up @@ -560,6 +566,9 @@ func TestMapFields(t *testing.T) {
},
Network: &ske.Network{
Id: utils.Ptr("nid"),
ControlPlane: &ske.V2ControlPlaneNetwork{
AccessScope: ske.V2ControlPlaneNetworkGetAccessScopeAttributeType(utils.Ptr("SNA")),
},
},
Name: utils.Ptr("name"),
Nodepools: &[]ske.Nodepool{
Expand Down Expand Up @@ -648,6 +657,9 @@ func TestMapFields(t *testing.T) {
}),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringValue("nid"),
"control_plane": types.ObjectValueMust(controlPlaneTypes, map[string]attr.Value{
"access_scope": types.StringValue("SNA"),
}),
}),
Hibernations: types.ListValueMust(
types.ObjectType{AttrTypes: hibernationTypes},
Expand Down Expand Up @@ -2239,10 +2251,16 @@ func TestToNetworkPayload(t *testing.T) {
Name: types.StringValue("name"),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringValue("nid"),
"control_plane": types.ObjectValueMust(controlPlaneTypes, map[string]attr.Value{
"access_scope": types.StringValue("SNA"),
}),
}),
},
&ske.Network{
Id: utils.Ptr("nid"),
ControlPlane: &ske.V2ControlPlaneNetwork{
AccessScope: ske.V2ControlPlaneNetworkGetAccessScopeAttributeType(utils.Ptr("SNA")),
},
},
true,
},
Expand All @@ -2252,12 +2270,29 @@ func TestToNetworkPayload(t *testing.T) {
ProjectId: types.StringValue("pid"),
Name: types.StringValue("name"),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringNull(),
"id": types.StringNull(),
"control_plane": types.ObjectNull(controlPlaneTypes),
}),
},
&ske.Network{},
true,
},
{
"no_control_plane",
&Model{
ProjectId: types.StringValue("pid"),
Name: types.StringValue("name"),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringValue("nid"),
"control_plane": types.ObjectNull(controlPlaneTypes),
}),
},
&ske.Network{
Id: utils.Ptr("nid"),
ControlPlane: nil,
},
true,
},
{
"no_network",
&Model{
Expand Down
5 changes: 5 additions & 0 deletions stackit/internal/services/ske/ske_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var testConfigVarsMax = config.Variables{
"refresh_before": config.StringVariable("600"),
"dns_zone_name": config.StringVariable("acc-" + acctest.RandStringFromCharSet(6, acctest.CharSetAlpha)),
"dns_name": config.StringVariable("acc-" + acctest.RandStringFromCharSet(6, acctest.CharSetAlpha) + ".runs.onstackit.cloud"),
"network_control_plane_access_scope": config.StringVariable("PUBLIC"),
}

var testConfigDatasource = config.Variables{
Expand Down Expand Up @@ -299,6 +300,8 @@ func TestAccSKEMax(t *testing.T) {
resource.TestCheckResourceAttrSet("stackit_ske_cluster.cluster", "pod_address_ranges.0"),
resource.TestCheckResourceAttrSet("stackit_ske_cluster.cluster", "kubernetes_version_used"),

resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "network.control_plane.access_scope", testutil.ConvertConfigVariable(testConfigVarsMax["network_control_plane_access_scope"])),

// Kubeconfig
resource.TestCheckResourceAttrPair(
"stackit_ske_kubeconfig.kubeconfig", "project_id",
Expand Down Expand Up @@ -373,6 +376,8 @@ func TestAccSKEMax(t *testing.T) {
resource.TestCheckResourceAttrSet("data.stackit_ske_cluster.cluster", "pod_address_ranges.0"),

resource.TestCheckResourceAttrSet("data.stackit_ske_cluster.cluster", "kubernetes_version_used"),

resource.TestCheckResourceAttr("data.stackit_ske_cluster.cluster", "network.control_plane.access_scope", testutil.ConvertConfigVariable(testConfigVarsMax["network_control_plane_access_scope"])),
),
},
// 3) Import cluster
Expand Down
6 changes: 6 additions & 0 deletions stackit/internal/services/ske/testdata/resource-max.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ variable "refresh" {}
variable "refresh_before" {}
variable "dns_zone_name" {}
variable "dns_name" {}
variable "network_control_plane_access_scope" {}

resource "stackit_ske_cluster" "cluster" {
project_id = var.project_id
Expand Down Expand Up @@ -92,6 +93,11 @@ resource "stackit_ske_cluster" "cluster" {
end = var.maintenance_end
}
region = var.region
network = {
control_plane = {
access_scope = var.network_control_plane_access_scope
}
}
}

resource "stackit_ske_kubeconfig" "kubeconfig" {
Expand Down