Deprecate ske project resource (#309)

* add deprecation message

* edit acceptance test

* Enable project before creating first cluster // fix typo in function name

* add cluster existence check before deleting ske project // add deprecation message to project resource

* add region to acceptance test

* Update resource error message

Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com>

* Update resource error message

Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com>

* Update deprecation message

Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com>

* Update error message

Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com>

* remove model id assignment

* update error handling for cluster existence check while deleting project

* add nil check for clusters during project deletion

* add deprecation notice to documentation

* Update datasource deprecation message

Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com>

* improve condition handling

---------

Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com>
This commit is contained in:
GokceGK 2024-03-25 13:23:06 +01:00 committed by GitHub
parent d6c677552f
commit 0fc2a28469
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 42 additions and 13 deletions

View file

@ -3,12 +3,12 @@
page_title: "stackit_ske_project Data Source - stackit"
subcategory: ""
description: |-
SKE project data source schema. Must have a region specified in the provider configuration.
SKE project data source schema. Must have a region specified in the provider configuration. Warning: SKE project resource is no longer in use and will be removed with the next release. SKE service enablement is done automatically when a new cluster is created.
---
# stackit_ske_project (Data Source)
SKE project data source schema. Must have a `region` specified in the provider configuration.
SKE project data source schema. Must have a `region` specified in the provider configuration. Warning: SKE project resource is no longer in use and will be removed with the next release. SKE service enablement is done automatically when a new cluster is created.
## Example Usage

View file

@ -3,12 +3,12 @@
page_title: "stackit_ske_project Resource - stackit"
subcategory: ""
description: |-
SKE project resource schema. Must have a region specified in the provider configuration. This resource allows you to enable the SKE service and you can only have one per project. Deleting this resource will destroy any SKE clusters associated to the project
SKE project resource schema. Must have a region specified in the provider configuration. This resource allows you to enable the SKE service and you can only have one per project. Before deleting this resource, all SKE clusters associated to the project must be deleted. Warning: SKE project resource is no longer in use and will be removed with the next minor release. SKE service enablement is done automatically when a new cluster is created.
---
# stackit_ske_project (Resource)
SKE project resource schema. Must have a `region` specified in the provider configuration. This resource allows you to enable the SKE service and you can only have one per project. Deleting this resource will destroy any SKE clusters associated to the project
SKE project resource schema. Must have a `region` specified in the provider configuration. This resource allows you to enable the SKE service and you can only have one per project. Before deleting this resource, all SKE clusters associated to the project must be deleted. Warning: SKE project resource is no longer in use and will be removed with the next minor release. SKE service enablement is done automatically when a new cluster is created.
## Example Usage

View file

@ -552,7 +552,20 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "name", clusterName)
availableVersions, err := r.loadAvaiableVersions(ctx)
// If SKE functionality is not enabled, enable it
_, err := r.client.EnableService(ctx, projectId).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating cluster", fmt.Sprintf("Calling API to enable SKE: %v", err))
return
}
_, err = wait.EnableServiceWaitHandler(ctx, r.client, projectId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating cluster", fmt.Sprintf("Wait for SKE enablement: %v", err))
return
}
availableVersions, err := r.loadAvailableVersions(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating cluster", fmt.Sprintf("Loading available Kubernetes versions: %v", err))
return
@ -572,7 +585,7 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest
tflog.Info(ctx, "SKE cluster created")
}
func (r *clusterResource) loadAvaiableVersions(ctx context.Context) ([]ske.KubernetesVersion, error) {
func (r *clusterResource) loadAvailableVersions(ctx context.Context) ([]ske.KubernetesVersion, error) {
c := r.client
res, err := c.ListProviderOptions(ctx).Execute()
if err != nil {
@ -1423,7 +1436,7 @@ func (r *clusterResource) Update(ctx context.Context, req resource.UpdateRequest
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "name", clName)
availableVersions, err := r.loadAvaiableVersions(ctx)
availableVersions, err := r.loadAvailableVersions(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating cluster", fmt.Sprintf("Loading available Kubernetes versions: %v", err))
return

View file

@ -74,7 +74,8 @@ func (r *projectDataSource) Configure(ctx context.Context, req datasource.Config
// Schema defines the schema for the data source.
func (r *projectDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "SKE project data source schema. Must have a `region` specified in the provider configuration.",
Description: "SKE project data source schema. Must have a `region` specified in the provider configuration. Warning: SKE project resource is no longer in use and will be removed with the next release. SKE service enablement is done automatically when a new cluster is created.",
DeprecationMessage: "SKE project datasource is no longer in use and will be removed with the next minor release. SKE service enablement is done automatically when a new cluster is created.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "Terraform's internal data source. ID. It is structured as \"`project_id`\".",

View file

@ -86,7 +86,8 @@ func (r *projectResource) Configure(ctx context.Context, req resource.ConfigureR
// Schema returns the Terraform schema structure
func (r *projectResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "SKE project resource schema. Must have a `region` specified in the provider configuration. This resource allows you to enable the SKE service and you can only have one per project. Deleting this resource will destroy any SKE clusters associated to the project",
Description: "SKE project resource schema. Must have a `region` specified in the provider configuration. This resource allows you to enable the SKE service and you can only have one per project. Before deleting this resource, all SKE clusters associated to the project must be deleted. Warning: SKE project resource is no longer in use and will be removed with the next minor release. SKE service enablement is done automatically when a new cluster is created.",
DeprecationMessage: "SKE project resource is no longer in use and will be removed with the next minor release. SKE service enablement is done automatically when a new cluster is created.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "Terraform's internal resource ID. It is structured as \"`project_id`\".",
@ -182,7 +183,19 @@ func (r *projectResource) Delete(ctx context.Context, req resource.DeleteRequest
ctx = tflog.SetField(ctx, "project_id", projectId)
c := r.client
_, err := c.DisableService(ctx, projectId).Execute()
clusters, err := c.ListClusters(ctx, projectId).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting project", fmt.Sprintf("Calling API to get the list of clusters: %v", err))
return
}
if clusters != nil && len(*clusters.Items) > 0 {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting project", fmt.Sprintln("You still have clusters in the project. Please delete them before deleting the project."))
return
}
_, err = c.DisableService(ctx, projectId).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting project", fmt.Sprintf("Calling API: %v", err))
return

View file

@ -32,8 +32,8 @@ var clusterResource = map[string]string{
"nodepool_name": "np-acc-test",
"nodepool_name_min": "np-acc-min-test",
"nodepool_machine_type": "b1.2",
"nodepool_os_version": "3602.2.2",
"nodepool_os_version_min": "3602.2.2",
"nodepool_os_version": "3760.2.0",
"nodepool_os_version_min": "3760.2.0",
"nodepool_os_name": "flatcar",
"nodepool_minimum": "2",
"nodepool_maximum": "3",
@ -519,7 +519,9 @@ func testAccCheckSKEDestroy(s *terraform.State) error {
var client *ske.APIClient
var err error
if testutil.SKECustomEndpoint == "" {
client, err = ske.NewAPIClient()
client, err = ske.NewAPIClient(
config.WithRegion("eu01"),
)
} else {
client, err = ske.NewAPIClient(
config.WithEndpoint(testutil.SKECustomEndpoint),