chore(iaas): move beta resources and datasources to GA (#717)

relates to STACKITTPR-103
This commit is contained in:
Ruben Hönle 2025-03-26 09:23:25 +01:00 committed by GitHub
parent 176fb8408f
commit 727d67af01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
59 changed files with 80 additions and 518 deletions

View file

@ -2,11 +2,9 @@ package server
const markdownDescription = `
Server resource schema. Must have a region specified in the provider configuration.` + "\n" + `
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. 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.
## Example Usage` + "\n" + `
### With key pair` + "\n" +
"```terraform" + `
resource "stackit_key_pair" "keypair" {
name = "example-key-pair"
@ -28,7 +26,6 @@ resource "stackit_server" "user-data-from-file" {
` + "\n```" + `
### Boot from volume` + "\n" +
"```terraform" + `
resource "stackit_server" "boot-from-volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@ -45,7 +42,6 @@ resource "stackit_server" "boot-from-volume" {
` + "\n```" + `
### Boot from existing volume` + "\n" +
"```terraform" + `
resource "stackit_volume" "example-volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@ -72,7 +68,6 @@ resource "stackit_server" "boot-from-volume" {
` + "\n```" + `
### Network setup` + "\n" +
"```terraform" + `
resource "stackit_server" "server-with-network" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@ -125,7 +120,6 @@ resource "stackit_server_network_interface_attach" "nic-attachment" {
` + "\n```" + `
### Server with attached volume` + "\n" +
"```terraform" + `
resource "stackit_volume" "example-volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@ -156,7 +150,6 @@ resource "stackit_server_volume_attach" "attach_volume" {
` + "\n```" + `
### Server with user data (cloud-init)` + "\n" +
"```terraform" + `
resource "stackit_server" "user-data" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

View file

@ -18,16 +18,10 @@ import (
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
"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"
)
// serverDataSourceBetaCheckDone 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 serverDataSourceBetaCheckDone bool
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &serverDataSource{}
@ -82,14 +76,6 @@ func (d *serverDataSource) Configure(ctx context.Context, req datasource.Configu
return
}
if !serverDataSourceBetaCheckDone {
features.CheckBetaResourcesEnabled(ctx, &providerData, &resp.Diagnostics, "stackit_server", "data source")
if resp.Diagnostics.HasError() {
return
}
serverDataSourceBetaCheckDone = true
}
if providerData.IaaSCustomEndpoint != "" {
apiClient, err = iaas.NewAPIClient(
config.WithCustomAuth(providerData.RoundTripper),
@ -112,9 +98,10 @@ func (d *serverDataSource) Configure(ctx context.Context, req datasource.Configu
// Schema defines the schema for the datasource.
func (r *serverDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
description := "Server datasource schema. Must have a `region` specified in the provider configuration."
resp.Schema = schema.Schema{
MarkdownDescription: features.AddBetaDescription("Server datasource schema. Must have a `region` specified in the provider configuration."),
Description: "Server datasource schema. Must have a `region` specified in the provider configuration.",
MarkdownDescription: description,
Description: description,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "Terraform's internal resource ID. It is structured as \"`project_id`,`server_id`\".",

View file

@ -33,16 +33,10 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
"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"
)
// 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 = &serverResource{}
@ -162,14 +156,6 @@ func (r *serverResource) Configure(ctx context.Context, req resource.ConfigureRe
return
}
if !resourceBetaCheckDone {
features.CheckBetaResourcesEnabled(ctx, &providerData, &resp.Diagnostics, "stackit_server", "resource")
if resp.Diagnostics.HasError() {
return
}
resourceBetaCheckDone = true
}
var apiClient *iaas.APIClient
var err error
if providerData.IaaSCustomEndpoint != "" {
@ -982,9 +968,11 @@ func toCreatePayload(ctx context.Context, model *Model) (*iaas.CreateServerPaylo
}
}
var userData *string
var userData *[]byte
if !model.UserData.IsNull() && !model.UserData.IsUnknown() {
encodedUserData := base64.StdEncoding.EncodeToString([]byte(model.UserData.ValueString()))
src := []byte(model.UserData.ValueString())
encodedUserData := make([]byte, base64.StdEncoding.EncodedLen(len(src)))
base64.StdEncoding.Encode(encodedUserData, src)
userData = &encodedUserData
}

View file

@ -216,7 +216,7 @@ func TestToCreatePayload(t *testing.T) {
ImageId: utils.Ptr("image"),
KeypairName: utils.Ptr("keypair"),
MachineType: utils.Ptr("machine_type"),
UserData: utils.Ptr(base64EncodedUserData),
UserData: utils.Ptr([]byte(base64EncodedUserData)),
},
true,
},
@ -258,7 +258,7 @@ func TestToCreatePayload(t *testing.T) {
ImageId: utils.Ptr("image"),
KeypairName: utils.Ptr("keypair"),
MachineType: utils.Ptr("machine_type"),
UserData: utils.Ptr(base64EncodedUserData),
UserData: utils.Ptr([]byte(base64EncodedUserData)),
},
true,
},