Skip to content

Commit

Permalink
Merge pull request #16 from komminarlabs/tk/bug-fix
Browse files Browse the repository at this point in the history
bug fix: fixed pointer issue in token resource
  • Loading branch information
thulasirajkomminar authored Aug 13, 2024
2 parents eb94a3b + 712aca8 commit a2295ca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/resources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Creates and manages a database.

### Required

- `name` (String) The name of the cluster database. The Length should be between `[ 1 .. 64 ]` characters. **Note:** After a database is deleted, you cannot [reuse](https://docs.influxdata.com/influxdb/cloud-dedicated/admin/databases/delete/#cannot-reuse-database-names) the same name for a new database.
- `name` (String) The name of the cluster database. The Length should be between `[ 1 .. 64 ]` characters. **Note:** Database names can't be updated. After a database is deleted, you cannot [reuse](https://docs.influxdata.com/influxdb/cloud-dedicated/admin/databases/delete/#cannot-reuse-database-names) the same name for a new database.

### Optional

Expand Down
9 changes: 7 additions & 2 deletions internal/provider/database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/komminarlabs/influxdb3"
Expand Down Expand Up @@ -55,7 +57,10 @@ func (r *DatabaseResource) Schema(ctx context.Context, req resource.SchemaReques
},
"name": schema.StringAttribute{
Required: true,
Description: "The name of the cluster database. The Length should be between `[ 1 .. 64 ]` characters. **Note:** After a database is deleted, you cannot [reuse](https://docs.influxdata.com/influxdb/cloud-dedicated/admin/databases/delete/#cannot-reuse-database-names) the same name for a new database.",
Description: "The name of the cluster database. The Length should be between `[ 1 .. 64 ]` characters. **Note:** Database names can't be updated. After a database is deleted, you cannot [reuse](https://docs.influxdata.com/influxdb/cloud-dedicated/admin/databases/delete/#cannot-reuse-database-names) the same name for a new database.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
stringvalidator.LengthBetween(1, 64),
},
Expand Down Expand Up @@ -257,7 +262,7 @@ func (r *DatabaseResource) Delete(ctx context.Context, req resource.DeleteReques
return
}

if deleteDatabasesResponse.StatusCode() != 200 {
if deleteDatabasesResponse.StatusCode() != 204 {
resp.Diagnostics.AddError(
"Error deleting database",
fmt.Sprintf("Status: %s", deleteDatabasesResponse.Status()),
Expand Down
11 changes: 7 additions & 4 deletions internal/provider/token_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package provider
import (
"context"
"fmt"
"unsafe"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
Expand Down Expand Up @@ -119,9 +118,11 @@ func (r *TokenResource) Create(ctx context.Context, req resource.CreateRequest,
// Generate API request body from plan
var permissionsRequest []influxdb3.DatabaseTokenPermission
for _, permission := range plan.Permissions {
resource := influxdb3.DatabaseTokenPermissionResource{}
resource.FromClusterDatabaseName(permission.Resource.ValueString())
permission := influxdb3.DatabaseTokenPermission{
Action: permission.Action.ValueStringPointer(),
Resource: (*influxdb3.DatabaseTokenPermissionResource)((unsafe.Pointer(&permission.Resource))),
Resource: &resource,
}
permissionsRequest = append(permissionsRequest, permission)
}
Expand Down Expand Up @@ -243,9 +244,11 @@ func (r *TokenResource) Update(ctx context.Context, req resource.UpdateRequest,
// Generate API request body from plan
var permissionsRequest []influxdb3.DatabaseTokenPermission
for _, permission := range plan.Permissions {
resource := influxdb3.DatabaseTokenPermissionResource{}
resource.FromClusterDatabaseName(permission.Resource.ValueString())
permission := influxdb3.DatabaseTokenPermission{
Action: permission.Action.ValueStringPointer(),
Resource: (*influxdb3.DatabaseTokenPermissionResource)((unsafe.Pointer(&permission.Resource))),
Resource: &resource,
}
permissionsRequest = append(permissionsRequest, permission)
}
Expand Down Expand Up @@ -319,7 +322,7 @@ func (r *TokenResource) Delete(ctx context.Context, req resource.DeleteRequest,
return
}

if deleteTokenResponse.StatusCode() != 200 {
if deleteTokenResponse.StatusCode() != 204 {
resp.Diagnostics.AddError(
"Error deleting token",
fmt.Sprintf("Status: %s", deleteTokenResponse.Status()),
Expand Down

0 comments on commit a2295ca

Please sign in to comment.