Skip to content

Commit c4e25f5

Browse files
authored
Feat: add egress_address_ranges attribute to ske resource (#672)
* feat: add egress_address_ranges attribute to ske resource * docs: generate new docs for ske
1 parent 170041f commit c4e25f5

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

docs/data-sources/ske_cluster.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ data "stackit_ske_cluster" "example" {
3232
- `allow_privileged_containers` (Boolean, Deprecated) DEPRECATED as of Kubernetes 1.25+
3333
Flag to specify if privileged mode for containers is enabled or not.
3434
This should be used with care since it also disables a couple of other features like the use of some volume type (e.g. PVCs).
35+
- `egress_address_ranges` (List of String) The outgoing network ranges (in CIDR notation) of traffic originating from workload on the cluster.
3536
- `extensions` (Attributes) A single extensions block as defined below (see [below for nested schema](#nestedatt--extensions))
3637
- `hibernations` (Attributes List) One or more hibernation block as defined below. (see [below for nested schema](#nestedatt--hibernations))
3738
- `id` (String) Terraform's internal data source. ID. It is structured as "`project_id`,`name`".

docs/resources/ske_cluster.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Deprecated as of Kubernetes 1.25 and later
6262

6363
### Read-Only
6464

65+
- `egress_address_ranges` (List of String) The outgoing network ranges (in CIDR notation) of traffic originating from workload on the cluster.
6566
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`name`".
6667
- `kubernetes_version_used` (String) Full Kubernetes version used. For example, if 1.22 was set in `kubernetes_version_min`, this value may result to 1.22.15. SKE automatically updates the cluster Kubernetes version if you have set `maintenance.enable_kubernetes_version_updates` to true or if there is a mandatory update, as described in [Updates for Kubernetes versions and Operating System versions in SKE](https://docs.stackit.cloud/stackit/en/version-updates-in-ske-10125631.html).
6768

stackit/internal/services/ske/cluster/datasource.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ func (r *clusterDataSource) Schema(_ context.Context, _ datasource.SchemaRequest
110110
DeprecationMessage: "Please remove this flag from your configuration when using Kubernetes version 1.25+.",
111111
Computed: true,
112112
},
113-
113+
"egress_address_ranges": schema.ListAttribute{
114+
Description: "The outgoing network ranges (in CIDR notation) of traffic originating from workload on the cluster.",
115+
Computed: true,
116+
ElementType: types.StringType,
117+
},
114118
"node_pools": schema.ListNestedAttribute{
115119
Description: "One or more `node_pool` block as defined below.",
116120
Computed: true,

stackit/internal/services/ske/cluster/resource.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type Model struct {
7777
Network types.Object `tfsdk:"network"`
7878
Hibernations types.List `tfsdk:"hibernations"`
7979
Extensions types.Object `tfsdk:"extensions"`
80+
EgressAddressRanges types.List `tfsdk:"egress_address_ranges"`
8081
}
8182

8283
// Struct corresponding to Model.NodePools[i]
@@ -374,6 +375,11 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
374375
Description: "Flag to specify if privileged mode for containers is enabled or not.\nThis should be used with care since it also disables a couple of other features like the use of some volume type (e.g. PVCs).\nDeprecated as of Kubernetes 1.25 and later",
375376
Optional: true,
376377
},
378+
"egress_address_ranges": schema.ListAttribute{
379+
Description: "The outgoing network ranges (in CIDR notation) of traffic originating from workload on the cluster.",
380+
Computed: true,
381+
ElementType: types.StringType,
382+
},
377383
"node_pools": schema.ListNestedAttribute{
378384
Description: "One or more `node_pool` block as defined below.",
379385
Required: true,
@@ -1320,6 +1326,15 @@ func mapFields(ctx context.Context, cl *ske.Cluster, m *Model) error {
13201326
m.AllowPrivilegedContainers = types.BoolPointerValue(cl.Kubernetes.AllowPrivilegedContainers)
13211327
}
13221328

1329+
m.EgressAddressRanges = types.ListNull(types.StringType)
1330+
if cl.Status != nil {
1331+
var diags diag.Diagnostics
1332+
m.EgressAddressRanges, diags = types.ListValueFrom(ctx, types.StringType, cl.Status.EgressAddressRanges)
1333+
if diags.HasError() {
1334+
return fmt.Errorf("map egressAddressRanges: %w", core.DiagsToError(diags))
1335+
}
1336+
}
1337+
13231338
err := mapNodePools(ctx, cl, m)
13241339
if err != nil {
13251340
return fmt.Errorf("map node_pools: %w", err)

stackit/internal/services/ske/cluster/resource_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func TestMapFields(t *testing.T) {
5757
Network: types.ObjectNull(networkTypes),
5858
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
5959
Extensions: types.ObjectNull(extensionsTypes),
60+
EgressAddressRanges: types.ListNull(types.StringType),
6061
},
6162
true,
6263
},
@@ -140,9 +141,10 @@ func TestMapFields(t *testing.T) {
140141
},
141142
},
142143
Status: &ske.ClusterStatus{
143-
Aggregated: &cs,
144-
Error: nil,
145-
Hibernated: nil,
144+
Aggregated: &cs,
145+
Error: nil,
146+
Hibernated: nil,
147+
EgressAddressRanges: &[]string{"0.0.0.0/32", "1.1.1.1/32"},
146148
},
147149
},
148150
Model{
@@ -152,7 +154,13 @@ func TestMapFields(t *testing.T) {
152154
KubernetesVersion: types.StringNull(),
153155
KubernetesVersionUsed: types.StringValue("1.2.3"),
154156
AllowPrivilegedContainers: types.BoolValue(true),
155-
157+
EgressAddressRanges: types.ListValueMust(
158+
types.StringType,
159+
[]attr.Value{
160+
types.StringValue("0.0.0.0/32"),
161+
types.StringValue("1.1.1.1/32"),
162+
},
163+
),
156164
NodePools: types.ListValueMust(
157165
types.ObjectType{AttrTypes: nodePoolTypes},
158166
[]attr.Value{
@@ -265,6 +273,7 @@ func TestMapFields(t *testing.T) {
265273
Network: types.ObjectNull(networkTypes),
266274
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
267275
Extensions: types.ObjectNull(extensionsTypes),
276+
EgressAddressRanges: types.ListNull(types.StringType),
268277
},
269278
true,
270279
},
@@ -298,6 +307,7 @@ func TestMapFields(t *testing.T) {
298307
NodePools: types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
299308
Maintenance: types.ObjectNull(maintenanceTypes),
300309
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
310+
EgressAddressRanges: types.ListNull(types.StringType),
301311
Extensions: types.ObjectValueMust(extensionsTypes, map[string]attr.Value{
302312
"acl": types.ObjectValueMust(aclTypes, map[string]attr.Value{
303313
"enabled": types.BoolValue(true),
@@ -345,6 +355,7 @@ func TestMapFields(t *testing.T) {
345355
NodePools: types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
346356
Maintenance: types.ObjectNull(maintenanceTypes),
347357
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
358+
EgressAddressRanges: types.ListNull(types.StringType),
348359
Extensions: types.ObjectValueMust(extensionsTypes, map[string]attr.Value{
349360
"acl": types.ObjectValueMust(aclTypes, map[string]attr.Value{
350361
"enabled": types.BoolValue(false),
@@ -403,6 +414,7 @@ func TestMapFields(t *testing.T) {
403414
NodePools: types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
404415
Maintenance: types.ObjectNull(maintenanceTypes),
405416
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
417+
EgressAddressRanges: types.ListNull(types.StringType),
406418
Extensions: types.ObjectValueMust(extensionsTypes, map[string]attr.Value{
407419
"acl": types.ObjectValueMust(aclTypes, map[string]attr.Value{
408420
"enabled": types.BoolValue(true),
@@ -440,6 +452,7 @@ func TestMapFields(t *testing.T) {
440452
Maintenance: types.ObjectNull(maintenanceTypes),
441453
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
442454
Extensions: types.ObjectNull(extensionsTypes),
455+
EgressAddressRanges: types.ListNull(types.StringType),
443456
},
444457
true,
445458
},
@@ -565,6 +578,7 @@ func TestMapFields(t *testing.T) {
565578
KubernetesVersion: types.StringNull(),
566579
KubernetesVersionUsed: types.StringValue("1.2.3"),
567580
AllowPrivilegedContainers: types.BoolValue(true),
581+
EgressAddressRanges: types.ListNull(types.StringType),
568582
NodePools: types.ListValueMust(
569583
types.ObjectType{AttrTypes: nodePoolTypes},
570584
[]attr.Value{

0 commit comments

Comments
 (0)