Skip to content

Commit 1c937d2

Browse files
committed
refactor: another round of cleanup
* cleaner payload * cleaner int types * cleaner logger * cleaner examples
1 parent 8220f18 commit 1c937d2

File tree

6 files changed

+36
-36
lines changed

6 files changed

+36
-36
lines changed

docs/resources/instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Aura instance
1717

1818
### Required
1919

20-
- `name` (String) Name if the instance
20+
- `name` (String) Name of the instance
2121
- `project_id` (String) Id of the project
2222
- `region` (String) Region of the instance
2323

examples/07-create-instance-snapshot/main.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ data "neo4jaura_projects" "this" {}
3232
variable "client_id" {}
3333
variable "client_secret" {}
3434

35-
variable "create_another" {
36-
type = bool
37-
default = false
38-
}
39-
4035
output "snapshot_profile" {
4136
value = neo4jaura_snapshot.this.profile
4237
}

internal/client/aura_api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (api *AuraApi) ResumeInstanceById(ctx context.Context, id string) (GetInsta
141141
return GetInstanceResponse{}, err
142142
}
143143
if status != 202 {
144-
return GetInstanceResponse{}, fmt.Errorf("Aura error: Status: %+v. Response: %+v", status, string(body))
144+
return GetInstanceResponse{}, fmt.Errorf("aura error: Status: %+v. Response: %+v", status, string(body))
145145
}
146146
return util.Unmarshal[GetInstanceResponse](body)
147147
}
@@ -169,7 +169,7 @@ func (api *AuraApi) GetSnapshotById(ctx context.Context, instanceId string, snap
169169
}
170170

171171
func (api *AuraApi) PostSnapshot(ctx context.Context, instanceId string) (PostSnapshotResponse, error) {
172-
body, status, err := api.auraClient.Post(ctx, fmt.Sprintf("instances/%s/snapshots", instanceId), []byte("{}"))
172+
body, status, err := api.auraClient.Post(ctx, fmt.Sprintf("instances/%s/snapshots", instanceId), nil)
173173
if err != nil {
174174
return PostSnapshotResponse{}, err
175175
}

internal/datasource/projects.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ func (ds *ProjectsDataSource) Read(ctx context.Context, request datasource.ReadR
123123

124124
tenantsValue, diags := types.ListValueFrom(ctx, data.Projects.ElementType(ctx), tenants)
125125
response.Diagnostics.Append(diags...)
126+
if response.Diagnostics.HasError() {
127+
return
128+
}
126129

127130
data.Projects = tenantsValue
128131

internal/resource/instance.go

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
2929
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
3030
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier"
31+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
3132
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
3233
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
3334
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -87,8 +88,8 @@ type InstanceResourceModel struct {
8788
Status types.String `tfsdk:"status"`
8889
CreatedAt types.String `tfsdk:"created_at"`
8990
MetricsIntegrationUrl types.String `tfsdk:"metrics_integration_url"`
90-
GraphNodes types.Int32 `tfsdk:"graph_nodes"`
91-
GraphRelationships types.Int32 `tfsdk:"graph_relationships"`
91+
GraphNodes types.Int64 `tfsdk:"graph_nodes"`
92+
GraphRelationships types.Int64 `tfsdk:"graph_relationships"`
9293
SecondariesCount types.Int32 `tfsdk:"secondaries_count"`
9394
CdcEnrichmentMode types.String `tfsdk:"cdc_enrichment_mode"`
9495
VectorOptimized types.Bool `tfsdk:"vector_optimized"`
@@ -149,8 +150,8 @@ func (r *InstanceResource) Schema(ctx context.Context, request resource.SchemaRe
149150
},
150151
},
151152
"name": schema.StringAttribute{
152-
MarkdownDescription: "Name if the instance",
153-
Description: "Name if the instance",
153+
MarkdownDescription: "Name of the instance",
154+
Description: "Name of the instance",
154155
Required: true,
155156
},
156157
"region": schema.StringAttribute{
@@ -280,20 +281,20 @@ func (r *InstanceResource) Schema(ctx context.Context, request resource.SchemaRe
280281
stringplanmodifier.UseStateForUnknown(),
281282
},
282283
},
283-
"graph_nodes": schema.Int32Attribute{
284+
"graph_nodes": schema.Int64Attribute{
284285
MarkdownDescription: "Number of nodes in the graph (free-db only)",
285286
Description: "Number of nodes in the graph (free-db only)",
286287
Computed: true,
287-
PlanModifiers: []planmodifier.Int32{
288-
int32planmodifier.UseStateForUnknown(),
288+
PlanModifiers: []planmodifier.Int64{
289+
int64planmodifier.UseStateForUnknown(),
289290
},
290291
},
291-
"graph_relationships": schema.Int32Attribute{
292+
"graph_relationships": schema.Int64Attribute{
292293
MarkdownDescription: "Number of relationships in the graph (only for free-db)",
293294
Description: "Number of relationships in the graph (only for free-db)",
294295
Computed: true,
295-
PlanModifiers: []planmodifier.Int32{
296-
int32planmodifier.UseStateForUnknown(),
296+
PlanModifiers: []planmodifier.Int64{
297+
int64planmodifier.UseStateForUnknown(),
297298
},
298299
},
299300
"secondaries_count": schema.Int32Attribute{
@@ -444,32 +445,32 @@ func (r *InstanceResource) Create(ctx context.Context, request resource.CreateRe
444445
data.MetricsIntegrationUrl = types.StringNull()
445446
}
446447
if instance.Data.GraphNodes != nil {
447-
graphNodes, err := strconv.Atoi(*instance.Data.GraphNodes)
448+
graphNodes, err := strconv.ParseInt(*instance.Data.GraphNodes, 10, 64)
448449
if err != nil {
449450
response.Diagnostics.AddWarning(
450451
"Error while parsing graph nodes",
451452
fmt.Sprintf("Cannot convert value to int: %s", *instance.Data.GraphNodes),
452453
)
453-
data.GraphNodes = types.Int32Null()
454+
data.GraphNodes = types.Int64Null()
454455
} else {
455-
data.GraphNodes = types.Int32Value(int32(graphNodes))
456+
data.GraphNodes = types.Int64Value(graphNodes)
456457
}
457458
} else {
458-
data.GraphNodes = types.Int32Null()
459+
data.GraphNodes = types.Int64Null()
459460
}
460461
if instance.Data.GraphRelationships != nil {
461-
graphRelationships, err := strconv.Atoi(*instance.Data.GraphRelationships)
462+
graphRelationships, err := strconv.ParseInt(*instance.Data.GraphRelationships, 10, 64)
462463
if err != nil {
463464
response.Diagnostics.AddWarning(
464465
"Error while parsing graph relationships",
465466
fmt.Sprintf("Cannot convert value to int: %s", *instance.Data.GraphNodes),
466467
)
467-
data.GraphRelationships = types.Int32Null()
468+
data.GraphRelationships = types.Int64Null()
468469
} else {
469-
data.GraphRelationships = types.Int32Value(int32(graphRelationships))
470+
data.GraphRelationships = types.Int64Value(graphRelationships)
470471
}
471472
} else {
472-
data.GraphRelationships = types.Int32Null()
473+
data.GraphRelationships = types.Int64Null()
473474
}
474475
if instance.Data.SecondariesCount != nil {
475476
data.SecondariesCount = types.Int32Value(int32(*instance.Data.SecondariesCount))
@@ -548,30 +549,30 @@ func (r *InstanceResource) Read(ctx context.Context, request resource.ReadReques
548549
stateData.MetricsIntegrationUrl = types.StringNull()
549550
}
550551
if instance.Data.GraphNodes != nil {
551-
graphNodes, err := strconv.Atoi(*instance.Data.GraphNodes)
552+
graphNodes, err := strconv.ParseInt(*instance.Data.GraphNodes, 10, 64)
552553
if err != nil {
553554
response.Diagnostics.AddWarning(
554555
"Error while parsing graph nodes",
555556
fmt.Sprintf("Cannot convert value to int: %s", *instance.Data.GraphNodes),
556557
)
557-
stateData.GraphNodes = types.Int32Null()
558+
stateData.GraphNodes = types.Int64Null()
558559
}
559-
stateData.GraphNodes = types.Int32Value(int32(graphNodes))
560+
stateData.GraphNodes = types.Int64Value(graphNodes)
560561
} else {
561-
stateData.GraphNodes = types.Int32Null()
562+
stateData.GraphNodes = types.Int64Null()
562563
}
563564
if instance.Data.GraphRelationships != nil {
564-
graphRelationships, err := strconv.Atoi(*instance.Data.GraphRelationships)
565+
graphRelationships, err := strconv.ParseInt(*instance.Data.GraphRelationships, 10, 64)
565566
if err != nil {
566567
response.Diagnostics.AddWarning(
567568
"Error while parsing graph relationships",
568569
fmt.Sprintf("Cannot convert value to int: %s", *instance.Data.GraphNodes),
569570
)
570-
stateData.GraphRelationships = types.Int32Null()
571+
stateData.GraphRelationships = types.Int64Null()
571572
}
572-
stateData.GraphRelationships = types.Int32Value(int32(graphRelationships))
573+
stateData.GraphRelationships = types.Int64Value(graphRelationships)
573574
} else {
574-
stateData.GraphRelationships = types.Int32Null()
575+
stateData.GraphRelationships = types.Int64Null()
575576
}
576577
if instance.Data.SecondariesCount != nil {
577578
stateData.SecondariesCount = types.Int32Value(int32(*instance.Data.SecondariesCount))

internal/resource/snapshot.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
2828
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2929
"github.com/hashicorp/terraform-plugin-framework/types"
30+
"github.com/hashicorp/terraform-plugin-log/tflog"
3031
"github.com/neo4j-labs/terraform-provider-neo4jaura/internal/client"
3132
)
3233

@@ -165,9 +166,9 @@ func (r *SnapshotResource) Read(ctx context.Context, request resource.ReadReques
165166
}
166167

167168
func (r *SnapshotResource) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) {
168-
// no op
169+
tflog.Info(ctx, "Snapshot resources are immutable and cannot be updated")
169170
}
170171

171172
func (r *SnapshotResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) {
172-
// snapshots are immutable
173+
tflog.Info(ctx, "Snapshot resources are immutable and cannot be deleted")
173174
}

0 commit comments

Comments
 (0)