Skip to content
1 change: 1 addition & 0 deletions docs/data-sources/ske_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Read-Only:
Read-Only:

- `enabled` (Boolean) Flag to enable/disable DNS extensions
- `gateway_api` (Boolean) Enables Gateway API support for ExternalDNS. The CRDs must be installed by the user. Once installed, ExternalDNS will be configured at the next cluster reconcile.
- `zones` (List of String) Specify a list of domain filters for externalDNS (e.g., `foo.runs.onstackit.cloud`)


Expand Down
1 change: 1 addition & 0 deletions docs/resources/ske_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Required:

Optional:

- `gateway_api` (Boolean) Enables Gateway API support for ExternalDNS. The CRDs must be installed by the user. Once installed, ExternalDNS will be configured at the next cluster reconcile.
- `zones` (List of String) Specify a list of domain filters for externalDNS (e.g., `foo.runs.onstackit.cloud`)


Expand Down
4 changes: 4 additions & 0 deletions stackit/internal/services/ske/cluster/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ func (r *clusterDataSource) Schema(_ context.Context, _ datasource.SchemaRequest
Computed: true,
ElementType: types.StringType,
},
"gateway_api": schema.BoolAttribute{
Description: "Enables Gateway API support for ExternalDNS. The CRDs must be installed by the user. Once installed, ExternalDNS will be configured at the next cluster reconcile.",
Computed: true,
},
},
},
"application_load_balancer": schema.SingleNestedAttribute{
Expand Down
27 changes: 19 additions & 8 deletions stackit/internal/services/ske/cluster/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,16 @@ var observabilityTypes = map[string]attr.Type{

// Struct corresponding to extensions.DNS
type dns struct {
Enabled types.Bool `tfsdk:"enabled"`
Zones types.List `tfsdk:"zones"`
Enabled types.Bool `tfsdk:"enabled"`
Zones types.List `tfsdk:"zones"`
GatewayApi types.Bool `tfsdk:"gateway_api"`
}

// Types corresponding to DNS
var dnsTypes = map[string]attr.Type{
"enabled": basetypes.BoolType{},
"zones": basetypes.ListType{ElemType: types.StringType},
"enabled": basetypes.BoolType{},
"zones": basetypes.ListType{ElemType: types.StringType},
"gateway_api": basetypes.BoolType{},
}

// NewClusterResource is a helper function to simplify the provider implementation.
Expand Down Expand Up @@ -825,6 +827,11 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
// API response (empty list).
Default: listdefault.StaticValue(types.ListValueMust(types.StringType, []attr.Value{})),
},
"gateway_api": schema.BoolAttribute{
Description: "Enables Gateway API support for ExternalDNS. The CRDs must be installed by the user. Once installed, ExternalDNS will be configured at the next cluster reconcile.",
Optional: true,
Computed: true,
},
},
},
"application_load_balancer": schema.SingleNestedAttribute{
Expand Down Expand Up @@ -1491,15 +1498,17 @@ func toExtensionsPayload(ctx context.Context, m *Model) (*ske.Extension, error)
return nil, fmt.Errorf("converting extensions.dns object: %v", diags.Errors())
}
dnsEnabled := dns.Enabled.ValueBool()
gatewayApi := dns.GatewayApi.ValueBool()

zones := []string{}
diags = dns.Zones.ElementsAs(ctx, &zones, true)
if diags.HasError() {
return nil, fmt.Errorf("converting extensions.dns.zones object: %v", diags.Errors())
}
skeDNS = &ske.DNS{
Enabled: dnsEnabled,
Zones: zones,
Enabled: dnsEnabled,
Zones: zones,
GatewayApi: &gatewayApi,
}
}

Expand Down Expand Up @@ -2152,15 +2161,17 @@ func mapExtensions(ctx context.Context, cl *ske.Cluster, m *Model) error {
dnsExtension := types.ObjectNull(dnsTypes)
if cl.Extensions.Dns != nil {
enabled := types.BoolValue(cl.Extensions.Dns.Enabled)
gatewayApi := types.BoolValue(*cl.Extensions.Dns.GatewayApi)

zonesList, diags := types.ListValueFrom(ctx, types.StringType, cl.Extensions.Dns.Zones)
if diags.HasError() {
return fmt.Errorf("creating zones list: %w", core.DiagsToError(diags))
}

dnsValues := map[string]attr.Value{
"enabled": enabled,
"zones": zonesList,
"enabled": enabled,
"zones": zonesList,
"gateway_api": gatewayApi,
}

dnsExtension, diags = types.ObjectValue(dnsTypes, dnsValues)
Expand Down
47 changes: 29 additions & 18 deletions stackit/internal/services/ske/cluster/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func TestMapFields(t *testing.T) {
Enabled: true,
},
Dns: &ske.DNS{
Zones: []string{"foo.onstackit.cloud"},
Enabled: true,
Zones: []string{"foo.onstackit.cloud"},
Enabled: true,
GatewayApi: new(true),
},
ApplicationLoadBalancer: &ske.ApplicationLoadBalancer{
Enabled: true,
Expand Down Expand Up @@ -277,6 +278,7 @@ func TestMapFields(t *testing.T) {
"zones": types.ListValueMust(types.StringType, []attr.Value{
types.StringValue("foo.onstackit.cloud"),
}),
"gateway_api": types.BoolValue(true),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(true),
Expand Down Expand Up @@ -340,8 +342,9 @@ func TestMapFields(t *testing.T) {
Enabled: true,
},
Dns: &ske.DNS{
Zones: nil,
Enabled: true,
Zones: nil,
Enabled: true,
GatewayApi: new(true),
},
ApplicationLoadBalancer: &ske.ApplicationLoadBalancer{
Enabled: true,
Expand Down Expand Up @@ -377,8 +380,9 @@ func TestMapFields(t *testing.T) {
"instance_id": types.StringValue(""),
}),
"dns": types.ObjectValueMust(dnsTypes, map[string]attr.Value{
"enabled": types.BoolValue(true),
"zones": types.ListNull(types.StringType),
"enabled": types.BoolValue(true),
"zones": types.ListNull(types.StringType),
"gateway_api": types.BoolValue(true),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(true),
Expand All @@ -403,8 +407,9 @@ func TestMapFields(t *testing.T) {
"instance_id": types.StringNull(),
}),
"dns": types.ObjectValueMust(dnsTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
"zones": types.ListNull(types.StringType),
"enabled": types.BoolValue(false),
"zones": types.ListNull(types.StringType),
"gateway_api": types.BoolValue(false),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
Expand Down Expand Up @@ -443,8 +448,9 @@ func TestMapFields(t *testing.T) {
"instance_id": types.StringNull(),
}),
"dns": types.ObjectValueMust(dnsTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
"zones": types.ListNull(types.StringType),
"enabled": types.BoolValue(false),
"zones": types.ListNull(types.StringType),
"gateway_api": types.BoolValue(false),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
Expand All @@ -471,8 +477,9 @@ func TestMapFields(t *testing.T) {
"instance_id": types.StringValue("id"),
}),
"dns": types.ObjectValueMust(dnsTypes, map[string]attr.Value{
"enabled": types.BoolValue(true),
"zones": types.ListNull(types.StringType),
"enabled": types.BoolValue(true),
"zones": types.ListNull(types.StringType),
"gateway_api": types.BoolValue(true),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
Expand All @@ -486,8 +493,9 @@ func TestMapFields(t *testing.T) {
Enabled: true,
},
Dns: &ske.DNS{
Zones: nil,
Enabled: true,
Zones: nil,
Enabled: true,
GatewayApi: new(true),
},
},
Name: new("name"),
Expand Down Expand Up @@ -522,8 +530,9 @@ func TestMapFields(t *testing.T) {
"instance_id": types.StringValue("id"),
}),
"dns": types.ObjectValueMust(dnsTypes, map[string]attr.Value{
"enabled": types.BoolValue(true),
"zones": types.ListNull(types.StringType),
"enabled": types.BoolValue(true),
"zones": types.ListNull(types.StringType),
"gateway_api": types.BoolValue(true),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
Expand Down Expand Up @@ -619,8 +628,9 @@ func TestMapFields(t *testing.T) {
Enabled: true,
},
Dns: &ske.DNS{
Zones: []string{"zone1"},
Enabled: true,
Zones: []string{"zone1"},
Enabled: true,
GatewayApi: new(true),
},
ApplicationLoadBalancer: &ske.ApplicationLoadBalancer{
Enabled: true,
Expand Down Expand Up @@ -782,6 +792,7 @@ func TestMapFields(t *testing.T) {
"zones": types.ListValueMust(types.StringType, []attr.Value{
types.StringValue("zone1"),
}),
"gateway_api": types.BoolValue(true),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(true),
Expand Down
4 changes: 4 additions & 0 deletions stackit/internal/services/ske/ske_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var testConfigVarsMax = config.Variables{
"ext_acl_allowed_cidr1": config.StringVariable("10.0.100.0/24"),
"ext_observability_enabled": config.StringVariable("false"),
"ext_dns_enabled": config.StringVariable("true"),
"ext_dns_gateway_api": config.StringVariable("true"),
"ext_application_load_balancer_enabled": config.StringVariable("true"),
"nodepool_hibernations1_start": config.StringVariable("0 18 * * *"),
"nodepool_hibernations1_end": config.StringVariable("59 23 * * *"),
Expand Down Expand Up @@ -308,6 +309,7 @@ func TestAccSKEMax(t *testing.T) {
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.acl.allowed_cidrs.0", testutil.ConvertConfigVariable(testConfigVarsMax["ext_acl_allowed_cidr1"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.observability.enabled", testutil.ConvertConfigVariable(testConfigVarsMax["ext_observability_enabled"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.dns.enabled", testutil.ConvertConfigVariable(testConfigVarsMax["ext_dns_enabled"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.dns.gateway_api", testutil.ConvertConfigVariable(testConfigVarsMax["ext_dns_gateway_api"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.dns.zones.#", "1"),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.dns.zones.0", testutil.ConvertConfigVariable(testConfigVarsMax["dns_name"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.application_load_balancer.enabled", testutil.ConvertConfigVariable(testConfigVarsMax["ext_application_load_balancer_enabled"])),
Expand Down Expand Up @@ -389,6 +391,7 @@ func TestAccSKEMax(t *testing.T) {
resource.TestCheckResourceAttr("data.stackit_ske_cluster.cluster", "extensions.acl.allowed_cidrs.0", testutil.ConvertConfigVariable(testConfigVarsMax["ext_acl_allowed_cidr1"])),
// no check for observability, as it was disabled in the setup
resource.TestCheckResourceAttr("data.stackit_ske_cluster.cluster", "extensions.dns.enabled", testutil.ConvertConfigVariable(testConfigVarsMax["ext_dns_enabled"])),
resource.TestCheckResourceAttr("data.stackit_ske_cluster.cluster", "extensions.dns.gateway_api", testutil.ConvertConfigVariable(testConfigVarsMax["ext_dns_gateway_api"])),
resource.TestCheckResourceAttr("data.stackit_ske_cluster.cluster", "extensions.dns.zones.#", "1"),
resource.TestCheckResourceAttr("data.stackit_ske_cluster.cluster", "extensions.dns.zones.0", testutil.ConvertConfigVariable(testConfigVarsMax["dns_name"])),
resource.TestCheckResourceAttr("data.stackit_ske_cluster.cluster", "extensions.application_load_balancer.enabled", testutil.ConvertConfigVariable(testConfigVarsMax["ext_application_load_balancer_enabled"])),
Expand Down Expand Up @@ -481,6 +484,7 @@ func TestAccSKEMax(t *testing.T) {
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.acl.allowed_cidrs.0", testutil.ConvertConfigVariable(configVarsMaxUpdated()["ext_acl_allowed_cidr1"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.observability.enabled", testutil.ConvertConfigVariable(configVarsMaxUpdated()["ext_observability_enabled"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.dns.enabled", testutil.ConvertConfigVariable(configVarsMaxUpdated()["ext_dns_enabled"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.dns.gateway_api", testutil.ConvertConfigVariable(configVarsMaxUpdated()["ext_dns_gateway_api"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.dns.zones.#", "1"),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.dns.zones.0", testutil.ConvertConfigVariable(configVarsMaxUpdated()["dns_name"])),
resource.TestCheckResourceAttr("stackit_ske_cluster.cluster", "extensions.application_load_balancer.enabled", testutil.ConvertConfigVariable(configVarsMaxUpdated()["ext_application_load_balancer_enabled"])),
Expand Down
6 changes: 4 additions & 2 deletions stackit/internal/services/ske/testdata/resource-max.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ variable "ext_acl_allowed_cidr1" {}
variable "ext_observability_enabled" {}
variable "ext_application_load_balancer_enabled" {}
variable "ext_dns_enabled" {}
variable "ext_dns_gateway_api" {}
variable "nodepool_hibernations1_start" {}
variable "nodepool_hibernations1_end" {}
variable "nodepool_hibernations1_timezone" {}
Expand Down Expand Up @@ -78,8 +79,9 @@ resource "stackit_ske_cluster" "cluster" {
enabled = var.ext_observability_enabled
}
dns = {
enabled = var.ext_dns_enabled
zones = [stackit_dns_zone.dns-zone.dns_name]
enabled = var.ext_dns_enabled
zones = [stackit_dns_zone.dns-zone.dns_name]
gateway_api = var.ext_dns_gateway_api
}
application_load_balancer = {
enabled = var.ext_application_load_balancer_enabled
Expand Down
Loading