Skip to content

Commit 9cea076

Browse files
committed
make sure port sends as null
1 parent 7fd5c5a commit 9cea076

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

internal/client/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type Database struct {
55
Name string `json:"name"`
66
Adapter string `json:"adapter"`
77
Hostname string `json:"hostname"`
8-
Port int64 `json:"port"`
8+
Port *int64 `json:"port"`
99
Database string `json:"database"`
1010
Ssl bool `json:"ssl"`
1111
Cacertfile string `json:"cacertfile"`

internal/provider/devhub_querydesk_database_resource.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,17 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
209209
})
210210
}
211211

212+
var port *int64
213+
if !plan.Port.IsNull() {
214+
portValue := plan.Port.ValueInt64()
215+
port = &portValue
216+
}
217+
212218
input := devhub.Database{
213219
Name: plan.Name.ValueString(),
214220
Adapter: strings.ToLower(plan.Adapter.ValueString()),
215221
Hostname: plan.Hostname.ValueString(),
216-
Port: plan.Port.ValueInt64(),
222+
Port: port,
217223
Database: plan.Database.ValueString(),
218224
Ssl: plan.Ssl.ValueBool(),
219225
Cacertfile: plan.Cacertfile.ValueString(),
@@ -293,8 +299,8 @@ func (r *databaseResource) Read(ctx context.Context, req resource.ReadRequest, r
293299
state.SlackChannel = types.StringNull()
294300
state.AgentId = types.StringNull()
295301

296-
if database.Port != 0 {
297-
state.Port = types.Int64Value(database.Port)
302+
if database.Port != nil {
303+
state.Port = types.Int64Value(*database.Port)
298304
}
299305

300306
if database.Group != "" {
@@ -361,11 +367,17 @@ func (r *databaseResource) Update(ctx context.Context, req resource.UpdateReques
361367
})
362368
}
363369

370+
var port *int64
371+
if !plan.Port.IsNull() {
372+
portValue := plan.Port.ValueInt64()
373+
port = &portValue
374+
}
375+
364376
input := devhub.Database{
365377
Name: plan.Name.ValueString(),
366378
Adapter: strings.ToLower(plan.Adapter.ValueString()),
367379
Hostname: plan.Hostname.ValueString(),
368-
Port: plan.Port.ValueInt64(),
380+
Port: port,
369381
Database: plan.Database.ValueString(),
370382
Ssl: plan.Ssl.ValueBool(),
371383
Cacertfile: plan.Cacertfile.ValueString(),

0 commit comments

Comments
 (0)