-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update base of provider to product base
- Loading branch information
1 parent
43750e2
commit 527f486
Showing
7 changed files
with
222 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// create.go | ||
package project | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
coolify_sdk "github.com/marconneves/coolify-sdk-go" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
) | ||
|
||
func (r *ProjectResource) CreateProject(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { | ||
var data ProjectModel | ||
|
||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
tflog.Debug(ctx, "Planned data before creation", map[string]interface{}{ | ||
"name": data.Name.ValueString(), | ||
"description": data.Description.ValueString(), | ||
}) | ||
|
||
createDTO := coolify_sdk.CreateProjectDTO{ | ||
Name: data.Name.ValueStringPointer(), | ||
Description: data.Description.ValueStringPointer(), | ||
} | ||
|
||
projectID, err := r.client.Project.Create(&createDTO) | ||
if err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create project, got error: %s", err)) | ||
return | ||
} | ||
|
||
data.Id = types.StringValue(*projectID) | ||
tflog.Trace(ctx, "Created a project", map[string]interface{}{"project_id": projectID}) | ||
|
||
tflog.Debug(ctx, "Data after project creation", map[string]interface{}{ | ||
"id": data.Id.ValueString(), | ||
"name": data.Name.ValueString(), | ||
"description": data.Description.ValueString(), | ||
}) | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
|
||
tflog.Debug(ctx, "Project state saved to file after creation") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package project | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
) | ||
|
||
func (r *ProjectResource) DeleteProject(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { | ||
var data ProjectModel | ||
|
||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
err := r.client.Project.Delete(data.Id.ValueString()) | ||
if err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete project, got error: %s", err)) | ||
return | ||
} | ||
|
||
tflog.Trace(ctx, "Deleted project", map[string]interface{}{"project_id": data.Id.ValueString()}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.