parent
349ed981db
commit
a58940981e
12 changed files with 1 additions and 1049 deletions
|
|
@ -1,45 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackit_postgresql_credential Data Source - stackit"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
PostgreSQL credential data source schema. Must have a region specified in the provider configuration.
|
|
||||||
!> 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
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackit_postgresql_credential (Data Source)
|
|
||||||
|
|
||||||
PostgreSQL credential data source schema. Must have a `region` specified in the provider configuration.
|
|
||||||
|
|
||||||
!> 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
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackit_postgresql_credential" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `credential_id` (String) The credential's ID.
|
|
||||||
- `instance_id` (String) ID of the PostgreSQL instance.
|
|
||||||
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `host` (String)
|
|
||||||
- `hosts` (List of String)
|
|
||||||
- `http_api_uri` (String)
|
|
||||||
- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credential_id`".
|
|
||||||
- `name` (String)
|
|
||||||
- `password` (String, Sensitive)
|
|
||||||
- `port` (Number)
|
|
||||||
- `uri` (String, Sensitive)
|
|
||||||
- `username` (String)
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackit_postgresql_instance Data Source - stackit"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
PostgreSQL instance data source schema. Must have a region specified in the provider configuration.
|
|
||||||
!> 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
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackit_postgresql_instance (Data Source)
|
|
||||||
|
|
||||||
PostgreSQL instance data source schema. Must have a `region` specified in the provider configuration.
|
|
||||||
|
|
||||||
!> 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
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackit_postgresql_instance" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `instance_id` (String) ID of the PostgreSQL instance.
|
|
||||||
- `project_id` (String) STACKIT Project ID to which the instance is associated.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `cf_guid` (String)
|
|
||||||
- `cf_organization_guid` (String)
|
|
||||||
- `cf_space_guid` (String)
|
|
||||||
- `dashboard_url` (String)
|
|
||||||
- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`".
|
|
||||||
- `image_url` (String)
|
|
||||||
- `name` (String) Instance name.
|
|
||||||
- `parameters` (Attributes) (see [below for nested schema](#nestedatt--parameters))
|
|
||||||
- `plan_id` (String) The selected plan ID.
|
|
||||||
- `plan_name` (String) The selected plan name.
|
|
||||||
- `version` (String) The service version.
|
|
||||||
|
|
||||||
<a id="nestedatt--parameters"></a>
|
|
||||||
### Nested Schema for `parameters`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `enable_monitoring` (Boolean)
|
|
||||||
- `metrics_frequency` (Number)
|
|
||||||
- `metrics_prefix` (String)
|
|
||||||
- `monitoring_instance_id` (String)
|
|
||||||
- `plugins` (List of String)
|
|
||||||
- `sgw_acl` (String)
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackit_postgresql_credential Resource - stackit"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
PostgreSQL credential resource schema. Must have a region specified in the provider configuration.
|
|
||||||
!> 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
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackit_postgresql_credential (Resource)
|
|
||||||
|
|
||||||
PostgreSQL credential resource schema. Must have a `region` specified in the provider configuration.
|
|
||||||
|
|
||||||
!> 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
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
resource "stackit_postgresql_credential" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `instance_id` (String) ID of the PostgreSQL instance.
|
|
||||||
- `project_id` (String) STACKIT Project ID to which the instance is associated.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `credential_id` (String) The credential's ID.
|
|
||||||
- `host` (String)
|
|
||||||
- `hosts` (List of String)
|
|
||||||
- `http_api_uri` (String)
|
|
||||||
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credential_id`".
|
|
||||||
- `name` (String)
|
|
||||||
- `password` (String, Sensitive)
|
|
||||||
- `port` (Number)
|
|
||||||
- `uri` (String, Sensitive)
|
|
||||||
- `username` (String)
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackit_postgresql_instance Resource - stackit"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
PostgreSQL instance resource schema. Must have a region specified in the provider configuration.
|
|
||||||
!> 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)
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackit_postgresql_instance (Resource)
|
|
||||||
|
|
||||||
PostgreSQL instance resource schema. Must have a `region` specified in the provider configuration.
|
|
||||||
|
|
||||||
!> 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)
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
resource "stackit_postgresql_instance" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
name = "example-instance"
|
|
||||||
version = "10"
|
|
||||||
plan_name = "example-plan-name"
|
|
||||||
parameters = {
|
|
||||||
sgw_acl = "x.x.x.x/x,y.y.y.y/y"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `name` (String) Instance name.
|
|
||||||
- `plan_name` (String) The selected plan name.
|
|
||||||
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
|
||||||
- `version` (String) The service version.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `parameters` (Attributes) (see [below for nested schema](#nestedatt--parameters))
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `cf_guid` (String)
|
|
||||||
- `cf_organization_guid` (String)
|
|
||||||
- `cf_space_guid` (String)
|
|
||||||
- `dashboard_url` (String)
|
|
||||||
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`instance_id`".
|
|
||||||
- `image_url` (String)
|
|
||||||
- `instance_id` (String) ID of the PostgreSQL instance.
|
|
||||||
- `plan_id` (String) The selected plan ID.
|
|
||||||
|
|
||||||
<a id="nestedatt--parameters"></a>
|
|
||||||
### Nested Schema for `parameters`
|
|
||||||
|
|
||||||
Optional:
|
|
||||||
|
|
||||||
- `enable_monitoring` (Boolean)
|
|
||||||
- `metrics_frequency` (Number)
|
|
||||||
- `metrics_prefix` (String)
|
|
||||||
- `monitoring_instance_id` (String)
|
|
||||||
- `plugins` (List of String)
|
|
||||||
- `sgw_acl` (String)
|
|
||||||
1
go.mod
1
go.mod
|
|
@ -23,7 +23,6 @@ require (
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/observability v0.1.0
|
github.com/stackitcloud/stackit-sdk-go/services/observability v0.1.0
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.18.0
|
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.18.0
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.15.0
|
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.15.0
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/postgresql v0.12.1
|
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.19.0
|
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.19.0
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/redis v0.19.0
|
github.com/stackitcloud/stackit-sdk-go/services/redis v0.19.0
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.9.0
|
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.9.0
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -173,8 +173,6 @@ github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.18.0 h1:pzHA3sxaAs
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.18.0/go.mod h1:ZecMIf9oYj2DGZqWh93l97WdVaRdLl+tW5Fq3YKGwBM=
|
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.18.0/go.mod h1:ZecMIf9oYj2DGZqWh93l97WdVaRdLl+tW5Fq3YKGwBM=
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.15.0 h1:05wQYhO37Z4y8xAD+4OTYz6rYu6eJEmwMfCG4tjETEc=
|
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.15.0 h1:05wQYhO37Z4y8xAD+4OTYz6rYu6eJEmwMfCG4tjETEc=
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.15.0/go.mod h1:SdrqGLCkilL6wl1+jcxmLtks2IocgIg+bsyeyYUIzR4=
|
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.15.0/go.mod h1:SdrqGLCkilL6wl1+jcxmLtks2IocgIg+bsyeyYUIzR4=
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/postgresql v0.12.1 h1:u2jNFPPLM2TlpM1qUu1UuG9XKx/EYPjwg2nJqAK1HUY=
|
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/postgresql v0.12.1/go.mod h1:rTbdB/rl+e9o9sJNrT3yMIaSNVBGqR5G2Vh4opKrEwo=
|
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.19.0 h1:qZ62GSQKw73JrS7a9WeGILMki26KNyqrMOmD8r41u/A=
|
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.19.0 h1:qZ62GSQKw73JrS7a9WeGILMki26KNyqrMOmD8r41u/A=
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.19.0/go.mod h1:eSgnPBknTJh7t+jVKN+xzeAh+Cg1USOlH3QCyfvG20g=
|
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.19.0/go.mod h1:eSgnPBknTJh7t+jVKN+xzeAh+Cg1USOlH3QCyfvG20g=
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/redis v0.19.0 h1:/s9GUIpwZTN6I7J4nKmBBmxc6lPJYpCHHxYsC+gDsZs=
|
github.com/stackitcloud/stackit-sdk-go/services/redis v0.19.0 h1:/s9GUIpwZTN6I7J4nKmBBmxc6lPJYpCHHxYsC+gDsZs=
|
||||||
|
|
|
||||||
|
|
@ -496,7 +496,7 @@ func (r *instanceResource) ImportState(ctx context.Context, req resource.ImportS
|
||||||
|
|
||||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
|
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
|
||||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...)
|
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...)
|
||||||
tflog.Info(ctx, "Postgresql instance state imported")
|
tflog.Info(ctx, "Postgresql Flex instance state imported")
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model *Model, flavor *flavorModel, storage *storageModel) error {
|
func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model *Model, flavor *flavorModel, storage *storageModel) error {
|
||||||
|
|
|
||||||
|
|
@ -1,163 +0,0 @@
|
||||||
package postgresql
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/services/postgresql"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ensure the implementation satisfies the expected interfaces.
|
|
||||||
var (
|
|
||||||
_ datasource.DataSource = &credentialDataSource{}
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewCredentialDataSource is a helper function to simplify the provider implementation.
|
|
||||||
func NewCredentialDataSource() datasource.DataSource {
|
|
||||||
return &credentialDataSource{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// credentialDataSource is the data source implementation.
|
|
||||||
type credentialDataSource struct {
|
|
||||||
client *postgresql.APIClient
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metadata returns the data source type name.
|
|
||||||
func (r *credentialDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
|
||||||
resp.TypeName = req.ProviderTypeName + "_postgresql_credential"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure adds the provider configured client to the data source.
|
|
||||||
func (r *credentialDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
|
||||||
// Prevent panic if the provider has not been configured.
|
|
||||||
if req.ProviderData == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
providerData, ok := req.ProviderData.(core.ProviderData)
|
|
||||||
if !ok {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Expected configure type stackit.ProviderData, got %T", req.ProviderData))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var apiClient *postgresql.APIClient
|
|
||||||
var err error
|
|
||||||
if providerData.PostgreSQLCustomEndpoint != "" {
|
|
||||||
apiClient, err = postgresql.NewAPIClient(
|
|
||||||
config.WithCustomAuth(providerData.RoundTripper),
|
|
||||||
config.WithEndpoint(providerData.PostgreSQLCustomEndpoint),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
apiClient, err = postgresql.NewAPIClient(
|
|
||||||
config.WithCustomAuth(providerData.RoundTripper),
|
|
||||||
config.WithRegion(providerData.Region),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Configuring client: %v. This is an error related to the provider configuration, not to the data source configuration", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
r.client = apiClient
|
|
||||||
tflog.Info(ctx, "PostgreSQL credential client configured")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Schema defines the schema for the data source.
|
|
||||||
func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
|
||||||
descriptions := map[string]string{
|
|
||||||
"main": "PostgreSQL credential data source schema. Must have a `region` specified in the provider configuration.",
|
|
||||||
"deprecation_message": strings.Join(
|
|
||||||
[]string{
|
|
||||||
"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",
|
|
||||||
},
|
|
||||||
" ",
|
|
||||||
),
|
|
||||||
"id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".",
|
|
||||||
"credential_id": "The credential's ID.",
|
|
||||||
"instance_id": "ID of the PostgreSQL instance.",
|
|
||||||
"project_id": "STACKIT project ID to which the instance is associated.",
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Schema = schema.Schema{
|
|
||||||
Description: descriptions["main"],
|
|
||||||
// Callout block: https://developer.hashicorp.com/terraform/registry/providers/docs#callouts
|
|
||||||
MarkdownDescription: fmt.Sprintf("%s\n\n!> %s", descriptions["main"], descriptions["deprecation_message"]),
|
|
||||||
DeprecationMessage: descriptions["deprecation_message"],
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"id": schema.StringAttribute{
|
|
||||||
Description: descriptions["id"],
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"credential_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["credential_id"],
|
|
||||||
Required: true,
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"instance_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["instance_id"],
|
|
||||||
Required: true,
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"project_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["project_id"],
|
|
||||||
Required: true,
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"host": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"hosts": schema.ListAttribute{
|
|
||||||
ElementType: types.StringType,
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"http_api_uri": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"name": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"password": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
Sensitive: true,
|
|
||||||
},
|
|
||||||
"port": schema.Int64Attribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"uri": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
Sensitive: true,
|
|
||||||
},
|
|
||||||
"username": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read refreshes the Terraform state with the latest data.
|
|
||||||
func (r *credentialDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
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)")
|
|
||||||
}
|
|
||||||
|
|
@ -1,217 +0,0 @@
|
||||||
package postgresql
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/services/postgresql"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ensure the implementation satisfies the expected interfaces.
|
|
||||||
var (
|
|
||||||
_ resource.Resource = &credentialResource{}
|
|
||||||
_ resource.ResourceWithConfigure = &credentialResource{}
|
|
||||||
_ resource.ResourceWithImportState = &credentialResource{}
|
|
||||||
)
|
|
||||||
|
|
||||||
type Model struct {
|
|
||||||
Id types.String `tfsdk:"id"` // needed by TF
|
|
||||||
CredentialId types.String `tfsdk:"credential_id"`
|
|
||||||
InstanceId types.String `tfsdk:"instance_id"`
|
|
||||||
ProjectId types.String `tfsdk:"project_id"`
|
|
||||||
Host types.String `tfsdk:"host"`
|
|
||||||
Hosts types.List `tfsdk:"hosts"`
|
|
||||||
HttpAPIURI types.String `tfsdk:"http_api_uri"`
|
|
||||||
Name types.String `tfsdk:"name"`
|
|
||||||
Password types.String `tfsdk:"password"`
|
|
||||||
Port types.Int64 `tfsdk:"port"`
|
|
||||||
Uri types.String `tfsdk:"uri"`
|
|
||||||
Username types.String `tfsdk:"username"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewCredentialResource is a helper function to simplify the provider implementation.
|
|
||||||
func NewCredentialResource() resource.Resource {
|
|
||||||
return &credentialResource{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// credentialResource is the resource implementation.
|
|
||||||
type credentialResource struct {
|
|
||||||
client *postgresql.APIClient
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metadata returns the resource type name.
|
|
||||||
func (r *credentialResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
|
||||||
resp.TypeName = req.ProviderTypeName + "_postgresql_credential"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure adds the provider configured client to the resource.
|
|
||||||
func (r *credentialResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
|
||||||
// Prevent panic if the provider has not been configured.
|
|
||||||
if req.ProviderData == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
providerData, ok := req.ProviderData.(core.ProviderData)
|
|
||||||
if !ok {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Expected configure type stackit.ProviderData, got %T", req.ProviderData))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var apiClient *postgresql.APIClient
|
|
||||||
var err error
|
|
||||||
if providerData.PostgreSQLCustomEndpoint != "" {
|
|
||||||
apiClient, err = postgresql.NewAPIClient(
|
|
||||||
config.WithCustomAuth(providerData.RoundTripper),
|
|
||||||
config.WithEndpoint(providerData.PostgreSQLCustomEndpoint),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
apiClient, err = postgresql.NewAPIClient(
|
|
||||||
config.WithCustomAuth(providerData.RoundTripper),
|
|
||||||
config.WithRegion(providerData.Region),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
r.client = apiClient
|
|
||||||
tflog.Info(ctx, "PostgreSQL credential client configured")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Schema defines the schema for the resource.
|
|
||||||
func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
|
||||||
descriptions := map[string]string{
|
|
||||||
"main": "PostgreSQL credential resource schema. Must have a `region` specified in the provider configuration.",
|
|
||||||
"deprecation_message": strings.Join(
|
|
||||||
[]string{
|
|
||||||
"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",
|
|
||||||
},
|
|
||||||
" ",
|
|
||||||
),
|
|
||||||
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".",
|
|
||||||
"credential_id": "The credential's ID.",
|
|
||||||
"instance_id": "ID of the PostgreSQL instance.",
|
|
||||||
"project_id": "STACKIT Project ID to which the instance is associated.",
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Schema = schema.Schema{
|
|
||||||
Description: descriptions["main"],
|
|
||||||
// Callout block: https://developer.hashicorp.com/terraform/registry/providers/docs#callouts
|
|
||||||
MarkdownDescription: fmt.Sprintf("%s\n\n!> %s", descriptions["main"], descriptions["deprecation_message"]),
|
|
||||||
DeprecationMessage: descriptions["deprecation_message"],
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"id": schema.StringAttribute{
|
|
||||||
Description: descriptions["id"],
|
|
||||||
Computed: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"credential_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["credential_id"],
|
|
||||||
Computed: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"instance_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["instance_id"],
|
|
||||||
Required: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.RequiresReplace(),
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"project_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["project_id"],
|
|
||||||
Required: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.RequiresReplace(),
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"host": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"hosts": schema.ListAttribute{
|
|
||||||
ElementType: types.StringType,
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"http_api_uri": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"name": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"password": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
Sensitive: true,
|
|
||||||
},
|
|
||||||
"port": schema.Int64Attribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"uri": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
Sensitive: true,
|
|
||||||
},
|
|
||||||
"username": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create creates the resource and sets the initial Terraform state.
|
|
||||||
func (r *credentialResource) Create(ctx context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "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)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read refreshes the Terraform state with the latest data.
|
|
||||||
func (r *credentialResource) Read(ctx context.Context, _ resource.ReadRequest, resp *resource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", "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)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update updates the resource and sets the updated Terraform state on success.
|
|
||||||
func (r *credentialResource) Update(ctx context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating credential", "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)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete deletes the resource and removes the Terraform state on success.
|
|
||||||
func (r *credentialResource) Delete(ctx context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", "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)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ImportState imports a resource into the Terraform state on success.
|
|
||||||
// The expected format of the resource import identifier is: project_id,instance_id
|
|
||||||
func (r *credentialResource) ImportState(ctx context.Context, _ resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error importing credential", "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)")
|
|
||||||
}
|
|
||||||
|
|
@ -1,186 +0,0 @@
|
||||||
package postgresql
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
|
||||||
"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/validate"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/services/postgresql"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ensure the implementation satisfies the expected interfaces.
|
|
||||||
var (
|
|
||||||
_ datasource.DataSource = &instanceDataSource{}
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewInstanceDataSource is a helper function to simplify the provider implementation.
|
|
||||||
func NewInstanceDataSource() datasource.DataSource {
|
|
||||||
return &instanceDataSource{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// instanceDataSource is the data source implementation.
|
|
||||||
type instanceDataSource struct {
|
|
||||||
client *postgresql.APIClient
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metadata returns the data source type name.
|
|
||||||
func (r *instanceDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
|
||||||
resp.TypeName = req.ProviderTypeName + "_postgresql_instance"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure adds the provider configured client to the data source.
|
|
||||||
func (r *instanceDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
|
||||||
// Prevent panic if the provider has not been configured.
|
|
||||||
if req.ProviderData == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
providerData, ok := req.ProviderData.(core.ProviderData)
|
|
||||||
if !ok {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Expected configure type stackit.ProviderData, got %T", req.ProviderData))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var apiClient *postgresql.APIClient
|
|
||||||
var err error
|
|
||||||
if providerData.PostgreSQLCustomEndpoint != "" {
|
|
||||||
apiClient, err = postgresql.NewAPIClient(
|
|
||||||
config.WithCustomAuth(providerData.RoundTripper),
|
|
||||||
config.WithEndpoint(providerData.PostgreSQLCustomEndpoint),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
apiClient, err = postgresql.NewAPIClient(
|
|
||||||
config.WithCustomAuth(providerData.RoundTripper),
|
|
||||||
config.WithRegion(providerData.Region),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Configuring client: %v. This is an error related to the provider configuration, not to the data source configuration", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
r.client = apiClient
|
|
||||||
tflog.Info(ctx, "PostgreSQL instance client configured")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Schema defines the schema for the data source.
|
|
||||||
func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
|
||||||
descriptions := map[string]string{
|
|
||||||
"main": "PostgreSQL instance data source schema. Must have a `region` specified in the provider configuration.",
|
|
||||||
"deprecation_message": strings.Join(
|
|
||||||
[]string{
|
|
||||||
"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",
|
|
||||||
},
|
|
||||||
" ",
|
|
||||||
),
|
|
||||||
"id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`\".",
|
|
||||||
"instance_id": "ID of the PostgreSQL instance.",
|
|
||||||
"project_id": "STACKIT Project ID to which the instance is associated.",
|
|
||||||
"name": "Instance name.",
|
|
||||||
"version": "The service version.",
|
|
||||||
"plan_name": "The selected plan name.",
|
|
||||||
"plan_id": "The selected plan ID.",
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Schema = schema.Schema{
|
|
||||||
Description: descriptions["main"],
|
|
||||||
// Callout block: https://developer.hashicorp.com/terraform/registry/providers/docs#callouts
|
|
||||||
MarkdownDescription: fmt.Sprintf("%s\n\n!> %s", descriptions["main"], descriptions["deprecation_message"]),
|
|
||||||
DeprecationMessage: descriptions["deprecation_message"],
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"id": schema.StringAttribute{
|
|
||||||
Description: descriptions["id"],
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"instance_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["instance_id"],
|
|
||||||
Required: true,
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"project_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["project_id"],
|
|
||||||
Required: true,
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"name": schema.StringAttribute{
|
|
||||||
Description: descriptions["name"],
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"version": schema.StringAttribute{
|
|
||||||
Description: descriptions["version"],
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"plan_name": schema.StringAttribute{
|
|
||||||
Description: descriptions["plan_name"],
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"plan_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["plan_id"],
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"parameters": schema.SingleNestedAttribute{
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"enable_monitoring": schema.BoolAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"metrics_frequency": schema.Int64Attribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"metrics_prefix": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"monitoring_instance_id": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"plugins": schema.ListAttribute{
|
|
||||||
ElementType: types.StringType,
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"sgw_acl": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"cf_guid": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"cf_space_guid": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"dashboard_url": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"image_url": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"cf_organization_guid": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read refreshes the Terraform state with the latest data.
|
|
||||||
func (r *instanceDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance 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)")
|
|
||||||
}
|
|
||||||
|
|
@ -1,262 +0,0 @@
|
||||||
package postgresql
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/services/postgresql"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Ensure the implementation satisfies the expected interfaces.
|
|
||||||
var (
|
|
||||||
_ resource.Resource = &instanceResource{}
|
|
||||||
_ resource.ResourceWithConfigure = &instanceResource{}
|
|
||||||
_ resource.ResourceWithImportState = &instanceResource{}
|
|
||||||
)
|
|
||||||
|
|
||||||
type Model struct {
|
|
||||||
Id types.String `tfsdk:"id"` // needed by TF
|
|
||||||
InstanceId types.String `tfsdk:"instance_id"`
|
|
||||||
ProjectId types.String `tfsdk:"project_id"`
|
|
||||||
CfGuid types.String `tfsdk:"cf_guid"`
|
|
||||||
CfSpaceGuid types.String `tfsdk:"cf_space_guid"`
|
|
||||||
DashboardUrl types.String `tfsdk:"dashboard_url"`
|
|
||||||
ImageUrl types.String `tfsdk:"image_url"`
|
|
||||||
Name types.String `tfsdk:"name"`
|
|
||||||
CfOrganizationGuid types.String `tfsdk:"cf_organization_guid"`
|
|
||||||
Parameters types.Object `tfsdk:"parameters"`
|
|
||||||
Version types.String `tfsdk:"version"`
|
|
||||||
PlanName types.String `tfsdk:"plan_name"`
|
|
||||||
PlanId types.String `tfsdk:"plan_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewInstanceResource is a helper function to simplify the provider implementation.
|
|
||||||
func NewInstanceResource() resource.Resource {
|
|
||||||
return &instanceResource{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// instanceResource is the resource implementation.
|
|
||||||
type instanceResource struct {
|
|
||||||
client *postgresql.APIClient
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metadata returns the resource type name.
|
|
||||||
func (r *instanceResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
|
||||||
resp.TypeName = req.ProviderTypeName + "_postgresql_instance"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure adds the provider configured client to the resource.
|
|
||||||
func (r *instanceResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
|
||||||
// Prevent panic if the provider has not been configured.
|
|
||||||
if req.ProviderData == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
providerData, ok := req.ProviderData.(core.ProviderData)
|
|
||||||
if !ok {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Expected configure type stackit.ProviderData, got %T", req.ProviderData))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var apiClient *postgresql.APIClient
|
|
||||||
var err error
|
|
||||||
if providerData.PostgreSQLCustomEndpoint != "" {
|
|
||||||
apiClient, err = postgresql.NewAPIClient(
|
|
||||||
config.WithCustomAuth(providerData.RoundTripper),
|
|
||||||
config.WithEndpoint(providerData.PostgreSQLCustomEndpoint),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
apiClient, err = postgresql.NewAPIClient(
|
|
||||||
config.WithCustomAuth(providerData.RoundTripper),
|
|
||||||
config.WithRegion(providerData.Region),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
r.client = apiClient
|
|
||||||
tflog.Info(ctx, "PostgreSQL instance client configured")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Schema defines the schema for the resource.
|
|
||||||
func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
|
||||||
descriptions := map[string]string{
|
|
||||||
"main": "PostgreSQL instance resource schema. Must have a `region` specified in the provider configuration.",
|
|
||||||
"deprecation_message": strings.Join(
|
|
||||||
[]string{
|
|
||||||
"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)",
|
|
||||||
},
|
|
||||||
" ",
|
|
||||||
),
|
|
||||||
"id": "Terraform's internal resource ID. It is structured as \"`project_id`,`instance_id`\".",
|
|
||||||
"instance_id": "ID of the PostgreSQL instance.",
|
|
||||||
"project_id": "STACKIT project ID to which the instance is associated.",
|
|
||||||
"name": "Instance name.",
|
|
||||||
"version": "The service version.",
|
|
||||||
"plan_name": "The selected plan name.",
|
|
||||||
"plan_id": "The selected plan ID.",
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Schema = schema.Schema{
|
|
||||||
Description: descriptions["main"],
|
|
||||||
// Callout block: https://developer.hashicorp.com/terraform/registry/providers/docs#callouts
|
|
||||||
MarkdownDescription: fmt.Sprintf("%s\n\n!> %s", descriptions["main"], descriptions["deprecation_message"]),
|
|
||||||
DeprecationMessage: descriptions["deprecation_message"],
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"id": schema.StringAttribute{
|
|
||||||
Description: descriptions["id"],
|
|
||||||
Computed: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"instance_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["instance_id"],
|
|
||||||
Computed: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"project_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["project_id"],
|
|
||||||
Required: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.RequiresReplace(),
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
Validators: []validator.String{
|
|
||||||
validate.UUID(),
|
|
||||||
validate.NoSeparator(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"name": schema.StringAttribute{
|
|
||||||
Description: descriptions["name"],
|
|
||||||
Required: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.RequiresReplace(),
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
Validators: []validator.String{
|
|
||||||
stringvalidator.LengthAtLeast(1),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"version": schema.StringAttribute{
|
|
||||||
Description: descriptions["version"],
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
"plan_name": schema.StringAttribute{
|
|
||||||
Description: descriptions["plan_name"],
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
"plan_id": schema.StringAttribute{
|
|
||||||
Description: descriptions["plan_id"],
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"parameters": schema.SingleNestedAttribute{
|
|
||||||
Attributes: map[string]schema.Attribute{
|
|
||||||
"enable_monitoring": schema.BoolAttribute{
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"metrics_frequency": schema.Int64Attribute{
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"metrics_prefix": schema.StringAttribute{
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"monitoring_instance_id": schema.StringAttribute{
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"plugins": schema.ListAttribute{
|
|
||||||
ElementType: types.StringType,
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"sgw_acl": schema.StringAttribute{
|
|
||||||
Optional: true,
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Optional: true,
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
"cf_guid": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"cf_space_guid": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"dashboard_url": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"image_url": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"cf_organization_guid": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
PlanModifiers: []planmodifier.String{
|
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create creates the resource and sets the initial Terraform state.
|
|
||||||
func (r *instanceResource) Create(ctx context.Context, _ resource.CreateRequest, resp *resource.CreateResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", "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)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read refreshes the Terraform state with the latest data.
|
|
||||||
func (r *instanceResource) Read(ctx context.Context, _ resource.ReadRequest, resp *resource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", "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)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update updates the resource and sets the updated Terraform state on success.
|
|
||||||
func (r *instanceResource) Update(ctx context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", "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)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete deletes the resource and removes the Terraform state on success.
|
|
||||||
func (r *instanceResource) Delete(ctx context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { // nolint:gocritic // function signature required by Terraform
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", "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)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ImportState imports a resource into the Terraform state on success.
|
|
||||||
// The expected format of the resource import identifier is: project_id,instance_id
|
|
||||||
func (r *instanceResource) ImportState(ctx context.Context, _ resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error importing instance", "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)")
|
|
||||||
}
|
|
||||||
|
|
@ -37,8 +37,6 @@ import (
|
||||||
postgresFlexDatabase "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/database"
|
postgresFlexDatabase "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/database"
|
||||||
postgresFlexInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/instance"
|
postgresFlexInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/instance"
|
||||||
postgresFlexUser "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/user"
|
postgresFlexUser "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/user"
|
||||||
postgresCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresql/credential"
|
|
||||||
postgresInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresql/instance"
|
|
||||||
rabbitMQCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/rabbitmq/credential"
|
rabbitMQCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/rabbitmq/credential"
|
||||||
rabbitMQInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/rabbitmq/instance"
|
rabbitMQInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/rabbitmq/instance"
|
||||||
redisCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/redis/credential"
|
redisCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/redis/credential"
|
||||||
|
|
@ -428,8 +426,6 @@ func (p *Provider) DataSources(_ context.Context) []func() datasource.DataSource
|
||||||
postgresFlexDatabase.NewDatabaseDataSource,
|
postgresFlexDatabase.NewDatabaseDataSource,
|
||||||
postgresFlexInstance.NewInstanceDataSource,
|
postgresFlexInstance.NewInstanceDataSource,
|
||||||
postgresFlexUser.NewUserDataSource,
|
postgresFlexUser.NewUserDataSource,
|
||||||
postgresInstance.NewInstanceDataSource,
|
|
||||||
postgresCredential.NewCredentialDataSource,
|
|
||||||
rabbitMQInstance.NewInstanceDataSource,
|
rabbitMQInstance.NewInstanceDataSource,
|
||||||
rabbitMQCredential.NewCredentialDataSource,
|
rabbitMQCredential.NewCredentialDataSource,
|
||||||
redisInstance.NewInstanceDataSource,
|
redisInstance.NewInstanceDataSource,
|
||||||
|
|
@ -477,8 +473,6 @@ func (p *Provider) Resources(_ context.Context) []func() resource.Resource {
|
||||||
postgresFlexDatabase.NewDatabaseResource,
|
postgresFlexDatabase.NewDatabaseResource,
|
||||||
postgresFlexInstance.NewInstanceResource,
|
postgresFlexInstance.NewInstanceResource,
|
||||||
postgresFlexUser.NewUserResource,
|
postgresFlexUser.NewUserResource,
|
||||||
postgresInstance.NewInstanceResource,
|
|
||||||
postgresCredential.NewCredentialResource,
|
|
||||||
rabbitMQInstance.NewInstanceResource,
|
rabbitMQInstance.NewInstanceResource,
|
||||||
rabbitMQCredential.NewCredentialResource,
|
rabbitMQCredential.NewCredentialResource,
|
||||||
redisInstance.NewInstanceResource,
|
redisInstance.NewInstanceResource,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue