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
48
stackit/internal/utils/attributes.go
Normal file
48
stackit/internal/utils/attributes.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
)
|
||||
|
||||
type attributeGetter interface {
|
||||
GetAttribute(ctx context.Context, attributePath path.Path, target interface{}) diag.Diagnostics
|
||||
}
|
||||
|
||||
func ToTime(ctx context.Context, format string, val types.String, target *time.Time) (diags diag.Diagnostics) {
|
||||
var err error
|
||||
text := val.ValueString()
|
||||
*target, err = time.Parse(format, text)
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &diags, "cannot parse date", fmt.Sprintf("cannot parse date %q with format %q: %v", text, format, err))
|
||||
return diags
|
||||
}
|
||||
return diags
|
||||
}
|
||||
|
||||
// GetTimeFromStringAttribute retrieves a string attribute from e.g. a [plan.Plan], [tfsdk.Config] or a [tfsdk.State] and
|
||||
// converts it to a [time.Time] object with a given format, if possible.
|
||||
func GetTimeFromStringAttribute(ctx context.Context, attributePath path.Path, source attributeGetter, dateFormat string, target *time.Time) (diags diag.Diagnostics) {
|
||||
var date types.String
|
||||
diags.Append(source.GetAttribute(ctx, attributePath, &date)...)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
if date.IsNull() || date.IsUnknown() {
|
||||
return diags
|
||||
}
|
||||
diags.Append(ToTime(ctx, dateFormat, date, target)...)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue