Skip to content

Commit 8572fd5

Browse files
committed
update docs and remove not needed fields
Signed-off-by: Jorge Turrado <jorge.turrado@mail.schwarz>
1 parent 09f3573 commit 8572fd5

6 files changed

Lines changed: 188 additions & 94 deletions

File tree

docs/resources/service_account_federated_identity_provider.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ description: |-
1919
issuer = "https://auth.example.com"
2020
2121
assertions = [
22+
{
23+
item = "aud" # Including the audience check is mandatory for security reasons, the value is free to choose
24+
operator = "equals"
25+
value = "sts.accounts.stackit.cloud"
26+
},
2227
{
2328
item = "iss"
24-
operator = "EQUALS"
29+
operator = "equals"
2530
value = "https://auth.example.com"
2631
},
2732
{
2833
item = "email"
29-
operator = "EQUALS"
34+
operator = "equals"
3035
value = "terraform@example.com"
3136
}
3237
]
@@ -53,14 +58,19 @@ resource "stackit_service_account_federated_identity_provider" "provider" {
5358
issuer = "https://auth.example.com"
5459
5560
assertions = [
61+
{
62+
item = "aud" # Including the audience check is mandatory for security reasons, the value is free to choose
63+
operator = "equals"
64+
value = "sts.accounts.stackit.cloud"
65+
},
5666
{
5767
item = "iss"
58-
operator = "EQUALS"
68+
operator = "equals"
5969
value = "https://auth.example.com"
6070
},
6171
{
6272
item = "email"
63-
operator = "EQUALS"
73+
operator = "equals"
6474
value = "terraform@example.com"
6575
}
6676
]
@@ -75,25 +85,21 @@ resource "stackit_service_account_federated_identity_provider" "provider" {
7585

7686
### Required
7787

88+
- `assertions` (Attributes List) The assertions for the federated identity provider. (see [below for nested schema](#nestedatt--assertions))
7889
- `issuer` (String) The issuer URL.
7990
- `name` (String) The name of the federated identity provider.
8091
- `project_id` (String) The STACKIT project ID associated with the service account.
8192
- `service_account_email` (String) The email address associated with the service account, used for account identification and communication.
8293

83-
### Optional
84-
85-
- `assertions` (Attributes List) The assertions for the federated identity provider. (see [below for nested schema](#nestedatt--assertions))
86-
8794
### Read-Only
8895

89-
- `created_at` (String) The timestamp when the federated identity provider was created.
96+
- `federation_id` (String) The unique identifier for the federated identity provider associated with the service account.
9097
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`service_account_email`,`federation_id`".
91-
- `updated_at` (String) The timestamp when the federated identity provider was last updated.
9298

9399
<a id="nestedatt--assertions"></a>
94100
### Nested Schema for `assertions`
95101

96-
Optional:
102+
Required:
97103

98104
- `item` (String) The assertion claim.
99105
- `operator` (String) The assertion operator.

stackit/internal/services/serviceaccount/federated_identity_provider/const.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ resource "stackit_service_account_federated_identity_provider" "provider" {
1919
assertions = [
2020
{
2121
item = "aud" # Including the audience check is mandatory for security reasons, the value is free to choose
22-
operator = "EQUALS"
22+
operator = "equals"
2323
value = "sts.accounts.stackit.cloud"
2424
},
2525
{
2626
item = "iss"
27-
operator = "EQUALS"
27+
operator = "equals"
2828
value = "https://auth.example.com"
2929
},
3030
{
3131
item = "email"
32-
operator = "EQUALS"
32+
operator = "equals"
3333
value = "terraform@example.com"
3434
}
3535
]

stackit/internal/services/serviceaccount/federated_identity_provider/mapper_test.go

Lines changed: 120 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package federated_identity_provider
33
import (
44
"context"
55
"testing"
6-
"time"
76

87
"github.com/hashicorp/terraform-plugin-framework/attr"
98
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -30,12 +29,11 @@ func assertionsListFromModels(t *testing.T, ctx context.Context, assertions []As
3029
return listValue
3130
}
3231

32+
func ptrString(s string) *string { return &s }
33+
3334
func TestMapFields(t *testing.T) {
3435
ctx := context.Background()
3536

36-
createdAt := time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
37-
updatedAt := time.Date(2026, 2, 3, 4, 5, 6, 0, time.UTC)
38-
3937
tests := []struct {
4038
description string
4139
input *serviceaccount.FederatedIdentityProvider
@@ -50,10 +48,9 @@ func TestMapFields(t *testing.T) {
5048
projectID: "pid",
5149
serviceAccountEmail: "service-account@sa.stackit.cloud",
5250
input: &serviceaccount.FederatedIdentityProvider{
53-
Name: "provider-name",
54-
Issuer: "https://issuer.example.com",
55-
CreatedAt: createdAt,
56-
UpdatedAt: updatedAt,
51+
Id: ptrString("fed-uuid-123"),
52+
Name: "provider-name",
53+
Issuer: "https://issuer.example.com",
5754
Assertions: []serviceaccount.FederatedIdentityProviderAssertionsInner{
5855
{Item: "iss", Operator: "EQUALS", Value: "https://issuer.example.com"},
5956
{Item: "sub", Operator: "EQUALS", Value: "user@example.com"},
@@ -107,15 +104,12 @@ func TestMapFields(t *testing.T) {
107104
if model.Id.ValueString() != "pid,service-account@sa.stackit.cloud,provider-name" {
108105
t.Fatalf("id mismatch: got %q", model.Id.ValueString())
109106
}
107+
if model.FederationId.ValueString() != "fed-uuid-123" {
108+
t.Fatalf("federation_id mismatch: got %q", model.FederationId.ValueString())
109+
}
110110
if model.Issuer.ValueString() != "https://issuer.example.com" {
111111
t.Fatalf("issuer mismatch: got %q", model.Issuer.ValueString())
112112
}
113-
if model.CreatedAt.ValueString() != createdAt.Format(time.RFC3339) {
114-
t.Fatalf("created_at mismatch: got %q", model.CreatedAt.ValueString())
115-
}
116-
if model.UpdatedAt.ValueString() != updatedAt.Format(time.RFC3339) {
117-
t.Fatalf("updated_at mismatch: got %q", model.UpdatedAt.ValueString())
118-
}
119113
}
120114

121115
if tt.expectAssertionsNull {
@@ -125,12 +119,6 @@ func TestMapFields(t *testing.T) {
125119
if !model.Issuer.IsNull() {
126120
t.Fatalf("expected issuer to be null")
127121
}
128-
if !model.CreatedAt.IsNull() {
129-
t.Fatalf("expected created_at to be null")
130-
}
131-
if !model.UpdatedAt.IsNull() {
132-
t.Fatalf("expected updated_at to be null")
133-
}
134122
return
135123
}
136124

@@ -257,3 +245,115 @@ func TestToCreatePayload(t *testing.T) {
257245
})
258246
}
259247
}
248+
249+
func TestToUpdatePayload(t *testing.T) {
250+
ctx := context.Background()
251+
252+
validAssertions := []AssertionModel{
253+
{Item: types.StringValue("aud"), Operator: types.StringValue("equals"), Value: types.StringValue("https://example.com")},
254+
{Item: types.StringValue("sub"), Operator: types.StringValue("equals"), Value: types.StringValue("user@example.com")},
255+
}
256+
257+
tests := []struct {
258+
description string
259+
model *Model
260+
expectError bool
261+
}{
262+
{
263+
description: "all_fields_set",
264+
model: &Model{
265+
Name: types.StringValue("provider-name"),
266+
Issuer: types.StringValue("https://issuer.example.com"),
267+
Assertions: assertionsListFromModels(t, ctx, validAssertions),
268+
},
269+
},
270+
{
271+
description: "null_assertions_replaces_external",
272+
model: &Model{
273+
Name: types.StringValue("provider-name"),
274+
Issuer: types.StringValue("https://issuer.example.com"),
275+
Assertions: types.ListNull(types.ObjectType{
276+
AttrTypes: map[string]attr.Type{
277+
"item": types.StringType,
278+
"operator": types.StringType,
279+
"value": types.StringType,
280+
},
281+
}),
282+
},
283+
},
284+
{
285+
description: "null_issuer_and_name",
286+
model: &Model{
287+
Name: types.StringNull(),
288+
Issuer: types.StringNull(),
289+
Assertions: assertionsListFromModels(t, ctx, validAssertions[:1]),
290+
},
291+
},
292+
{
293+
description: "invalid_assertions_type",
294+
model: &Model{
295+
Name: types.StringValue("provider-name"),
296+
Issuer: types.StringValue("https://issuer.example.com"),
297+
Assertions: types.ListValueMust(types.StringType, []attr.Value{types.StringValue("not-an-object")}),
298+
},
299+
expectError: true,
300+
},
301+
}
302+
303+
for _, tt := range tests {
304+
t.Run(tt.description, func(t *testing.T) {
305+
payload, err := toUpdatePayload(ctx, tt.model)
306+
if tt.expectError {
307+
if err == nil {
308+
t.Fatalf("expected error but got nil")
309+
}
310+
if payload != nil {
311+
t.Fatalf("expected nil payload on error")
312+
}
313+
return
314+
}
315+
if err != nil {
316+
t.Fatalf("unexpected error: %v", err)
317+
}
318+
319+
switch tt.description {
320+
case "all_fields_set":
321+
if payload.Name != "provider-name" {
322+
t.Fatalf("name mismatch: got %q", payload.Name)
323+
}
324+
if payload.Issuer != "https://issuer.example.com" {
325+
t.Fatalf("issuer mismatch: got %q", payload.Issuer)
326+
}
327+
if len(payload.Assertions) != 2 {
328+
t.Fatalf("assertions length mismatch: got %d, expected 2", len(payload.Assertions))
329+
}
330+
if payload.Assertions[0].Item == nil || *payload.Assertions[0].Item != "aud" {
331+
t.Fatalf("assertions[0].item mismatch")
332+
}
333+
if payload.Assertions[0].Operator == nil || *payload.Assertions[0].Operator != "equals" {
334+
t.Fatalf("assertions[0].operator mismatch")
335+
}
336+
if payload.Assertions[0].Value == nil || *payload.Assertions[0].Value != "https://example.com" {
337+
t.Fatalf("assertions[0].value mismatch")
338+
}
339+
if payload.Assertions[1].Item == nil || *payload.Assertions[1].Item != "sub" {
340+
t.Fatalf("assertions[1].item mismatch")
341+
}
342+
case "null_assertions_replaces_external":
343+
if len(payload.Assertions) != 0 {
344+
t.Fatalf("expected assertions to be empty when null, got %d", len(payload.Assertions))
345+
}
346+
case "null_issuer_and_name":
347+
if payload.Issuer != "" {
348+
t.Fatalf("expected empty issuer for null, got %q", payload.Issuer)
349+
}
350+
if payload.Name != "" {
351+
t.Fatalf("expected empty name for null, got %q", payload.Name)
352+
}
353+
if len(payload.Assertions) != 1 {
354+
t.Fatalf("assertions length mismatch: got %d, expected 1", len(payload.Assertions))
355+
}
356+
}
357+
})
358+
}
359+
}

stackit/internal/services/serviceaccount/federated_identity_provider/model.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ type Model struct {
1111
Name types.String `tfsdk:"name"`
1212
Issuer types.String `tfsdk:"issuer"`
1313
Assertions types.List `tfsdk:"assertions"`
14-
CreatedAt types.String `tfsdk:"created_at"`
15-
UpdatedAt types.String `tfsdk:"updated_at"`
1614
}
1715

1816
// AssertionModel describes an assertion in the assertions list.

0 commit comments

Comments
 (0)