Skip to content

Commit cd4e912

Browse files
JorTurFerJorge Turrado
authored andcommitted
fix tests
Signed-off-by: Jorge Turrado <jorge.turrado@mail.schwarz>
1 parent 6e066c8 commit cd4e912

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestMapFields(t *testing.T) {
101101
if model.Name.ValueString() != "provider-name" {
102102
t.Fatalf("name mismatch: got %q", model.Name.ValueString())
103103
}
104-
if model.Id.ValueString() != "pid,service-account@sa.stackit.cloud,provider-name" {
104+
if model.Id.ValueString() != "pid,service-account@sa.stackit.cloud,fed-uuid-123" {
105105
t.Fatalf("id mismatch: got %q", model.Id.ValueString())
106106
}
107107
if model.FederationId.ValueString() != "fed-uuid-123" {

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (r *ServiceAccountFederatedIdentityProviderResource) Metadata(_ context.Con
4444
resp.TypeName = req.ProviderTypeName + "_service_account_federated_identity_provider"
4545
}
4646

47-
func (r *ServiceAccountFederatedIdentityProviderResource) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
47+
func (r *ServiceAccountFederatedIdentityProviderResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
4848
descriptions := map[string]string{
4949
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`service_account_email`,`federation_id`\".",
5050
"main": "Service account federated identity provider schema.",
@@ -340,17 +340,24 @@ func mapFields(ctx context.Context, apiResp *serviceaccount.FederatedIdentityPro
340340
if apiResp == nil {
341341
return fmt.Errorf("apiResp is nil")
342342
}
343-
model.Id = utils.BuildInternalTerraformId(projectId, serviceAccountEmail, *apiResp.Id)
343+
344+
federationId := ""
345+
if apiResp.Id != nil {
346+
federationId = *apiResp.Id
347+
}
348+
model.Id = utils.BuildInternalTerraformId(projectId, serviceAccountEmail, federationId)
344349
model.ProjectId = types.StringValue(projectId)
345350
model.ServiceAccountEmail = types.StringValue(serviceAccountEmail)
346-
if apiResp.Id != nil {
347-
model.FederationId = types.StringValue(*apiResp.Id)
351+
if federationId != "" {
352+
model.FederationId = types.StringValue(federationId)
348353
} else {
349354
model.FederationId = types.StringNull()
350355
}
351356

352357
if apiResp.Name != "" {
353358
model.Name = types.StringValue(apiResp.Name)
359+
} else {
360+
model.Name = types.StringNull()
354361
}
355362

356363
if apiResp.Issuer != "" {

0 commit comments

Comments
 (0)