Alpha (#4)
* chore: initial push to be able to work together * chore: add missing wait folder * chore: add missing folders * chore: cleanup alpha branch * feat: mssql alpha instance (#2) * fix: remove unused attribute types and functions from backup models * fix: update API client references to use sqlserverflexalpha package * fix: update package references to use sqlserverflexalpha and modify user data source model * fix: add sqlserverflexalpha user data source to provider * fix: add sqlserverflexalpha user resource and update related functionality * chore: add stackit_sqlserverflexalpha_user resource and instance_id variable * fix: refactor sqlserverflexalpha user resource and enhance schema with status and default_database --------- Co-authored-by: Andre Harms <andre.harms@stackit.cloud> Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud> * feat: add sqlserver instance * chore: fixing tests * chore: update docs --------- Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud> Co-authored-by: Andre Harms <andre.harms@stackit.cloud>
This commit is contained in:
parent
45073a716b
commit
2733834fc9
351 changed files with 62744 additions and 3 deletions
78
stackit/internal/features/experiments.go
Normal file
78
stackit/internal/features/experiments.go
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package features
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
)
|
||||
|
||||
const (
|
||||
RoutingTablesExperiment = "routing-tables"
|
||||
NetworkExperiment = "network"
|
||||
IamExperiment = "iam"
|
||||
)
|
||||
|
||||
var AvailableExperiments = []string{IamExperiment, RoutingTablesExperiment, NetworkExperiment}
|
||||
|
||||
// Check if an experiment is valid.
|
||||
func ValidExperiment(experiment string, diags *diag.Diagnostics) bool {
|
||||
validExperiment := slices.ContainsFunc(AvailableExperiments, func(e string) bool {
|
||||
return strings.EqualFold(e, experiment)
|
||||
})
|
||||
if !validExperiment {
|
||||
diags.AddError("Invalid Experiment", fmt.Sprintf("The Experiment %s is invalid. This is most likely a bug in the STACKIT Provider. Please open an issue. Available Experiments: %v", experiment, AvailableExperiments))
|
||||
}
|
||||
|
||||
return validExperiment
|
||||
}
|
||||
|
||||
// Check if an experiment is enabled.
|
||||
func CheckExperimentEnabled(ctx context.Context, data *core.ProviderData, experiment, resourceName string, resourceType core.ResourceType, diags *diag.Diagnostics) {
|
||||
if CheckExperimentEnabledWithoutError(ctx, data, experiment, resourceName, resourceType, diags) {
|
||||
return
|
||||
}
|
||||
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 CheckExperimentEnabledWithoutError(ctx context.Context, data *core.ProviderData, experiment, resourceName string, resourceType core.ResourceType, diags *diag.Diagnostics) bool {
|
||||
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"
|
||||
diags.AddError(errTitle, errContent)
|
||||
return false
|
||||
}
|
||||
experimentActive := slices.ContainsFunc(data.Experiments, func(e string) bool {
|
||||
return strings.EqualFold(e, experiment)
|
||||
})
|
||||
|
||||
if experimentActive {
|
||||
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 true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
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%s%s",
|
||||
description,
|
||||
"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.",
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue