Skip to content

Commit dcd6460

Browse files
authored
Merge branch 'stackitcloud:main' into main
2 parents 01201ed + 1444376 commit dcd6460

File tree

22 files changed

+954
-521
lines changed

22 files changed

+954
-521
lines changed

docs/data-sources/ske_cluster.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ data "stackit_ske_cluster" "example" {
2727
- `name` (String) The cluster name.
2828
- `project_id` (String) STACKIT project ID to which the cluster is associated.
2929

30+
### Optional
31+
32+
- `region` (String) The resource region. If not defined, the provider region is used.
33+
3034
### Read-Only
3135

3236
- `allow_privileged_containers` (Boolean, Deprecated) DEPRECATED as of Kubernetes 1.25+

docs/data-sources/ske_project.md

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stackit_service_account_key Resource - stackit"
4+
subcategory: ""
5+
description: |-
6+
Service account key schema.
7+
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
8+
Example Usage
9+
Automatically rotate service account keys
10+
11+
resource "stackit_service_account" "sa" {
12+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
13+
name = "sa01"
14+
}
15+
16+
resource "time_rotating" "rotate" {
17+
rotation_days = 80
18+
}
19+
20+
resource "stackit_service_account_key" "sa_key" {
21+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
22+
service_account_email = stackit_service_account.sa.email
23+
ttl_days = 90
24+
25+
rotate_when_changed = {
26+
rotation = time_rotating.rotate.id
27+
}
28+
}
29+
---
30+
31+
# stackit_service_account_key (Resource)
32+
33+
Service account key schema.
34+
35+
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.
36+
## Example Usage
37+
38+
39+
### Automatically rotate service account keys
40+
```terraform
41+
resource "stackit_service_account" "sa" {
42+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
43+
name = "sa01"
44+
}
45+
46+
resource "time_rotating" "rotate" {
47+
rotation_days = 80
48+
}
49+
50+
resource "stackit_service_account_key" "sa_key" {
51+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
52+
service_account_email = stackit_service_account.sa.email
53+
ttl_days = 90
54+
55+
rotate_when_changed = {
56+
rotation = time_rotating.rotate.id
57+
}
58+
}
59+
60+
```
61+
62+
63+
64+
<!-- schema generated by tfplugindocs -->
65+
## Schema
66+
67+
### Required
68+
69+
- `project_id` (String) The STACKIT project ID associated with the service account key.
70+
- `service_account_email` (String) The email address associated with the service account, used for account identification and communication.
71+
72+
### Optional
73+
74+
- `public_key` (String) Specifies the public_key (RSA2048 key-pair). If not provided, a certificate from STACKIT will be used to generate a private_key.
75+
- `rotate_when_changed` (Map of String) A map of arbitrary key/value pairs designed to force key recreation when they change, facilitating key rotation based on external factors such as a changing timestamp. Modifying this map triggers the creation of a new resource.
76+
- `ttl_days` (Number) Specifies the key's validity duration in days. If left unspecified, the key is considered valid until it is deleted
77+
78+
### Read-Only
79+
80+
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`service_account_email`,`key_id`".
81+
- `json` (String, Sensitive) The raw JSON representation of the service account key json, available for direct use.
82+
- `key_id` (String) The unique identifier for the key associated with the service account.

docs/resources/ske_cluster.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ Deprecated as of Kubernetes 1.25 and later
5959
- `kubernetes_version_min` (String) The minimum Kubernetes version. This field will be used to set the minimum kubernetes version on creation/update of the cluster. If unset, the latest supported Kubernetes version will be used. SKE automatically updates the cluster Kubernetes version if you have set `maintenance.enable_kubernetes_version_updates` to true or if there is a mandatory update, as described in [Updates for Kubernetes versions and Operating System versions in SKE](https://docs.stackit.cloud/stackit/en/version-updates-in-ske-10125631.html). To get the current kubernetes version being used for your cluster, use the read-only `kubernetes_version_used` field.
6060
- `maintenance` (Attributes) A single maintenance block as defined below. (see [below for nested schema](#nestedatt--maintenance))
6161
- `network` (Attributes) Network block as defined below. (see [below for nested schema](#nestedatt--network))
62+
- `region` (String) The resource region. If not defined, the provider region is used.
6263

6364
### Read-Only
6465

6566
- `egress_address_ranges` (List of String) The outgoing network ranges (in CIDR notation) of traffic originating from workload on the cluster.
66-
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`name`".
67+
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`name`".
6768
- `kubernetes_version_used` (String) Full Kubernetes version used. For example, if 1.22 was set in `kubernetes_version_min`, this value may result to 1.22.15. SKE automatically updates the cluster Kubernetes version if you have set `maintenance.enable_kubernetes_version_updates` to true or if there is a mandatory update, as described in [Updates for Kubernetes versions and Operating System versions in SKE](https://docs.stackit.cloud/stackit/en/version-updates-in-ske-10125631.html).
6869

6970
<a id="nestedatt--node_pools"></a>

docs/resources/ske_project.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

examples/data-sources/stackit_ske_project/data-source.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/resources/stackit_ske_project/resource.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v0.6.0
3232
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v0.5.0
3333
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.6.0
34-
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v0.5.0
34+
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.0.0
3535
github.com/stackitcloud/stackit-sdk-go/services/ske v0.22.0
3636
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.0.0
3737
github.com/teambition/rrule-go v1.8.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ github.com/stackitcloud/stackit-sdk-go/services/serverupdate v0.5.0 h1:TMUxDh8XG
192192
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v0.5.0/go.mod h1:giHnHz3kHeLY8Av9MZLsyJlaTXYz+BuGqdP/SKB5Vo0=
193193
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.6.0 h1:y+XzJcntHJ7M+IWWvAUkiVFA8op+jZxwHs3ktW2aLoA=
194194
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.6.0/go.mod h1:J/Wa67cbDI1wAyxib9PiEbNqGfIoFUH+DSLueVazQx8=
195-
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v0.5.0 h1:QG+rGBHsyXOlJ3ZIeOgExGqu9PoTlGY1rltW/VpG6lw=
196-
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v0.5.0/go.mod h1:16dOVT052cMuHhUJ3NIcPuY7TrpCr9QlxmvvfjLZubA=
195+
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.0.0 h1:Xxd5KUSWRt7FytnNWClLEa0n9GM6e5xAKo835ODSpAM=
196+
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.0.0/go.mod h1:EMqjiq/72WKXSwnJGLpumUJS4Uwlyhg5vtNg7qWoGtc=
197197
github.com/stackitcloud/stackit-sdk-go/services/ske v0.22.0 h1:3KUVls8zXsbT2tOYRSHyp3/l0Kpjl4f3INmQKYTe65Y=
198198
github.com/stackitcloud/stackit-sdk-go/services/ske v0.22.0/go.mod h1:63IvXpBJTIVONAnGPSDo0sRJ+6n6tzO918OLqfYBxto=
199199
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.0.0 h1:RYJO0rZea9+sxVfaJDWRo2zgfKNgiUcA5c0nbvZURiU=

stackit/internal/services/postgresflex/user/resource.go

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/hashicorp/terraform-plugin-framework/resource"
2121
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
2222
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
23-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
2423
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2524
"github.com/hashicorp/terraform-plugin-framework/types"
2625
"github.com/stackitcloud/stackit-sdk-go/core/config"
@@ -202,9 +201,6 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
202201
Description: descriptions["roles"],
203202
ElementType: types.StringType,
204203
Required: true,
205-
PlanModifiers: []planmodifier.Set{
206-
setplanmodifier.RequiresReplace(),
207-
},
208204
Validators: []validator.Set{
209205
setvalidator.ValueStringsAre(
210206
stringvalidator.OneOf("login", "createdb"),
@@ -344,9 +340,74 @@ func (r *userResource) Read(ctx context.Context, req resource.ReadRequest, resp
344340
}
345341

346342
// Update updates the resource and sets the updated Terraform state on success.
347-
func (r *userResource) Update(ctx context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { // nolint:gocritic // function signature required by Terraform
348-
// Update shouldn't be called
349-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", "User can't be updated")
343+
func (r *userResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { // nolint:gocritic // function signature required by Terraform
344+
// Retrieve values from plan
345+
var model Model
346+
diags := req.Plan.Get(ctx, &model)
347+
resp.Diagnostics.Append(diags...)
348+
if resp.Diagnostics.HasError() {
349+
return
350+
}
351+
projectId := model.ProjectId.ValueString()
352+
instanceId := model.InstanceId.ValueString()
353+
userId := model.UserId.ValueString()
354+
region := model.Region.ValueString()
355+
ctx = tflog.SetField(ctx, "project_id", projectId)
356+
ctx = tflog.SetField(ctx, "instance_id", instanceId)
357+
ctx = tflog.SetField(ctx, "user_id", userId)
358+
ctx = tflog.SetField(ctx, "region", region)
359+
360+
// Retrieve values from state
361+
var stateModel Model
362+
diags = req.State.Get(ctx, &stateModel)
363+
resp.Diagnostics.Append(diags...)
364+
if resp.Diagnostics.HasError() {
365+
return
366+
}
367+
368+
var roles []string
369+
if !(model.Roles.IsNull() || model.Roles.IsUnknown()) {
370+
diags = model.Roles.ElementsAs(ctx, &roles, false)
371+
resp.Diagnostics.Append(diags...)
372+
if resp.Diagnostics.HasError() {
373+
return
374+
}
375+
}
376+
377+
// Generate API request body from model
378+
payload, err := toUpdatePayload(&model, roles)
379+
if err != nil {
380+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", fmt.Sprintf("Updating API payload: %v", err))
381+
return
382+
}
383+
384+
// Update existing instance
385+
err = r.client.UpdateUser(ctx, projectId, region, instanceId, userId).UpdateUserPayload(*payload).Execute()
386+
if err != nil {
387+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", err.Error())
388+
return
389+
}
390+
391+
userResp, err := r.client.GetUser(ctx, projectId, region, instanceId, userId).Execute()
392+
if err != nil {
393+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", fmt.Sprintf("Calling API: %v", err))
394+
return
395+
}
396+
397+
// Map response body to schema
398+
err = mapFields(userResp, &stateModel, region)
399+
if err != nil {
400+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", fmt.Sprintf("Processing API payload: %v", err))
401+
return
402+
}
403+
404+
// Set state to fully populated data
405+
diags = resp.State.Set(ctx, stateModel)
406+
resp.Diagnostics.Append(diags...)
407+
if resp.Diagnostics.HasError() {
408+
return
409+
}
410+
tflog.Info(ctx, "Postgres Flex user updated")
350411
}
351412

352413
// Delete deletes the resource and removes the Terraform state on success.
@@ -515,3 +576,16 @@ func toCreatePayload(model *Model, roles []string) (*postgresflex.CreateUserPayl
515576
Username: conversion.StringValueToPointer(model.Username),
516577
}, nil
517578
}
579+
580+
func toUpdatePayload(model *Model, roles []string) (*postgresflex.UpdateUserPayload, error) {
581+
if model == nil {
582+
return nil, fmt.Errorf("nil model")
583+
}
584+
if roles == nil {
585+
return nil, fmt.Errorf("nil roles")
586+
}
587+
588+
return &postgresflex.UpdateUserPayload{
589+
Roles: &roles,
590+
}, nil
591+
}

0 commit comments

Comments
 (0)