Make server backup schedule resources beta (#434)
* Make server backup schedule resources beta * Adjust guide
This commit is contained in:
parent
b5eb8bd379
commit
5b617e0676
11 changed files with 86 additions and 22 deletions
|
|
@ -3,12 +3,15 @@
|
|||
page_title: "stackit_server_backup_schedule Data Source - stackit"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
Server backup schedule resource schema. Must have a region specified in the provider configuration.
|
||||
Server backup schedule datasource schema. Must have a region specified in the provider configuration.
|
||||
!> This resource is in beta and may be subject to breaking changes in the future. Use with caution.
|
||||
---
|
||||
|
||||
# stackit_server_backup_schedule (Data Source)
|
||||
|
||||
Server backup schedule resource schema. Must have a `region` specified in the provider configuration.
|
||||
Server backup schedule datasource schema. Must have a `region` specified in the provider configuration.
|
||||
|
||||
!> This resource is in beta and may be subject to breaking changes in the future. Use with caution.
|
||||
|
||||
## Example Usage
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,15 @@
|
|||
page_title: "stackit_server_backup_schedules Data Source - stackit"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
Server backup schedule data source schema.
|
||||
Server backup schedules datasource schema. Must have a region specified in the provider configuration.
|
||||
!> This resource is in beta and may be subject to breaking changes in the future. Use with caution.
|
||||
---
|
||||
|
||||
# stackit_server_backup_schedules (Data Source)
|
||||
|
||||
Server backup schedule data source schema.
|
||||
Server backup schedules datasource schema. Must have a `region` specified in the provider configuration.
|
||||
|
||||
!> This resource is in beta and may be subject to breaking changes in the future. Use with caution.
|
||||
|
||||
## Example Usage
|
||||
|
||||
|
|
|
|||
|
|
@ -36,4 +36,9 @@ export STACKIT_TF_ENABLE_BETA_RESOURCES=true
|
|||
|
||||
## Listing Beta Resources
|
||||
|
||||
Currently, there are no beta resources available. This section will be updated as new beta services are introduced.
|
||||
- `stackit_server_backup_schedule`
|
||||
|
||||
## Listing Beta Data Sources
|
||||
|
||||
- `stackit_server_backup_schedule`
|
||||
- `stackit_server_backup_schedules`
|
||||
|
|
@ -4,12 +4,15 @@ page_title: "stackit_server_backup_schedule Resource - stackit"
|
|||
subcategory: ""
|
||||
description: |-
|
||||
Server backup schedule resource schema. Must have a region specified in the provider configuration.
|
||||
!> This resource is in beta and may be subject to breaking changes in the future. Use with caution.
|
||||
---
|
||||
|
||||
# stackit_server_backup_schedule (Resource)
|
||||
|
||||
Server backup schedule resource schema. Must have a `region` specified in the provider configuration.
|
||||
|
||||
!> This resource is in beta and may be subject to breaking changes in the future. Use with caution.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```terraform
|
||||
|
|
|
|||
|
|
@ -69,16 +69,16 @@ func LogAndAddWarning(ctx context.Context, diags *diag.Diagnostics, summary, det
|
|||
diags.AddWarning(summary, detail)
|
||||
}
|
||||
|
||||
func LogAndAddWarningBeta(ctx context.Context, diags *diag.Diagnostics, name string) {
|
||||
warnTitle := fmt.Sprintf("The resource %q is in beta", name)
|
||||
warnContent := fmt.Sprintf("The resource %q is in beta and may be subject to breaking changes in the future. Use with caution.", name)
|
||||
func LogAndAddWarningBeta(ctx context.Context, diags *diag.Diagnostics, name, resourceType string) {
|
||||
warnTitle := fmt.Sprintf("The %s %q is in beta", resourceType, name)
|
||||
warnContent := fmt.Sprintf("The %s %q is in beta and may be subject to breaking changes in the future. Use with caution.", resourceType, name)
|
||||
tflog.Warn(ctx, fmt.Sprintf("%s | %s", warnTitle, warnContent))
|
||||
diags.AddWarning(warnTitle, warnContent)
|
||||
}
|
||||
|
||||
func LogAndAddErrorBeta(ctx context.Context, diags *diag.Diagnostics, name string) {
|
||||
errTitle := fmt.Sprintf("The resource %q is in beta and beta is not enabled", name)
|
||||
errContent := fmt.Sprintf(`The resource %q is in beta and the beta functionality is currently not enabled. To enable it, set the environment variable STACKIT_TF_ENABLE_BETA_RESOURCES to "true" or set the "enable_beta_resources" provider field to true.`, name)
|
||||
func LogAndAddErrorBeta(ctx context.Context, diags *diag.Diagnostics, name, resourceType string) {
|
||||
errTitle := fmt.Sprintf("The %s %q is in beta and beta is not enabled", resourceType, name)
|
||||
errContent := fmt.Sprintf(`The %s %q is in beta and the beta functionality is currently not enabled. To enable it, set the environment variable STACKIT_TF_ENABLE_BETA_RESOURCES to "true" or set the "enable_beta_resources" provider field to true.`, resourceType, name)
|
||||
tflog.Error(ctx, fmt.Sprintf("%s | %s", errTitle, errContent))
|
||||
diags.AddError(errTitle, errContent)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,12 +39,12 @@ 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 string) {
|
||||
func CheckBetaResourcesEnabled(ctx context.Context, data *core.ProviderData, diags *diag.Diagnostics, resourceName, resourceType string) {
|
||||
if !BetaResourcesEnabled(ctx, data, diags) {
|
||||
core.LogAndAddErrorBeta(ctx, diags, resourceName)
|
||||
core.LogAndAddErrorBeta(ctx, diags, resourceName, resourceType)
|
||||
return
|
||||
}
|
||||
core.LogAndAddWarningBeta(ctx, diags, resourceName)
|
||||
core.LogAndAddWarningBeta(ctx, diags, resourceName, resourceType)
|
||||
}
|
||||
|
||||
func AddBetaDescription(description string) string {
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ func TestCheckBetaResourcesEnabled(t *testing.T) {
|
|||
t.Setenv("STACKIT_TF_ENABLE_BETA_RESOURCES", envValue)
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
CheckBetaResourcesEnabled(context.Background(), &core.ProviderData{}, &diags, "test")
|
||||
CheckBetaResourcesEnabled(context.Background(), &core.ProviderData{}, &diags, "stackit_test", "resource")
|
||||
|
||||
if tt.expectError && diags.ErrorsCount() == 0 {
|
||||
t.Fatalf("Expected error, got none")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
||||
|
||||
|
|
@ -29,6 +30,11 @@ import (
|
|||
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
|
||||
)
|
||||
|
||||
// resourceBetaCheckDone is used to prevent multiple checks for beta resources.
|
||||
// This is a workaround for the lack of a global state in the provider and
|
||||
// needs to exist because the Configure method is called twice.
|
||||
var resourceBetaCheckDone bool
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ resource.Resource = &scheduleResource{}
|
||||
|
|
@ -82,6 +88,14 @@ func (r *scheduleResource) Configure(ctx context.Context, req resource.Configure
|
|||
return
|
||||
}
|
||||
|
||||
if !resourceBetaCheckDone {
|
||||
features.CheckBetaResourcesEnabled(ctx, &providerData, &resp.Diagnostics, "stackit_server_backup_schedule", "resource")
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
resourceBetaCheckDone = true
|
||||
}
|
||||
|
||||
var apiClient *serverbackup.APIClient
|
||||
var err error
|
||||
if providerData.ServerBackupCustomEndpoint != "" {
|
||||
|
|
@ -109,7 +123,8 @@ func (r *scheduleResource) Configure(ctx context.Context, req resource.Configure
|
|||
// Schema defines the schema for the resource.
|
||||
func (r *scheduleResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Description: "Server backup schedule resource schema. Must have a `region` specified in the provider configuration.",
|
||||
Description: "Server backup schedule resource schema. Must have a `region` specified in the provider configuration.",
|
||||
MarkdownDescription: features.AddBetaDescription("Server backup schedule resource schema. Must have a `region` specified in the provider configuration."),
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{
|
||||
Description: "Terraform's internal resource identifier. It is structured as \"`project_id`,`server_id`,`backup_schedule_id`\".",
|
||||
|
|
@ -442,7 +457,7 @@ func enableBackupsService(ctx context.Context, model *Model, client *serverbacku
|
|||
tflog.Debug(ctx, "Service for server backup already enabled")
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Failed to enable server backup service: %w", err)
|
||||
return fmt.Errorf("enable server backup service: %w", err)
|
||||
}
|
||||
tflog.Info(ctx, "Enabled server backup service")
|
||||
return nil
|
||||
|
|
@ -495,7 +510,7 @@ func toCreatePayload(model *Model) (*serverbackup.CreateBackupSchedulePayload, e
|
|||
if !(model.BackupProperties.VolumeIds.IsNull() || model.BackupProperties.VolumeIds.IsUnknown()) {
|
||||
ids, err = utils.ListValuetoStringSlice(model.BackupProperties.VolumeIds)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error by converting volume id: %w", err)
|
||||
return nil, fmt.Errorf("convert volume id: %w", err)
|
||||
}
|
||||
}
|
||||
// we should provide null to the API in case no volumeIds were chosen, else it errors
|
||||
|
|
@ -528,7 +543,7 @@ func toUpdatePayload(model *Model) (*serverbackup.UpdateBackupSchedulePayload, e
|
|||
if !(model.BackupProperties.VolumeIds.IsNull() || model.BackupProperties.VolumeIds.IsUnknown()) {
|
||||
ids, err = utils.ListValuetoStringSlice(model.BackupProperties.VolumeIds)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error by converting volume id: %w", err)
|
||||
return nil, fmt.Errorf("convert volume id: %w", err)
|
||||
}
|
||||
}
|
||||
// we should provide null to the API in case no volumeIds were chosen, else it errors
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
|
@ -20,6 +21,11 @@ import (
|
|||
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
|
||||
)
|
||||
|
||||
// scheduleDataSourceBetaCheckDone is used to prevent multiple checks for beta resources.
|
||||
// This is a workaround for the lack of a global state in the provider and
|
||||
// needs to exist because the Configure method is called twice.
|
||||
var scheduleDataSourceBetaCheckDone bool
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &scheduleDataSource{}
|
||||
|
|
@ -53,6 +59,14 @@ func (r *scheduleDataSource) Configure(ctx context.Context, req datasource.Confi
|
|||
return
|
||||
}
|
||||
|
||||
if !scheduleDataSourceBetaCheckDone {
|
||||
features.CheckBetaResourcesEnabled(ctx, &providerData, &resp.Diagnostics, "stackit_server_backup_schedule", "data source")
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
scheduleDataSourceBetaCheckDone = true
|
||||
}
|
||||
|
||||
var apiClient *serverbackup.APIClient
|
||||
var err error
|
||||
if providerData.ServerBackupCustomEndpoint != "" {
|
||||
|
|
@ -80,7 +94,8 @@ func (r *scheduleDataSource) Configure(ctx context.Context, req datasource.Confi
|
|||
// Schema defines the schema for the data source.
|
||||
func (r *scheduleDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Description: "Server backup schedule resource schema. Must have a `region` specified in the provider configuration.",
|
||||
Description: "Server backup schedule datasource schema. Must have a `region` specified in the provider configuration.",
|
||||
MarkdownDescription: features.AddBetaDescription("Server backup schedule datasource schema. Must have a `region` specified in the provider configuration."),
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{
|
||||
Description: "Terraform's internal resource identifier. It is structured as \"`project_id`,`server_id`,`backup_schedule_id`\".",
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
|
|
@ -19,6 +20,11 @@ import (
|
|||
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
|
||||
)
|
||||
|
||||
// scheduleDataSourceBetaCheckDone is used to prevent multiple checks for beta resources.
|
||||
// This is a workaround for the lack of a global state in the provider and
|
||||
// needs to exist because the Configure method is called twice.
|
||||
var schedulesDataSourceBetaCheckDone bool
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &schedulesDataSource{}
|
||||
|
|
@ -52,6 +58,14 @@ func (r *schedulesDataSource) Configure(ctx context.Context, req datasource.Conf
|
|||
return
|
||||
}
|
||||
|
||||
if !schedulesDataSourceBetaCheckDone {
|
||||
features.CheckBetaResourcesEnabled(ctx, &providerData, &resp.Diagnostics, "stackit_server_backup_schedules", "data source")
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
schedulesDataSourceBetaCheckDone = true
|
||||
}
|
||||
|
||||
var apiClient *serverbackup.APIClient
|
||||
var err error
|
||||
if providerData.ServerBackupCustomEndpoint != "" {
|
||||
|
|
@ -79,7 +93,8 @@ func (r *schedulesDataSource) Configure(ctx context.Context, req datasource.Conf
|
|||
// Schema defines the schema for the data source.
|
||||
func (r *schedulesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Description: "Server backup schedule data source schema.",
|
||||
Description: "Server backup schedules datasource schema. Must have a `region` specified in the provider configuration.",
|
||||
MarkdownDescription: features.AddBetaDescription("Server backup schedules datasource schema. Must have a `region` specified in the provider configuration."),
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{
|
||||
Description: "Terraform's internal data source identifier. It is structured as \"`project_id`,`server_id`\".",
|
||||
|
|
|
|||
|
|
@ -36,4 +36,9 @@ export STACKIT_TF_ENABLE_BETA_RESOURCES=true
|
|||
|
||||
## Listing Beta Resources
|
||||
|
||||
Currently, there are no beta resources available. This section will be updated as new beta services are introduced.
|
||||
- `stackit_server_backup_schedule`
|
||||
|
||||
## Listing Beta Data Sources
|
||||
|
||||
- `stackit_server_backup_schedule`
|
||||
- `stackit_server_backup_schedules`
|
||||
Loading…
Add table
Add a link
Reference in a new issue