parent
d1e12fcf64
commit
24b7387db9
140 changed files with 1597 additions and 7 deletions
|
|
@ -102,6 +102,8 @@ func (r *serviceAccountDataSource) Read(ctx context.Context, req datasource.Read
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
// Extract the project ID from the model configuration
|
||||
projectId := model.ProjectId.ValueString()
|
||||
|
||||
|
|
@ -120,6 +122,8 @@ func (r *serviceAccountDataSource) Read(ctx context.Context, req datasource.Read
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Iterate over the service accounts returned by the API to find the one matching the email
|
||||
serviceAccounts := *listSaResp.Items
|
||||
for i := range serviceAccounts {
|
||||
|
|
|
|||
|
|
@ -128,6 +128,8 @@ func (r *serviceAccountResource) Create(ctx context.Context, req resource.Create
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
// Set logging context with the project ID and service account name.
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountName := model.Name.ValueString()
|
||||
|
|
@ -148,6 +150,8 @@ func (r *serviceAccountResource) Create(ctx context.Context, req resource.Create
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Set the service account name and map the response to the resource schema.
|
||||
model.Name = types.StringValue(serviceAccountName)
|
||||
err = mapFields(serviceAccountResp, &model)
|
||||
|
|
@ -178,6 +182,8 @@ func (r *serviceAccountResource) Read(ctx context.Context, req resource.ReadRequ
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
// Extract the project ID for the service account.
|
||||
projectId := model.ProjectId.ValueString()
|
||||
|
||||
|
|
@ -188,6 +194,8 @@ func (r *serviceAccountResource) Read(ctx context.Context, req resource.ReadRequ
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Iterate over the list of service accounts to find the one that matches the email from the state.
|
||||
serviceAccounts := *listSaResp.Items
|
||||
for i := range serviceAccounts {
|
||||
|
|
@ -233,6 +241,8 @@ func (r *serviceAccountResource) Delete(ctx context.Context, req resource.Delete
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountName := model.Name.ValueString()
|
||||
serviceAccountEmail := model.Email.ValueString()
|
||||
|
|
@ -245,6 +255,9 @@ func (r *serviceAccountResource) Delete(ctx context.Context, req resource.Delete
|
|||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting service account", fmt.Sprintf("Calling API: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
tflog.Info(ctx, "Service account deleted")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -162,6 +162,8 @@ func (r *serviceAccountKeyResource) Create(ctx context.Context, req resource.Cre
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
// Set logging context with the project ID and service account email.
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
|
||||
|
|
@ -182,6 +184,8 @@ func (r *serviceAccountKeyResource) Create(ctx context.Context, req resource.Cre
|
|||
// Initialize the API request with the required parameters.
|
||||
saAccountKeyResp, err := r.client.CreateServiceAccountKey(ctx, projectId, serviceAccountEmail).CreateServiceAccountKeyPayload(*payload).Execute()
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Failed to create service account key", fmt.Sprintf("API call error: %v", err))
|
||||
return
|
||||
|
|
@ -213,6 +217,8 @@ func (r *serviceAccountKeyResource) Read(ctx context.Context, req resource.ReadR
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
|
||||
keyId := model.KeyId.ValueString()
|
||||
|
|
@ -230,6 +236,8 @@ func (r *serviceAccountKeyResource) Read(ctx context.Context, req resource.ReadR
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// No mapping needed for read response, as private_key is excluded and ID remains unchanged.
|
||||
diags = resp.State.Set(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
|
|
@ -260,6 +268,8 @@ func (r *serviceAccountKeyResource) Delete(ctx context.Context, req resource.Del
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
|
||||
keyId := model.KeyId.ValueString()
|
||||
|
|
@ -274,6 +284,8 @@ func (r *serviceAccountKeyResource) Delete(ctx context.Context, req resource.Del
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
tflog.Info(ctx, "Service account key deleted")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -179,6 +179,8 @@ func (r *serviceAccountTokenResource) Create(ctx context.Context, req resource.C
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
// Set logging context with the project ID and service account email.
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
|
||||
|
|
@ -194,12 +196,13 @@ func (r *serviceAccountTokenResource) Create(ctx context.Context, req resource.C
|
|||
|
||||
// Initialize the API request with the required parameters.
|
||||
serviceAccountAccessTokenResp, err := r.client.CreateAccessToken(ctx, projectId, serviceAccountEmail).CreateAccessTokenPayload(*payload).Execute()
|
||||
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Failed to create service account access token", fmt.Sprintf("API call error: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Map the response to the resource schema.
|
||||
err = mapCreateResponse(serviceAccountAccessTokenResp, &model)
|
||||
if err != nil {
|
||||
|
|
@ -227,6 +230,8 @@ func (r *serviceAccountTokenResource) Read(ctx context.Context, req resource.Rea
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
// Extract the project ID and serviceAccountEmail for the service account.
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
|
||||
|
|
@ -245,6 +250,8 @@ func (r *serviceAccountTokenResource) Read(ctx context.Context, req resource.Rea
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Iterate over the list of service account tokens to find the one that matches the ID from the state.
|
||||
saTokens := *listSaTokensResp.Items
|
||||
for i := range saTokens {
|
||||
|
|
@ -296,6 +303,8 @@ func (r *serviceAccountTokenResource) Delete(ctx context.Context, req resource.D
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
|
||||
accessTokenId := model.AccessTokenId.ValueString()
|
||||
|
|
@ -309,6 +318,9 @@ func (r *serviceAccountTokenResource) Delete(ctx context.Context, req resource.D
|
|||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting service account token", fmt.Sprintf("Calling API: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
tflog.Info(ctx, "Service account token deleted")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue