feat(iaas): add experimental support for routing tables and routes (#896)

* Merged PR 788126: feat(iaas): Onboard routing tables

feat(iaas): Onboard routing tables

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Merged PR 793350: fix(routingtable): region attribute is missing in scheme

fix(routingtable): region attribute is missing in scheme

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Merged PR 797968: feat(iaas): onboarding of routing table routes

relates to STACKITTPR-241

* use iaasalpha sdk from github

* resolve todos

* remove routes from routing table model

* restructure packages

* acc tests routing tables

* add acc tests for routes

* chore(iaas): mark routing table resources as experimental

* chore(deps): use iaasalpha sdk v0.1.19-alpha

* Review feedback

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

---------

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
Co-authored-by: Alexander Dahmen (EXT) <Alexander.Dahmen_ext@external.mail.schwarz>
Co-authored-by: Alexander Dahmen <alexander.dahmen@inovex.de>
This commit is contained in:
Ruben Hönle 2025-07-02 10:30:50 +02:00 committed by GitHub
parent d2c51afbe5
commit 9ff9b8f610
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
65 changed files with 5160 additions and 53 deletions

View file

@ -39,7 +39,7 @@ Defaulting to the provider feature flag.`, value)
//
// Should be called in the Configure method of a beta resource.
// Then, check for Errors in the diags using the diags.HasError() method.
func CheckBetaResourcesEnabled(ctx context.Context, data *core.ProviderData, diags *diag.Diagnostics, resourceName, resourceType string) {
func CheckBetaResourcesEnabled(ctx context.Context, data *core.ProviderData, diags *diag.Diagnostics, resourceName string, resourceType core.ResourceType) {
if !BetaResourcesEnabled(ctx, data, diags) {
core.LogAndAddErrorBeta(ctx, diags, resourceName, resourceType)
return
@ -47,11 +47,11 @@ func CheckBetaResourcesEnabled(ctx context.Context, data *core.ProviderData, dia
core.LogAndAddWarningBeta(ctx, diags, resourceName, resourceType)
}
func AddBetaDescription(description string) string {
func AddBetaDescription(description string, resourceType core.ResourceType) string {
// Callout block: https://developer.hashicorp.com/terraform/registry/providers/docs#callouts
return fmt.Sprintf("%s\n\n~> %s %s",
description,
"This resource is in beta and may be subject to breaking changes in the future. Use with caution.",
fmt.Sprintf("This %s is in beta and may be subject to breaking changes in the future. Use with caution.", resourceType),
"See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.",
)
}

View file

@ -11,7 +11,11 @@ import (
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
)
var AvailableExperiments []string = []string{"iam"}
const (
RoutingTablesExperiment = "routing-tables"
)
var AvailableExperiments = []string{"iam", RoutingTablesExperiment}
// Check if an experiment is valid.
func ValidExperiment(experiment string, diags *diag.Diagnostics) bool {
@ -26,7 +30,7 @@ func ValidExperiment(experiment string, diags *diag.Diagnostics) bool {
}
// Check if an experiment is enabled.
func CheckExperimentEnabled(ctx context.Context, data *core.ProviderData, experiment, resourceType string, diags *diag.Diagnostics) {
func CheckExperimentEnabled(ctx context.Context, data *core.ProviderData, experiment, resourceName string, resourceType core.ResourceType, diags *diag.Diagnostics) {
if !ValidExperiment(experiment, diags) {
errTitle := fmt.Sprintf("The experiment %s does not exist.", experiment)
errContent := "This is a bug in the STACKIT Terraform Provider. Please open an issue here: https://github.com/stackitcloud/terraform-provider-stackit/issues"
@ -38,23 +42,25 @@ func CheckExperimentEnabled(ctx context.Context, data *core.ProviderData, experi
})
if experimentActive {
warnTitle := fmt.Sprintf("%s is part of the %s experiment.", resourceType, experiment)
warnContent := fmt.Sprintf("This resource is part of the %s experiment and is likely going to undergo significant changes or be removed in the future. Use it at your own discretion.", experiment)
warnTitle := fmt.Sprintf("%s is part of the %s experiment.", resourceName, experiment)
warnContent := fmt.Sprintf("This %s is part of the %s experiment and is likely going to undergo significant changes or be removed in the future. Use it at your own discretion.", resourceType, experiment)
tflog.Warn(ctx, fmt.Sprintf("%s | %s", warnTitle, warnContent))
diags.AddWarning(warnTitle, warnContent)
return
}
errTitle := fmt.Sprintf("%s is part of the %s experiment, which is currently disabled by default", resourceType, experiment)
errTitle := fmt.Sprintf("%s is part of the %s experiment, which is currently disabled by default", resourceName, experiment)
errContent := fmt.Sprintf(`Enable the %s experiment by adding it into your provider block.`, experiment)
tflog.Error(ctx, fmt.Sprintf("%s | %s", errTitle, errContent))
diags.AddError(errTitle, errContent)
}
func AddExperimentDescription(description, experiment string) string {
func AddExperimentDescription(description, experiment string, resourceType core.ResourceType) string {
// Callout block: https://developer.hashicorp.com/terraform/registry/providers/docs#callouts
return fmt.Sprintf("%s\n\n~> %s%s%s",
return fmt.Sprintf("%s\n\n~> %s%s%s%s%s",
description,
"This resource is part of the ",
"This ",
resourceType,
" is part of the ",
experiment,
" experiment and is likely going to undergo significant changes or be removed in the future. Use it at your own discretion.",
)

View file

@ -49,7 +49,8 @@ func TestCheckExperimentEnabled(t *testing.T) {
ctx context.Context
data *core.ProviderData
experiment string
resourceType string
resourceName string
resourceType core.ResourceType
diags *diag.Diagnostics
}
tests := []struct {
@ -65,8 +66,9 @@ func TestCheckExperimentEnabled(t *testing.T) {
data: &core.ProviderData{
Experiments: []string{"iam"},
},
experiment: "iam",
diags: &diag.Diagnostics{},
experiment: "iam",
resourceType: core.Resource,
diags: &diag.Diagnostics{},
},
wantDiagsErr: false,
wantDiagsWarning: true,
@ -78,8 +80,9 @@ func TestCheckExperimentEnabled(t *testing.T) {
data: &core.ProviderData{
Experiments: []string{},
},
experiment: "iam",
diags: &diag.Diagnostics{},
experiment: "iam",
resourceType: core.Resource,
diags: &diag.Diagnostics{},
},
wantDiagsErr: true,
wantDiagsWarning: false,
@ -92,7 +95,7 @@ func TestCheckExperimentEnabled(t *testing.T) {
Experiments: []string{"iam"},
},
experiment: "foobar",
resourceType: "provider",
resourceType: core.Resource,
diags: &diag.Diagnostics{},
},
wantDiagsErr: true,
@ -101,7 +104,7 @@ func TestCheckExperimentEnabled(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
CheckExperimentEnabled(tt.args.ctx, tt.args.data, tt.args.experiment, tt.args.resourceType, tt.args.diags)
CheckExperimentEnabled(tt.args.ctx, tt.args.data, tt.args.experiment, tt.args.resourceName, tt.args.resourceType, tt.args.diags)
if got := tt.args.diags.HasError(); got != tt.wantDiagsErr {
t.Errorf("CheckExperimentEnabled() diags.HasError() = %v, want %v", got, tt.wantDiagsErr)
}