Skip to content

Commit e553628

Browse files
authored
Remove CRUD method logic from PostgreSQL (first step of removal) (#423)
* Remove CRUD method logic from PostgreSQL (first step of removal) * remove comment * removed unused vars and parameters * move verb tense to the past * also datasource * apply change to credential * improve error message, remove acc testing * update docs
1 parent 2a0998f commit e553628

11 files changed

Lines changed: 40 additions & 1628 deletions

File tree

docs/data-sources/postgresql_credential.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ page_title: "stackit_postgresql_credential Data Source - stackit"
44
subcategory: ""
55
description: |-
66
PostgreSQL credential data source schema. Must have a region specified in the provider configuration.
7-
!> The STACKIT PostgreSQL service will reach its end of support on June 30th 2024. Data sources of this type will stop working after that. Use stackitpostgresflexuser instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
7+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackitpostgresflexuser instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
88
---
99

1010
# stackit_postgresql_credential (Data Source)
1111

1212
PostgreSQL credential data source schema. Must have a `region` specified in the provider configuration.
1313

14-
!> The STACKIT PostgreSQL service will reach its end of support on June 30th 2024. Data sources of this type will stop working after that. Use stackit_postgresflex_user instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
14+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_user instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
1515

1616
## Example Usage
1717

docs/data-sources/postgresql_instance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ page_title: "stackit_postgresql_instance Data Source - stackit"
44
subcategory: ""
55
description: |-
66
PostgreSQL instance data source schema. Must have a region specified in the provider configuration.
7-
!> The STACKIT PostgreSQL service will reach its end of support on June 30th 2024. Data sources of this type will stop working after that. Use stackitpostgresflexinstance instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
7+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackitpostgresflexinstance instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
88
---
99

1010
# stackit_postgresql_instance (Data Source)
1111

1212
PostgreSQL instance data source schema. Must have a `region` specified in the provider configuration.
1313

14-
!> The STACKIT PostgreSQL service will reach its end of support on June 30th 2024. Data sources of this type will stop working after that. Use stackit_postgresflex_instance instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
14+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_instance instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
1515

1616
## Example Usage
1717

docs/resources/postgresql_credential.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ page_title: "stackit_postgresql_credential Resource - stackit"
44
subcategory: ""
55
description: |-
66
PostgreSQL credential resource schema. Must have a region specified in the provider configuration.
7-
!> The STACKIT PostgreSQL service will reach its end of support on June 30th 2024. Resources of this type will stop working after that. Use stackitpostgresflexuser instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
7+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackitpostgresflexuser instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
88
---
99

1010
# stackit_postgresql_credential (Resource)
1111

1212
PostgreSQL credential resource schema. Must have a `region` specified in the provider configuration.
1313

14-
!> The STACKIT PostgreSQL service will reach its end of support on June 30th 2024. Resources of this type will stop working after that. Use stackit_postgresflex_user instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
14+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_user instead. For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html
1515

1616
## Example Usage
1717

docs/resources/postgresql_instance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ page_title: "stackit_postgresql_instance Resource - stackit"
44
subcategory: ""
55
description: |-
66
PostgreSQL instance resource schema. Must have a region specified in the provider configuration.
7-
!> The STACKIT PostgreSQL service will reach its end of support on June 30th 2024. Resources of this type will stop working after that. Use stackitpostgresflexinstance instead. Check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html on how to backup and restore an instance from PostgreSQL to PostgreSQL Flex, then import the resource to Terraform using an "import" block (https://developer.hashicorp.com/terraform/language/import)
7+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackitpostgresflexinstance instead. Check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html on how to backup and restore an instance from PostgreSQL to PostgreSQL Flex, then import the resource to Terraform using an "import" block (https://developer.hashicorp.com/terraform/language/import)
88
---
99

1010
# stackit_postgresql_instance (Resource)
1111

1212
PostgreSQL instance resource schema. Must have a `region` specified in the provider configuration.
1313

14-
!> The STACKIT PostgreSQL service will reach its end of support on June 30th 2024. Resources of this type will stop working after that. Use stackit_postgresflex_instance instead. Check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html on how to backup and restore an instance from PostgreSQL to PostgreSQL Flex, then import the resource to Terraform using an "import" block (https://developer.hashicorp.com/terraform/language/import)
14+
!> The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_instance instead. Check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html on how to backup and restore an instance from PostgreSQL to PostgreSQL Flex, then import the resource to Terraform using an "import" block (https://developer.hashicorp.com/terraform/language/import)
1515

1616
## Example Usage
1717

stackit/internal/services/postgresql/credential/datasource.go

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package postgresql
33
import (
44
"context"
55
"fmt"
6-
"net/http"
76
"strings"
87

98
"github.com/hashicorp/terraform-plugin-framework/datasource"
@@ -15,7 +14,6 @@ import (
1514
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
1615
"github.com/hashicorp/terraform-plugin-framework/types"
1716
"github.com/stackitcloud/stackit-sdk-go/core/config"
18-
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
1917
"github.com/stackitcloud/stackit-sdk-go/services/postgresql"
2018
)
2119

@@ -81,8 +79,8 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ
8179
"main": "PostgreSQL credential data source schema. Must have a `region` specified in the provider configuration.",
8280
"deprecation_message": strings.Join(
8381
[]string{
84-
"The STACKIT PostgreSQL service will reach its end of support on June 30th 2024.",
85-
"Data sources of this type will stop working after that.",
82+
"The STACKIT PostgreSQL service has reached its end of support on June 30th 2024.",
83+
"Resources of this type have stopped working since then.",
8684
"Use stackit_postgresflex_user instead.",
8785
"For more details, check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html",
8886
},
@@ -160,42 +158,6 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ
160158
}
161159

162160
// Read refreshes the Terraform state with the latest data.
163-
func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
164-
var model Model
165-
diags := req.Config.Get(ctx, &model)
166-
resp.Diagnostics.Append(diags...)
167-
if resp.Diagnostics.HasError() {
168-
return
169-
}
170-
projectId := model.ProjectId.ValueString()
171-
instanceId := model.InstanceId.ValueString()
172-
credentialId := model.CredentialId.ValueString()
173-
ctx = tflog.SetField(ctx, "project_id", projectId)
174-
ctx = tflog.SetField(ctx, "instance_id", instanceId)
175-
ctx = tflog.SetField(ctx, "credential_id", credentialId)
176-
177-
recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute()
178-
if err != nil {
179-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
180-
if ok && oapiErr.StatusCode == http.StatusNotFound {
181-
resp.State.RemoveResource(ctx)
182-
}
183-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err))
184-
return
185-
}
186-
187-
// Map response body to schema
188-
err = mapFields(recordSetResp, &model)
189-
if err != nil {
190-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Processing API payload: %v", err))
191-
return
192-
}
193-
194-
// Set refreshed state
195-
diags = resp.State.Set(ctx, model)
196-
resp.Diagnostics.Append(diags...)
197-
if resp.Diagnostics.HasError() {
198-
return
199-
}
200-
tflog.Info(ctx, "PostgreSQL credential read")
161+
func (r *credentialDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
162+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential data", "The STACKIT PostgreSQL service has reached its end of support on June 30th 2024. Resources of this type have stopped working since then. Use stackit_postgresflex_instance instead. Check https://docs.stackit.cloud/stackit/en/bring-your-data-to-stackit-postgresql-flex-138347648.html on how to backup and restore an instance from PostgreSQL to PostgreSQL Flex, then import the resource to Terraform using an \"import\" block (https://developer.hashicorp.com/terraform/language/import)")
201163
}

0 commit comments

Comments
 (0)