Skip to content

Commit cd32a67

Browse files
committed
feat: implement sa access key resource
1 parent 77dd211 commit cd32a67

File tree

9 files changed

+600
-7
lines changed

9 files changed

+600
-7
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
Schema for a STACKIT service account access key resource.
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 access tokens
10+
11+
resource "stackit_service_account" "sa" {
12+
project_id = var.stackit_project_id
13+
name = "sa01"
14+
}
15+
16+
resource "time_rotating" "rotate" {
17+
rotation_days = 80
18+
}
19+
20+
resource "stackit_service_account_key" "sakey" {
21+
project_id = var.stackit_project_id
22+
service_account_email = stackit_service_account.sa.email
23+
ttl_days = 90
24+
}
25+
---
26+
27+
# stackit_service_account_key (Resource)
28+
29+
Schema for a STACKIT service account access key resource.
30+
31+
~> 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.
32+
## Example Usage
33+
34+
35+
### Automatically rotate access tokens
36+
```terraform
37+
resource "stackit_service_account" "sa" {
38+
project_id = var.stackit_project_id
39+
name = "sa01"
40+
}
41+
42+
resource "time_rotating" "rotate" {
43+
rotation_days = 80
44+
}
45+
46+
resource "stackit_service_account_key" "sakey" {
47+
project_id = var.stackit_project_id
48+
service_account_email = stackit_service_account.sa.email
49+
ttl_days = 90
50+
}
51+
52+
```
53+
54+
55+
56+
<!-- schema generated by tfplugindocs -->
57+
## Schema
58+
59+
### Required
60+
61+
- `project_id` (String) The STACKIT project ID associated with the service account key.
62+
- `service_account_email` (String) The email address associated with the service account, used for account identification and communication.
63+
64+
### Optional
65+
66+
- `public_key` (String) Specifies the certificate file (certificate.pem) required for generating the public and private keys. If not provided, a default certificate from STACKIT will be used.
67+
- `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.
68+
- `ttl_days` (Number) Specifies the key's validity duration in days. If left unspecified, the key is considered valid until it is deleted
69+
70+
### Read-Only
71+
72+
- `id` (String) The unique internal identifier for the Terraform resource, formatted as a combination of 'project_id,key_id'.
73+
- `json` (String, Sensitive) The raw JSON representation of the API response, available for direct use.
74+
- `key_id` (String) The unique identifier for the key associated with the service account.

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ require (
3737
golang.org/x/mod v0.23.0
3838
)
3939

40-
require github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
40+
require (
41+
github.com/davecgh/go-spew v1.1.1 // indirect
42+
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
43+
github.com/pmezard/go-difflib v1.0.0 // indirect
44+
gopkg.in/yaml.v3 v3.0.1 // indirect
45+
)
4146

4247
require (
4348
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
@@ -76,7 +81,7 @@ require (
7681
github.com/oklog/run v1.1.0 // indirect
7782
github.com/rogpeppe/go-internal v1.12.0 // indirect
7883
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.6.0
79-
github.com/stretchr/testify v1.8.4 // indirect
84+
github.com/stretchr/testify v1.8.4
8085
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
8186
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
8287
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v0.5.0 h1:QG+r
195195
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v0.5.0/go.mod h1:16dOVT052cMuHhUJ3NIcPuY7TrpCr9QlxmvvfjLZubA=
196196
github.com/stackitcloud/stackit-sdk-go/services/ske v0.22.0 h1:3KUVls8zXsbT2tOYRSHyp3/l0Kpjl4f3INmQKYTe65Y=
197197
github.com/stackitcloud/stackit-sdk-go/services/ske v0.22.0/go.mod h1:63IvXpBJTIVONAnGPSDo0sRJ+6n6tzO918OLqfYBxto=
198-
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v0.10.0 h1:STq6VaVUeHLeXzl1r5E4+MK5lcNVtdKjjP7N0XOowY4=
199-
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v0.10.0/go.mod h1:hdeLDwSCOmGIYtY4DGN15kjL44DQvo/txHXtTEvZidA=
200198
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.0.0 h1:RYJO0rZea9+sxVfaJDWRo2zgfKNgiUcA5c0nbvZURiU=
201199
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.0.0/go.mod h1:d2ICXCS2h3IMsZW0OanWkEH2XdLiY/XRKx2TcR940nw=
202200
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

stackit/internal/conversion/conversion.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func StringListToPointer(list basetypes.ListValue) (*[]string, error) {
136136

137137
// ToJSONMApPartialUpdatePayload returns a map[string]interface{} to be used in a PATCH request payload.
138138
// It takes a current map as it is in the terraform state and a desired map as it is in the user configuratiom
139-
// and builds a map which sets to null keys that should be removed, updates the values of existing keys and adds new keys
139+
// and builds a map which sets to null key that should be removed, updates the values of existing key and adds new key
140140
// This method is needed because in partial updates, e.g. if the key is not provided it is ignored and not removed
141141
func ToJSONMapPartialUpdatePayload(ctx context.Context, current, desired types.Map) (map[string]interface{}, error) {
142142
currentMap, err := ToStringInterfaceMap(ctx, current)
@@ -150,7 +150,7 @@ func ToJSONMapPartialUpdatePayload(ctx context.Context, current, desired types.M
150150
}
151151

152152
mapPayload := map[string]interface{}{}
153-
// Update and remove existing keys
153+
// Update and remove existing key
154154
for k := range currentMap {
155155
if desiredValue, ok := desiredMap[k]; ok {
156156
mapPayload[k] = desiredValue
@@ -159,7 +159,7 @@ func ToJSONMapPartialUpdatePayload(ctx context.Context, current, desired types.M
159159
}
160160
}
161161

162-
// Add new keys
162+
// Add new key
163163
for k, desiredValue := range desiredMap {
164164
if _, ok := mapPayload[k]; !ok {
165165
mapPayload[k] = desiredValue
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package key
2+
3+
const markdownDescription = `
4+
Schema for a STACKIT service account access key resource.` + "\n" + `
5+
~> 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.
6+
## Example Usage` + "\n" + `
7+
8+
### Automatically rotate access tokens` + "\n" +
9+
"```terraform" + `
10+
resource "stackit_service_account" "sa" {
11+
project_id = var.stackit_project_id
12+
name = "sa01"
13+
}
14+
15+
resource "time_rotating" "rotate" {
16+
rotation_days = 80
17+
}
18+
19+
resource "stackit_service_account_key" "sakey" {
20+
project_id = var.stackit_project_id
21+
service_account_email = stackit_service_account.sa.email
22+
ttl_days = 90
23+
}
24+
` + "\n```"

0 commit comments

Comments
 (0)