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
1 change: 1 addition & 0 deletions docs/data-sources/ske_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,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 @@ -169,6 +169,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,
},
},
},
},
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 @@ -260,14 +260,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 @@ -813,6 +815,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,
},
},
},
},
Expand Down Expand Up @@ -1456,15 +1463,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 @@ -2092,15 +2101,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),
},
},
Hibernation: &ske.Hibernation{
Expand Down Expand Up @@ -274,6 +275,7 @@ func TestMapFields(t *testing.T) {
"zones": types.ListValueMust(types.StringType, []attr.Value{
types.StringValue("foo.onstackit.cloud"),
}),
"gateway_api": types.BoolValue(true),
}),
}),
Region: types.StringValue(testRegion),
Expand Down Expand Up @@ -334,8 +336,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 @@ -368,8 +371,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),
}),
}),
KubernetesVersionUsed: types.StringValue(""),
Expand All @@ -391,8 +395,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),
}),
}),
types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
Expand Down Expand Up @@ -428,8 +433,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),
}),
}),
KubernetesVersionUsed: types.StringValue(""),
Expand All @@ -453,8 +459,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),
}),
}),
types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
Expand All @@ -465,8 +472,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 @@ -501,8 +509,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),
}),
}),
KubernetesVersionUsed: types.StringValue(""),
Expand Down Expand Up @@ -595,8 +604,9 @@ func TestMapFields(t *testing.T) {
Enabled: true,
},
Dns: &ske.DNS{
Zones: []string{"zone1"},
Enabled: true,
Zones: []string{"zone1"},
Enabled: true,
GatewayApi: new(true),
},
},
Hibernation: &ske.Hibernation{
Expand Down Expand Up @@ -755,6 +765,7 @@ func TestMapFields(t *testing.T) {
"zones": types.ListValueMust(types.StringType, []attr.Value{
types.StringValue("zone1"),
}),
"gateway_api": types.BoolValue(true),
}),
}),
Region: types.StringValue(testRegion),
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"),
"nodepool_hibernations1_start": config.StringVariable("0 18 * * *"),
"nodepool_hibernations1_end": config.StringVariable("59 23 * * *"),
"nodepool_hibernations1_timezone": config.StringVariable("Europe/Berlin"),
Expand Down Expand Up @@ -306,6 +307,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"])),

Expand Down Expand Up @@ -386,6 +388,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"])),

Expand Down Expand Up @@ -477,6 +480,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"])),

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 @@ -21,6 +21,7 @@ variable "ext_acl_enabled" {}
variable "ext_acl_allowed_cidr1" {}
variable "ext_observability_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 @@ -77,8 +78,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
}
}
hibernations = [{
Expand Down
Loading