Skip to content

Conversation

@david-mey-STACKIT
Copy link

Description

STACKITLB-798

Add Application Load Balancer provider (API: https://docs.api.stackit.cloud/documentation/alb/version/v2)

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@h3adex
Copy link
Contributor

h3adex commented Feb 6, 2026

imo we should use stackit_application_loadbalancer instead of stackit_alb as resource/datasource naming.

go.mod Outdated
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.3.1
github.com/teambition/rrule-go v1.8.2
golang.org/x/mod v0.30.0
k8s.io/utils v0.0.0-20260108192941-914a6e750570
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add a new module just for a to pointer utils function.
We already have the same function in the core module of our SDK. Replace the ptr.to() to utils.Ptr()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thx didn't know this existed

The example below creates the supporting infrastructure using the STACKIT Terraform provider, including the network, network interface, a public IP address and server resources.
---

# stackit_alb (Data Source)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like @h3adex already suggested, I would prefer as well that the datasource and resource is named application_load_balancer. This makes it easier for first time users to understand for what resource and datasource

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, will change it. I dislike that its so long, but i get why we need it

Comment on lines 12 to 15
## Setting up supporting infrastructure


The example below creates the supporting infrastructure using the STACKIT Terraform provider, including the network, network interface, a public IP address and server resources.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description doesn't fit to the datasource

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max acc test is failing

    alb_acc_test.go:305: Step 1/4 error: Error running apply: exit status 1
        
        Error: Error updating Application Load Balancer
        
          with stackit_alb.loadbalancer,
          on terraform_plugin_test.tf line 169, in resource "stackit_alb" "loadbalancer":
         169: resource "stackit_alb" "loadbalancer" {
        
        Calling API for create: 400 Bad Request, status code 400, Body:
        {
          "code": 3,
          "message": "one or more fields are invalid",
          "details": [
            {
              "@type": "type.googleapis.com/google.rpc.BadRequest.FieldViolation",
              "field": "loadBalancer.listeners[0].https.certificateConfig.certificateIds[0]",
              "description": "The specified certificate \"name-v1-8c81bd317af8a03b8ef0851ccb074eb17d1ad589b540446244a5e593f78ef820\" does not exist."
            }
          ]
        }
--- FAIL: TestAccALBResourceMax (117.56s)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes thats a resource I wanted to test that not in TF yet. I'll take it out for now

Comment on lines 20 to 21
if providerData.LoadBalancerCustomEndpoint != "" {
apiClientConfigOptions = append(apiClientConfigOptions, config.WithEndpoint(providerData.LoadBalancerCustomEndpoint))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong custom endpoint

Description: descriptions["options"],
Computed: true,
Attributes: map[string]schema.Attribute{
"acl": schema.SetAttribute{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be close to the api names. And this is actually an objects which has a property allowed_source_ranges. Keep the struct like in the api, because when the api changes in the future, we can't adjust the provider like the api is adjusted

Suggested change
"acl": schema.SetAttribute{
"access_control": schema. SingleNestedAttribute{

resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this function here. You may need to update your branch

Suggested change
}
}
ctx = core.InitProviderContext(ctx)

)
resp.State.RemoveResource(ctx)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}
ctx = core.LogResponse(ctx)

&resp.Diagnostics,
err,
"Reading application load balancer",
fmt.Sprintf("Load balancer with name %q does not exist in project %q.", name, projectId),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Sprintf("Load balancer with name %q does not exist in project %q.", name, projectId),
fmt.Sprintf("Application load balancer with name %q does not exist in project %q.", name, projectId),

if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "Load balancer read")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tflog.Info(ctx, "Load balancer read")
tflog.Info(ctx, "Application load balancer read")

david-mey-STACKIT added a commit to david-mey-STACKIT/terraform-provider-stackit that referenced this pull request Feb 9, 2026
Comment on lines 414 to 417
protocolOptions := albUtils.ToStringList(albSdk.AllowedListenerProtocolEnumValues)
roleOptions := albUtils.ToStringList(albSdk.AllowedNetworkRoleEnumValues)
errorOptions := albUtils.ToStringList(albSdk.AllowedLoadBalancerErrorTypesEnumValues)
servicePlanOptions := []string{"p10"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same like mentioned for the datasource. check if the sdk has already the enums as list and use it here to decrease maintenance overhead

Comment on lines 388 to 394
func (r *applicationLoadBalancerResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
// Do nothing!
// We do not validate the TF input, because the API does that and
// maintaining and syncing between them is not worth it, because
// 400 Bad Request error gives all the details the user needs via the API in TF, which
// also is the single source of truth.
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an optional method which is not mandatory to implement for the terraform provider. So you can just remove it :)

Comment on lines +531 to +533
Validators: []validator.String{
stringvalidator.LengthBetween(4, 6),
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this validator

Comment on lines 548 to 569
"errors": schema.SetNestedAttribute{
Description: descriptions["errors"],
Computed: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{
Description: descriptions["errors.type"],
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"description": schema.StringAttribute{
Description: descriptions["errors.description"],
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These attributes shouldn't need the plan modifier UseStateForUnknown

"observability_metrics": "Observability metrics configuration.",
"observability_metrics_credentials_ref": "Credentials reference for metrics. This reference is created via the observability create endpoint and the credential needs to contain the basic auth username and password for the metrics solution the push URL points to. Then this enables monitoring via remote write for the Application Load Balancer.",
"observability_metrics_push_url": "The Observability(Metrics)/Prometheus remote write push URL you want the metrics to be shipped to.",
"plan_id": "Service Plan configures the size of the Application Load Balancer. " + utils.FormatPossibleValues(servicePlanOptions...) + ". See available plans via STACKIT CLI 'stackit alb plans' or API https://docs.api.stackit.cloud/documentation/alb/version/v2#tag/Project/operation/APIService_ListPlans",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we have the alb plans still as a beta command

Suggested change
"plan_id": "Service Plan configures the size of the Application Load Balancer. " + utils.FormatPossibleValues(servicePlanOptions...) + ". See available plans via STACKIT CLI 'stackit alb plans' or API https://docs.api.stackit.cloud/documentation/alb/version/v2#tag/Project/operation/APIService_ListPlans",
"plan_id": "Service Plan configures the size of the Application Load Balancer. " + utils.FormatPossibleValues(servicePlanOptions...) + ". See available plans via STACKIT CLI 'stackit beta alb plans' or API https://docs.api.stackit.cloud/documentation/alb/version/v2#tag/Project/operation/APIService_ListPlans",

Copy link
Author

@david-mey-STACKIT david-mey-STACKIT Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will change. Will you take care of updating this once the CLI is GA? Is updating the CLI complex or is there an automated tool for it?

target_port = var.target_pool_port
targets = [
{
display_name = var.target_display_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding the docs display_name is optional and therefore not be set in the min test

Comment on lines 209 to 212
resource.TestCheckResourceAttrSet("stackit_application_load_balancer.loadbalancer", "target_security_group.id"),
resource.TestCheckResourceAttrSet("stackit_application_load_balancer.loadbalancer", "target_security_group.name"),
resource.TestCheckResourceAttrSet("stackit_application_load_balancer.loadbalancer", "load_balancer_security_group.id"),
resource.TestCheckResourceAttrSet("stackit_application_load_balancer.loadbalancer", "load_balancer_security_group.name"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you check the resource instead of the datasource

Comment on lines +112 to +113
maps.Copy(tempConfig, testConfigVarsMin)
tempConfig["target_pool_port"] = config.StringVariable("5431")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't there more fields which can be updated in-place in the minimal config? like rename the target pool or change the target pool at all or change the listeners?

Comment on lines 289 to 293
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("stackit_application_load_balancer.loadbalancer", "project_id", testutil.ConvertConfigVariable(testConfigVarsMin["project_id"])),
resource.TestCheckResourceAttr("stackit_application_load_balancer.loadbalancer", "name", testutil.ConvertConfigVariable(testConfigVarsMin["loadbalancer_name"])),
resource.TestCheckResourceAttr("stackit_application_load_balancer.loadbalancer", "target_pools.0.target_port", testutil.ConvertConfigVariable(configVarsMinUpdated()["target_pool_port"])),
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check here all fields like in the Create step. With the only difference that here the updated configVars is used

Comment on lines +507 to +509
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("stackit_application_load_balancer.loadbalancer", "project_id", testutil.ConvertConfigVariable(testConfigVarsMax["project_id"])),
resource.TestCheckResourceAttr("stackit_application_load_balancer.loadbalancer", "name", testutil.ConvertConfigVariable(testConfigVarsMax["loadbalancer_name"])),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. you can basically copy all the checks from the Create step and replace testConfigVarsMax by configVarsMaxUpdated()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants