feat: update SQL Server Flex client configuration
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / CI (pull_request) Failing after 9m28s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 16m18s
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / CI (pull_request) Failing after 9m28s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 16m18s
This commit is contained in:
parent
4383300103
commit
694a3cfef0
22 changed files with 3342 additions and 1740 deletions
|
|
@ -74,7 +74,7 @@ func (d *databaseDataSource) Configure(
|
|||
return
|
||||
}
|
||||
d.client = apiClient
|
||||
tflog.Info(ctx, "SQL SERVER Flex database client configured")
|
||||
tflog.Info(ctx, "SQL SERVER Flex alpha database client configured")
|
||||
}
|
||||
|
||||
// Read retrieves the resource's state from the API.
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ func TestMapFields(t *testing.T) {
|
|||
|
||||
func TestMapResourceFields(t *testing.T) {
|
||||
type given struct {
|
||||
source *sqlserverflexalpha.ListDatabase
|
||||
source *sqlserverflexalpha.GetDatabaseResponse
|
||||
model *resourceModel
|
||||
region string
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ func TestMapResourceFields(t *testing.T) {
|
|||
{
|
||||
name: "should map fields correctly",
|
||||
given: given{
|
||||
source: &sqlserverflexalpha.ListDatabase{
|
||||
source: &sqlserverflexalpha.GetDatabaseResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Name: utils.Ptr("my-db"),
|
||||
Owner: utils.Ptr("\"my-owner\""),
|
||||
|
|
|
|||
|
|
@ -326,35 +326,51 @@ func (r *databaseResource) Read(ctx context.Context, req resource.ReadRequest, r
|
|||
tflog.Info(ctx, "sqlserverflexalpha.Database read")
|
||||
}
|
||||
|
||||
func (r *databaseResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
var data resourceModel
|
||||
|
||||
// Read Terraform plan data into the model
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Todo: Update API call logic
|
||||
|
||||
// Save updated data into Terraform state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
|
||||
tflog.Info(ctx, "sqlserverflexalpha.Database updated")
|
||||
func (r *databaseResource) Update(ctx context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
// TODO: Check update api endpoint - not available at the moment, so return an error for now
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating database", "Database can't be updated")
|
||||
}
|
||||
|
||||
func (r *databaseResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
var data sqlserverflexalphaGen.DatabaseModel
|
||||
|
||||
// Read Terraform prior state data into the model
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||
|
||||
// nolint:gocritic // function signature required by Terraform
|
||||
var model resourceModel
|
||||
diags := req.State.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Todo: Delete API call logic
|
||||
// Read identity data
|
||||
var identityData DatabaseResourceIdentityModel
|
||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId, instanceId, region, databaseName, errExt := r.extractIdentityData(model, identityData)
|
||||
if errExt != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
extractErrorSummary,
|
||||
fmt.Sprintf(extractErrorMessage, errExt),
|
||||
)
|
||||
}
|
||||
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
ctx = tflog.SetField(ctx, "database_name", databaseName)
|
||||
|
||||
// Delete existing record set
|
||||
err := r.client.DeleteDatabaseRequestExecute(ctx, projectId, region, instanceId, databaseName)
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting database", fmt.Sprintf("Calling API: %v", err))
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
tflog.Info(ctx, "sqlserverflexalpha.Database deleted")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue