Skip to content

Commit 0dbc14d

Browse files
committed
oxide_instance: add validation to ssh_public_keys attribute
Add validation to the `ssh_public_keys` attribute to validate that it contains no empty or null values. A customer pointed out that the following Terraform configuration resulted in an unclear error message. ```hcl resource "oxide_instance" "example" { ssh_public_keys = ["4db0f0d3-8e82-491a-beff-39764be1c529", null] } ``` Even worse, the error message didn't occur until apply time. ``` oxide_instance.example: Creating... ╷ │ Error: Error retrieving name or ID information │ │ with oxide_instance.example, │ on main.tf line 22, in resource "oxide_instance" "example": │ 22: resource "oxide_instance" "example" { │ │ name or ID parse error: invalid syntax ╵ ``` With this change, the error message occurs at plan time and is much more clear. ``` > terraform apply ╷ │ Error: Null Set Value │ │ with oxide_instance.example, │ on main.tf line 31, in resource "oxide_instance" "example": │ 31: ssh_public_keys = ["4db0f0d3-8e82-491a-beff-39764be1c529", null] │ │ This attribute contains a null value. ╵ ```
1 parent 7478329 commit 0dbc14d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

internal/provider/resource_instance.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
14+
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
1415
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1516
"github.com/hashicorp/terraform-plugin-framework/attr"
1617
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -178,6 +179,12 @@ func (r *instanceResource) Schema(ctx context.Context, _ resource.SchemaRequest,
178179
PlanModifiers: []planmodifier.Set{
179180
setplanmodifier.RequiresReplace(),
180181
},
182+
Validators: []validator.Set{
183+
setvalidator.NoNullValues(),
184+
setvalidator.ValueStringsAre(
185+
stringvalidator.NoneOf(""),
186+
),
187+
},
181188
},
182189
"network_interfaces": schema.SetNestedAttribute{
183190
Optional: true,

0 commit comments

Comments
 (0)