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
16 changes: 9 additions & 7 deletions stackit/internal/services/ske/cluster/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
"extensions": schema.SingleNestedAttribute{
Description: "A single extensions block as defined below.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
Expand Down Expand Up @@ -830,13 +831,13 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
"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{
Description: "Application Load Balancer extension.",
Optional: true,
Computed: true,
Attributes: map[string]schema.Attribute{
"enabled": schema.BoolAttribute{
Description: "Enables the application load balancer extension. Note: This feature is in private preview. Enabling application load balancer extension is only possible for enabled accounts. Otherwise the request will be rejected.",
Expand Down Expand Up @@ -2029,7 +2030,7 @@ func checkDisabledExtensions(ctx context.Context, ex *extensions) (aclDisabled,
}

applicationLoadBalancer := applicationLoadBalancer{}
if ex.ApplicationLoadBalancer.IsNull() {
if utils.IsUndefined(ex.ApplicationLoadBalancer) {
applicationLoadBalancer.Enabled = types.BoolValue(false)
} else {
diags = ex.ApplicationLoadBalancer.As(ctx, &applicationLoadBalancer, basetypes.ObjectAsOptions{})
Expand All @@ -2049,11 +2050,13 @@ func mapExtensions(ctx context.Context, cl *ske.Cluster, m *Model) error {

var diags diag.Diagnostics
ex := extensions{}
if !m.Extensions.IsNull() {
if !utils.IsUndefined(m.Extensions) {
diags := m.Extensions.As(ctx, &ex, basetypes.ObjectAsOptions{})
if diags.HasError() {
return fmt.Errorf("converting extensions object: %v", diags.Errors())
}
} else {
m.Extensions = types.ObjectNull(extensionsTypes)
}

// If the user provides the extensions block with the enabled flags as false
Expand All @@ -2069,9 +2072,8 @@ func mapExtensions(ctx context.Context, cl *ske.Cluster, m *Model) error {
if err != nil {
return fmt.Errorf("checking if extensions are disabled: %w", err)
}
disabledExtensions := aclDisabled && observabilityDisabled && dnsDisabled && applicationLoadBalancerDisabled

if skeUtils.IsEmptyExtension(cl.Extensions) && (disabledExtensions || m.Extensions.IsNull()) {
if skeUtils.IsEmptyExtension(cl.Extensions) && utils.IsUndefined(m.Extensions) {
if m.Extensions.Attributes() == nil {
m.Extensions = types.ObjectNull(extensionsTypes)
}
Expand Down Expand Up @@ -2154,14 +2156,14 @@ func mapExtensions(ctx context.Context, cl *ske.Cluster, m *Model) error {
if diags.HasError() {
return fmt.Errorf("creating applicationLoadBalancer: %w", core.DiagsToError(diags))
}
} else if applicationLoadBalancerDisabled && !ex.ApplicationLoadBalancer.IsNull() {
} else if applicationLoadBalancerDisabled && !utils.IsUndefined(ex.ApplicationLoadBalancer) {
applicationLoadBalancerExtension = ex.ApplicationLoadBalancer
}

dnsExtension := types.ObjectNull(dnsTypes)
if cl.Extensions.Dns != nil {
enabled := types.BoolValue(cl.Extensions.Dns.Enabled)
gatewayApi := types.BoolValue(*cl.Extensions.Dns.GatewayApi)
gatewayApi := types.BoolPointerValue(cl.Extensions.Dns.GatewayApi)

zonesList, diags := types.ListValueFrom(ctx, types.StringType, cl.Extensions.Dns.Zones)
if diags.HasError() {
Expand Down
16 changes: 9 additions & 7 deletions stackit/internal/services/ske/cluster/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,8 @@ func TestMapFields(t *testing.T) {
Enabled: true,
},
Dns: &ske.DNS{
Zones: nil,
Enabled: true,
GatewayApi: new(true),
Zones: nil,
Enabled: true,
},
ApplicationLoadBalancer: &ske.ApplicationLoadBalancer{
Enabled: true,
Expand Down Expand Up @@ -382,7 +381,7 @@ func TestMapFields(t *testing.T) {
"dns": types.ObjectValueMust(dnsTypes, map[string]attr.Value{
"enabled": types.BoolValue(true),
"zones": types.ListNull(types.StringType),
"gateway_api": types.BoolValue(true),
"gateway_api": types.BoolNull(),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(true),
Expand All @@ -409,7 +408,7 @@ func TestMapFields(t *testing.T) {
"dns": types.ObjectValueMust(dnsTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
"zones": types.ListNull(types.StringType),
"gateway_api": types.BoolValue(false),
"gateway_api": types.BoolNull(),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
Expand Down Expand Up @@ -450,7 +449,7 @@ func TestMapFields(t *testing.T) {
"dns": types.ObjectValueMust(dnsTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
"zones": types.ListNull(types.StringType),
"gateway_api": types.BoolValue(false),
"gateway_api": types.BoolNull(),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
Expand Down Expand Up @@ -497,6 +496,9 @@ func TestMapFields(t *testing.T) {
Enabled: true,
GatewayApi: new(true),
},
ApplicationLoadBalancer: &ske.ApplicationLoadBalancer{
Enabled: true,
},
},
Name: new("name"),
Access: &ske.Access{
Expand Down Expand Up @@ -535,7 +537,7 @@ func TestMapFields(t *testing.T) {
"gateway_api": types.BoolValue(true),
}),
"application_load_balancer": types.ObjectValueMust(applicationLoadBalancerTypes, map[string]attr.Value{
"enabled": types.BoolValue(false),
"enabled": types.BoolValue(true),
}),
}),
KubernetesVersionUsed: types.StringValue(""),
Expand Down
Loading