Skip to content
Merged
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
16 changes: 16 additions & 0 deletions docs/data-sources/sqlserverflex_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,36 @@ data "stackit_sqlserverflex_instance" "example" {

### Optional

- `network` (Attributes) The network configuration of the instance. (see [below for nested schema](#nestedatt--network))
- `region` (String) The resource region. If not defined, the provider region is used.

### Read-Only

- `acl` (List of String) The Access Control List (ACL) for the SQLServer Flex instance.
- `backup_schedule` (String) The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *").
- `edition` (String) Edition of the MSSQL server instance.
- `flavor` (Attributes) (see [below for nested schema](#nestedatt--flavor))
- `flavor_id` (String) The flavor ID of the SQLServer Flex instance.
- `id` (String) Terraform's internal data source. ID. It is structured as "`project_id`,`region`,`instance_id`".
- `name` (String) Instance name.
- `options` (Attributes) Custom parameters for the SQLServer Flex instance. (see [below for nested schema](#nestedatt--options))
- `replicas` (Number)
- `retention_days` (Number) The days (30 to 90) for how long the backup files should be stored before cleaned up.
- `storage` (Attributes) (see [below for nested schema](#nestedatt--storage))
- `version` (String)

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

Optional:

- `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.

Read-Only:

- `acl` (List of String) List of IPV4 cidr.


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

Expand Down
38 changes: 24 additions & 14 deletions docs/resources/sqlserverflex_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ resource "stackit_sqlserverflex_instance" "example" {
name = "example-instance"
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
backup_schedule = "00 00 * * *"
flavor = {
cpu = 4
ram = 16
}
flavor_id = "4.16-Single"
storage = {
class = "premium-perf2-stackit"
size = 5
Expand All @@ -35,21 +32,25 @@ resource "stackit_sqlserverflex_instance" "example" {

### Required

- `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.

### Optional

- `acl` (List of String) The Access Control List (ACL) for the SQLServer Flex instance.
- `backup_schedule` (String) The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *")
- `options` (Attributes) (see [below for nested schema](#nestedatt--options))
- `acl` (List of String, Deprecated) The Access Control List (ACL) for the SQLServer Flex instance.
- `backup_schedule` (String) The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *") Will be required in the future. Set a value to prevent breaking changes.
- `flavor` (Attributes) (see [below for nested schema](#nestedatt--flavor))
- `flavor_id` (String) The flavor ID of the SQLServer Flex instance.
- `network` (Attributes) The network configuration of the instance. Will be required in the future. Set a value to prevent breaking changes. (see [below for nested schema](#nestedatt--network))
- `options` (Attributes, Deprecated) (see [below for nested schema](#nestedatt--options))
- `region` (String) The resource region. If not defined, the provider region is used.
- `storage` (Attributes) (see [below for nested schema](#nestedatt--storage))
- `version` (String)
- `retention_days` (Number) The days (30 to 90) for how long the backup files should be stored before cleaned up. Will be required in the future. Set a value to prevent breaking changes.
- `storage` (Attributes) The object containing information about the storage size and class. Will be required in the future. Set a value to prevent breaking changes. (see [below for nested schema](#nestedatt--storage))
- `version` (String) The sqlserver version used for the instance. Possible values are: `2022`. Will be required in the future. Set a value to prevent breaking changes.

### Read-Only

- `edition` (String) Edition of the MSSQL server instance.
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`instance_id`".
- `instance_id` (String) ID of the SQLServer Flex instance.
- `replicas` (Number)
Expand All @@ -68,16 +69,25 @@ Read-Only:
- `id` (String)


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

Optional:

- `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.


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

Optional:

- `retention_days` (Number)
- `retention_days` (Number, Deprecated)

Read-Only:

- `edition` (String)
- `edition` (String, Deprecated)


<a id="nestedatt--storage"></a>
Expand All @@ -88,8 +98,8 @@ Optional:
- `class` (String) The storage class. You can list available storage classes using the [STACKIT CLI](https://github.com/stackitcloud/stackit-cli):
```bash
stackit beta sqlserverflex options --storages --flavor-id FLAVOR_ID
```
- `size` (Number)
``` Will be required in the future. Set a value to prevent breaking changes.
- `size` (Number) The storage size in Gigabytes. Will be required in the future. Set a value to prevent breaking changes.

## Import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ resource "stackit_sqlserverflex_instance" "example" {
name = "example-instance"
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
backup_schedule = "00 00 * * *"
flavor = {
cpu = 4
ram = 16
}
flavor_id = "4.16-Single"
storage = {
class = "premium-perf2-stackit"
size = 5
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.7.0
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.11.0
github.com/stackitcloud/stackit-sdk-go/services/ske v1.18.0
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.13.0
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.16.0
github.com/stackitcloud/stackit-sdk-go/services/telemetrylink v0.2.0
github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter v0.3.0
github.com/stackitcloud/stackit-sdk-go/services/vpn v0.14.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,8 @@ github.com/stackitcloud/stackit-sdk-go/services/sfs v0.11.0 h1:YhQ2GF+AyHVUps1iE
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.11.0/go.mod h1:jMlBoXqrPNX5nXbo6oT7exalqilw1jiLPoIp4Cn0CdI=
github.com/stackitcloud/stackit-sdk-go/services/ske v1.18.0 h1:6Umom7V12bVa7D3dnMJAKj/GWg7wqR9FpqmZ8TjsO1Q=
github.com/stackitcloud/stackit-sdk-go/services/ske v1.18.0/go.mod h1:TbqmZhLMofmfl+HhVl6oHYcI3zvXTm1vRjN3A/fOkM4=
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.13.0 h1:w7l3Z7lkDKnJ+3rudGjZ8GMKxGmpIS5dT6pO9MMNWqQ=
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.13.0/go.mod h1:AiUoMAqQcOlMgDtkVJlqI7P/VGD5xjN3dYjERGnwN/M=
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.16.0 h1:A6zN5JUz5DOTigTxAyAC+4p5VpJzaYDftx2yIH0mgn8=
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.16.0/go.mod h1:AiUoMAqQcOlMgDtkVJlqI7P/VGD5xjN3dYjERGnwN/M=
github.com/stackitcloud/stackit-sdk-go/services/telemetrylink v0.2.0 h1:U1mQoCk0TXc8NsSc/Sl9PKMdEyJpWNU2zLnsqmx6wEc=
github.com/stackitcloud/stackit-sdk-go/services/telemetrylink v0.2.0/go.mod h1:hgw8janWmDfP2bnuZensxqcAePr49BX5ug8Rq85o+h8=
github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter v0.3.0 h1:MEvzGItcbig+9A4JvK2E5W6/mqXDPafiGkDZ1BprBAI=
Expand Down
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, "metrics_retention_days", "sets `UseStateForUnknown` only if `metrics_retention_days` has not changed"),
int32planmodifier.UseStateForUnknownIf(int32planmodifier.Int32Changed(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, "metrics_retention_days_5m_downsampling", "sets `UseStateForUnknown` only if `metrics_retention_days_5m_downsampling` has not changed"),
int32planmodifier.UseStateForUnknownIf(int32planmodifier.Int32Changed(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, "metrics_retention_days_1h_downsampling", "sets `UseStateForUnknown` only if `metrics_retention_days_1h_downsampling` has not changed"),
int32planmodifier.UseStateForUnknownIf(int32planmodifier.Int32Changed(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
91 changes: 60 additions & 31 deletions stackit/internal/services/sqlserverflex/instance/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
sqlserverflex "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v2api"
sqlserverflex "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3api"
)

// Ensure the implementation satisfies the expected interfaces.
Expand Down Expand Up @@ -62,15 +62,21 @@ func (r *instanceDataSource) Configure(ctx context.Context, req datasource.Confi
// Schema defines the schema for the data source.
func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
descriptions := map[string]string{
"main": "SQLServer Flex instance data source schema. Must have a `region` specified in the provider configuration.",
"id": "Terraform's internal data source. ID. It is structured as \"`project_id`,`region`,`instance_id`\".",
"instance_id": "ID of the SQLServer Flex instance.",
"project_id": "STACKIT project ID to which the instance is associated.",
"name": "Instance name.",
"acl": "The Access Control List (ACL) for the SQLServer Flex instance.",
"backup_schedule": `The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *").`,
"options": "Custom parameters for the SQLServer Flex instance.",
"region": "The resource region. If not defined, the provider region is used.",
"main": "SQLServer Flex instance data source schema. Must have a `region` specified in the provider configuration.",
"id": "Terraform's internal data source. ID. It is structured as \"`project_id`,`region`,`instance_id`\".",
"instance_id": "ID of the SQLServer Flex instance.",
"project_id": "STACKIT project ID to which the instance is associated.",
"name": "Instance name.",
"acl": "The Access Control List (ACL) for the SQLServer Flex instance.",
"backup_schedule": `The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *").`,
"options": "Custom parameters for the SQLServer Flex instance.",
"flavor_id": "The flavor ID of the SQLServer Flex instance.",
"network": "The network configuration of the instance.",
"network.access_scope": "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.",
"network.acl": "List of IPV4 cidr.",
"retention_days": "The days (30 to 90) for how long the backup files should be stored before cleaned up.",
"edition": "Edition of the MSSQL server instance.",
"region": "The resource region. If not defined, the provider region is used.",
}

resp.Schema = schema.Schema{
Expand Down Expand Up @@ -118,14 +124,33 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques
"description": schema.StringAttribute{
Computed: true,
},
"cpu": schema.Int32Attribute{
"cpu": schema.Int64Attribute{
Computed: true,
},
"ram": schema.Int32Attribute{
"ram": schema.Int64Attribute{
Computed: true,
},
},
},
"flavor_id": schema.StringAttribute{
Description: descriptions["flavor_id"],
Computed: true,
},
"network": schema.SingleNestedAttribute{
Description: descriptions["network"],
Optional: true,
Attributes: map[string]schema.Attribute{
"access_scope": schema.StringAttribute{
Description: descriptions["network.access_scope"],
Optional: true,
},
"acl": schema.ListAttribute{
Description: descriptions["network.acl"],
ElementType: types.StringType,
Computed: true,
},
},
},
"replicas": schema.Int32Attribute{
Computed: true,
},
Expand All @@ -143,18 +168,26 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques
"version": schema.StringAttribute{
Computed: true,
},
"edition": schema.StringAttribute{
Description: descriptions["edition"],
Computed: true,
},
"options": schema.SingleNestedAttribute{
Description: descriptions["options"],
Computed: true,
Attributes: map[string]schema.Attribute{
"edition": schema.StringAttribute{
Computed: true,
},
"retention_days": schema.Int64Attribute{
"retention_days": schema.Int32Attribute{
Computed: true,
},
},
},
"retention_days": schema.Int32Attribute{
Description: descriptions["retention_days"],
Computed: true,
},
"region": schema.StringAttribute{
// the region cannot be found, so it has to be passed
Optional: true,
Expand All @@ -181,7 +214,7 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "instance_id", instanceId)
ctx = tflog.SetField(ctx, "region", region)
instanceResp, err := r.client.DefaultAPI.GetInstance(ctx, projectId, instanceId, region).Execute()
instanceResp, err := r.client.DefaultAPI.GetInstance(ctx, projectId, region, instanceId).Execute()
if err != nil {
utils.LogError(
ctx,
Expand All @@ -199,22 +232,6 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques

ctx = core.LogResponse(ctx)

var flavor = &flavorModel{}
if !(model.Flavor.IsNull() || model.Flavor.IsUnknown()) {
diags = model.Flavor.As(ctx, flavor, basetypes.ObjectAsOptions{})
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}
var storage = &storageModel{}
if !(model.Storage.IsNull() || model.Storage.IsUnknown()) {
diags = model.Storage.As(ctx, storage, basetypes.ObjectAsOptions{})
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}
var options = &optionsModel{}
if !(model.Options.IsNull() || model.Options.IsUnknown()) {
diags = model.Options.As(ctx, options, basetypes.ObjectAsOptions{})
Expand All @@ -224,7 +241,19 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
}
}

err = mapFields(ctx, instanceResp, &model, flavor, storage, options, region)
flavorResp, err := getFlavor(ctx, r.client.DefaultAPI, projectId, region, instanceResp.FlavorId)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Finding flavor: %v", err))
return
}
flavor := &flavorModel{
Id: types.StringValue(flavorResp.Id),
Description: types.StringValue(flavorResp.Description),
CPU: types.Int64Value(flavorResp.Cpu),
RAM: types.Int64Value(flavorResp.Memory),
}

err = mapFields(ctx, instanceResp, &model, flavor, region)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API payload: %v", err))
return
Expand Down
Loading
Loading