Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions docs/data-sources/postgresflex_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,48 @@ data "stackit_postgresflex_instance" "example" {

### Read-Only

- `acl` (List of String) The Access Control List (ACL) for the PostgresFlex instance.
- `backup_schedule` (String)
- `acl` (List of String, Deprecated) The Access Control List (ACL) for the PostgresFlex instance.
- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. Must be a valid cron expression using numeric minute and hour values, e.g: '0 2 * * *'.
- `connection_info` (Attributes) The connection info for the PostgresFlex instance. (see [below for nested schema](#nestedatt--connection_info))
- `encryption` (Attributes) (see [below for nested schema](#nestedatt--encryption))
- `flavor` (Attributes) (see [below for nested schema](#nestedatt--flavor))
- `flavor_id` (String)
- `id` (String) Terraform's internal data source. ID. It is structured as "`project_id`,`region`,`instance_id`".
- `name` (String) Instance name.
- `network` (Attributes) (see [below for nested schema](#nestedatt--network))
- `replicas` (Number)
- `retention_days` (Number)
- `storage` (Attributes) (see [below for nested schema](#nestedatt--storage))
- `version` (String)

<a id="nestedatt--connection_info"></a>
### Nested Schema for `connection_info`

Read-Only:

- `write` (Attributes) The DNS name and port in the instance overview. (see [below for nested schema](#nestedatt--connection_info--write))

<a id="nestedatt--connection_info--write"></a>
### Nested Schema for `connection_info.write`

Read-Only:

- `host` (String) The host of the instance.
- `port` (Number) The port of the instance.



<a id="nestedatt--encryption"></a>
### Nested Schema for `encryption`

Read-Only:

- `kek_key_id` (String)
- `kek_key_ring_id` (String)
- `kek_key_version` (String)
- `service_account` (String)


<a id="nestedatt--flavor"></a>
### Nested Schema for `flavor`

Expand All @@ -50,9 +83,21 @@ Read-Only:
- `cpu` (Number)
- `description` (String)
- `id` (String)
- `node_type` (String)
- `ram` (Number)


<a id="nestedatt--network"></a>
### Nested Schema for `network`

Read-Only:

- `access_scope` (String) The network access scope of the instance. This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected. Possible values are: `PUBLIC`, `SNA`.
- `acl` (List of String) List of IPV4 cidr.
- `instance_address` (String)
- `router_address` (String)


<a id="nestedatt--storage"></a>
### Nested Schema for `storage`

Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/postgresflex_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ data "stackit_postgresflex_user" "example" {

### Read-Only

- `host` (String)
- `host` (String, Deprecated)
- `id` (String) Terraform's internal data source. ID. It is structured as "`project_id`,`region`,`instance_id`,`user_id`".
- `port` (Number)
- `port` (Number, Deprecated)
- `roles` (Set of String)
- `username` (String)
89 changes: 69 additions & 20 deletions docs/resources/postgresflex_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ Postgres Flex instance resource schema. Must have a `region` specified in the pr

```terraform
resource "stackit_postgresflex_instance" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-instance"
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
backup_schedule = "00 00 * * *"
flavor = {
cpu = 2
ram = 4
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-instance"
network = {
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
}
replicas = 3
backup_schedule = "0 0 * * *"
flavor_id = "4.8-replica"
storage = {
class = "premium-perf2-stackit"
size = 5
}
version = 14
version = "14"
retention_days = 32
}
```

Expand All @@ -36,24 +35,55 @@ resource "stackit_postgresflex_instance" "example" {

### Required

- `acl` (List of String) The Access Control List (ACL) for the PostgresFlex instance.
- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. Must be a valid cron expression using numeric minute and hour values, e.g: '0 2 * * *'.
- `flavor` (Attributes) (see [below for nested schema](#nestedatt--flavor))
- `name` (String) Instance name.
- `project_id` (String) STACKIT project ID to which the instance is associated.
- `replicas` (Number) How many replicas the instance should have. Valid values are 1 for single mode or 3 for replication.
- `storage` (Attributes) (see [below for nested schema](#nestedatt--storage))
- `version` (String)

### Optional

- `acl` (List of String, Deprecated) The Access Control List (ACL) for the PostgresFlex instance.
- `encryption` (Attributes) (see [below for nested schema](#nestedatt--encryption))
- `flavor` (Attributes) (see [below for nested schema](#nestedatt--flavor))
- `flavor_id` (String) The flavor ID of the PostgreSQL Flex instance. Can only be set when `flavor` and `replicas` are not set. You can list available storage classes using the [STACKIT CLI](https://github.com/stackitcloud/stackit-cli):
```bash
stackit postgresflex options --flavors
```
- `network` (Attributes) The network configuration of the instance. Will be required after February 2027. Set a value to prevent breaking changes. (see [below for nested schema](#nestedatt--network))
- `region` (String) The resource region. If not defined, the provider region is used.
- `replicas` (Number) How many replicas the instance should have. Valid values are 1 for single mode or 3 for replication. Can only be set together with `flavor`
- `retention_days` (Number) How long backups are retained. The value can only be between 32 and 90 days. Will be required after February 2027. Set a value to prevent breaking changes.

### Read-Only

- `connection_info` (Attributes) The connection info for the PostgresFlex instance. (see [below for nested schema](#nestedatt--connection_info))
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`instance_id`".
- `instance_id` (String) ID of the PostgresFlex instance.

<a id="nestedatt--storage"></a>
### Nested Schema for `storage`

Required:

- `class` (String) The storage class. You can list available storage classes using the [STACKIT CLI](https://github.com/stackitcloud/stackit-cli):
```bash
stackit postgresflex options --storages --flavor-id FLAVOR_ID
```
- `size` (Number)


<a id="nestedatt--encryption"></a>
### Nested Schema for `encryption`

Required:

- `kek_key_id` (String) The ID of the Key within the STACKIT-KMS to use for the encryption.
- `kek_key_ring_id` (String) The ID of the keyring where the key is located within the STACKTI-KMS.
- `kek_key_version` (String) Version of the key within the STACKIT-KMS to use for the encryption.
- `service_account` (String) Service-Account linked to the Key within the STACKIT-KMS.


<a id="nestedatt--flavor"></a>
### Nested Schema for `flavor`

Expand All @@ -66,18 +96,37 @@ Read-Only:

- `description` (String)
- `id` (String)
- `node_type` (String)


<a id="nestedatt--storage"></a>
### Nested Schema for `storage`
<a id="nestedatt--network"></a>
### Nested Schema for `network`

Required:
Optional:

- `class` (String) The storage class. You can list available storage classes using the [STACKIT CLI](https://github.com/stackitcloud/stackit-cli):
```bash
stackit postgresflex options --storages --flavor-id FLAVOR_ID
```
- `size` (Number)
- `access_scope` (String) The network access scope of the instance. This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected. Possible values are: `PUBLIC`, `SNA`.
- `acl` (List of String) The Access Control List (ACL) for the PostgresFlex instance.

Read-Only:

- `instance_address` (String)
- `router_address` (String)


<a id="nestedatt--connection_info"></a>
### Nested Schema for `connection_info`

Read-Only:

- `write` (Attributes) The DNS name and port in the instance overview. (see [below for nested schema](#nestedatt--connection_info--write))

<a id="nestedatt--connection_info--write"></a>
### Nested Schema for `connection_info.write`

Read-Only:

- `host` (String) The host of the instance.
- `port` (Number) The port of the instance.

## Import

Expand Down
6 changes: 3 additions & 3 deletions docs/resources/postgresflex_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ resource "stackit_postgresflex_user" "example_rotate" {

### Read-Only

- `host` (String)
- `host` (String, Deprecated)
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`instance_id`,`user_id`".
- `password` (String, Sensitive)
- `port` (Number)
- `uri` (String, Sensitive)
- `port` (Number, Deprecated)
- `uri` (String, Sensitive, Deprecated)
- `user_id` (String) User ID.

## Import
Expand Down
19 changes: 9 additions & 10 deletions examples/resources/stackit_postgresflex_instance/resource.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
resource "stackit_postgresflex_instance" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-instance"
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
backup_schedule = "00 00 * * *"
flavor = {
cpu = 2
ram = 4
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-instance"
network = {
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
}
replicas = 3
backup_schedule = "0 0 * * *"
flavor_id = "4.8-replica"
storage = {
class = "premium-perf2-stackit"
size = 5
}
version = 14
}
version = "14"
retention_days = 32
}
Original file line number Diff line number Diff line change
Expand Up @@ -540,23 +540,23 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Int32{
int32planmodifier.UseStateForUnknownIf(int32planmodifier.Int32Changed(path.Root("metrics_retention_days")), "sets `UseStateForUnknown` only if `metrics_retention_days` has not changed"),
int32planmodifier.UseStateForUnknownIf(int32planmodifier.Int32Unchanged(path.Root("metrics_retention_days")), "sets `UseStateForUnknown` only if `metrics_retention_days` has not changed"),
},
},
"metrics_retention_days_5m_downsampling": schema.Int32Attribute{
Description: "Specifies for how many days the 5m downsampled metrics are kept. must be less than the value of the general retention. Default is set to `90`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Int32{
int32planmodifier.UseStateForUnknownIf(int32planmodifier.Int32Changed(path.Root("metrics_retention_days_5m_downsampling")), "sets `UseStateForUnknown` only if `metrics_retention_days_5m_downsampling` has not changed"),
int32planmodifier.UseStateForUnknownIf(int32planmodifier.Int32Unchanged(path.Root("metrics_retention_days_5m_downsampling")), "sets `UseStateForUnknown` only if `metrics_retention_days_5m_downsampling` has not changed"),
},
},
"metrics_retention_days_1h_downsampling": schema.Int32Attribute{
Description: "Specifies for how many days the 1h downsampled metrics are kept. must be less than the value of the 5m downsampling retention. Default is set to `90`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Int32{
int32planmodifier.UseStateForUnknownIf(int32planmodifier.Int32Changed(path.Root("metrics_retention_days_1h_downsampling")), "sets `UseStateForUnknown` only if `metrics_retention_days_1h_downsampling` has not changed"),
int32planmodifier.UseStateForUnknownIf(int32planmodifier.Int32Unchanged(path.Root("metrics_retention_days_1h_downsampling")), "sets `UseStateForUnknown` only if `metrics_retention_days_1h_downsampling` has not changed"),
},
},
"metrics_url": schema.StringAttribute{
Expand Down
17 changes: 12 additions & 5 deletions stackit/internal/services/postgresflex/database/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"strconv"

"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
postgresflexUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/utils"
Expand All @@ -17,7 +18,7 @@ import (
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"

"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3beta1api"
)

// Ensure the implementation satisfies the expected interfaces.
Expand Down Expand Up @@ -130,21 +131,27 @@ func (r *databaseDataSource) Read(ctx context.Context, req datasource.ReadReques

projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
databaseId := model.DatabaseId.ValueString()
databaseIdStr := model.DatabaseId.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "instance_id", instanceId)
ctx = tflog.SetField(ctx, "database_id", databaseId)
ctx = tflog.SetField(ctx, "database_id", databaseIdStr)
ctx = tflog.SetField(ctx, "region", region)

databaseResp, err := getDatabase(ctx, r.client, projectId, region, instanceId, databaseId)
databaseId, err := strconv.ParseInt(databaseIdStr, 10, 64)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading database", fmt.Sprintf("Parsing database ID: %v", err))
return
}

databaseResp, err := r.client.DefaultAPI.GetDatabase(ctx, projectId, region, instanceId, databaseId).Execute()
if err != nil {
utils.LogError(
ctx,
&resp.Diagnostics,
err,
"Reading database",
fmt.Sprintf("Database with ID %q or instance with ID %q does not exist in project %q.", databaseId, instanceId, projectId),
fmt.Sprintf("Database with ID %d or instance with ID %q does not exist in project %q.", databaseId, instanceId, projectId),
map[int]string{
http.StatusForbidden: fmt.Sprintf("Project with ID %q not found or forbidden access", projectId),
},
Expand Down
Loading
Loading