diff --git a/docs/data-sources/server_backup_schedule.md b/docs/data-sources/server_backup_schedule.md index 222fd43a..f607fbd3 100644 --- a/docs/data-sources/server_backup_schedule.md +++ b/docs/data-sources/server_backup_schedule.md @@ -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 diff --git a/docs/data-sources/server_backup_schedules.md b/docs/data-sources/server_backup_schedules.md index 4a900f91..edbb813a 100644 --- a/docs/data-sources/server_backup_schedules.md +++ b/docs/data-sources/server_backup_schedules.md @@ -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 diff --git a/docs/guides/opting_into_beta_resources.md b/docs/guides/opting_into_beta_resources.md index d4ac3c71..771a1c5e 100644 --- a/docs/guides/opting_into_beta_resources.md +++ b/docs/guides/opting_into_beta_resources.md @@ -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. \ No newline at end of file +- `stackit_server_backup_schedule` + +## Listing Beta Data Sources + +- `stackit_server_backup_schedule` +- `stackit_server_backup_schedules` \ No newline at end of file diff --git a/docs/resources/server_backup_schedule.md b/docs/resources/server_backup_schedule.md index a18da224..6415f2f3 100644 --- a/docs/resources/server_backup_schedule.md +++ b/docs/resources/server_backup_schedule.md @@ -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 diff --git a/stackit/internal/core/core.go b/stackit/internal/core/core.go index a2eba28a..96d79ce3 100644 --- a/stackit/internal/core/core.go +++ b/stackit/internal/core/core.go @@ -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) } diff --git a/stackit/internal/features/beta.go b/stackit/internal/features/beta.go index 0ccf0e45..fd806b16 100644 --- a/stackit/internal/features/beta.go +++ b/stackit/internal/features/beta.go @@ -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 { diff --git a/stackit/internal/features/beta_test.go b/stackit/internal/features/beta_test.go index 0e34c630..242636c5 100644 --- a/stackit/internal/features/beta_test.go +++ b/stackit/internal/features/beta_test.go @@ -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") diff --git a/stackit/internal/services/serverbackup/schedule/resource.go b/stackit/internal/services/serverbackup/schedule/resource.go index efae47eb..ca68b438 100644 --- a/stackit/internal/services/serverbackup/schedule/resource.go +++ b/stackit/internal/services/serverbackup/schedule/resource.go @@ -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 diff --git a/stackit/internal/services/serverbackup/schedule/schedule_datasource.go b/stackit/internal/services/serverbackup/schedule/schedule_datasource.go index 4c924a3a..37beafc1 100644 --- a/stackit/internal/services/serverbackup/schedule/schedule_datasource.go +++ b/stackit/internal/services/serverbackup/schedule/schedule_datasource.go @@ -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`\".", diff --git a/stackit/internal/services/serverbackup/schedule/schedules_datasource.go b/stackit/internal/services/serverbackup/schedule/schedules_datasource.go index 9571f834..8c3c22e1 100644 --- a/stackit/internal/services/serverbackup/schedule/schedules_datasource.go +++ b/stackit/internal/services/serverbackup/schedule/schedules_datasource.go @@ -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`\".", diff --git a/templates/guides/opting_into_beta_resources.md.tmpl b/templates/guides/opting_into_beta_resources.md.tmpl index d4ac3c71..771a1c5e 100644 --- a/templates/guides/opting_into_beta_resources.md.tmpl +++ b/templates/guides/opting_into_beta_resources.md.tmpl @@ -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. \ No newline at end of file +- `stackit_server_backup_schedule` + +## Listing Beta Data Sources + +- `stackit_server_backup_schedule` +- `stackit_server_backup_schedules` \ No newline at end of file