Skip to content

Commit 17f47db

Browse files
committed
enhancement: validate uuid attributes
Attributes that expect UUIDs now validate whether their values are, in fact, valid UUIDs. This catches cases where names were passed to attributes accidentally worked. Closes SSE-347.
1 parent e11529f commit 17f47db

24 files changed

Lines changed: 377 additions & 4 deletions

File tree

.changelog/0.21.0.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ title = "`oxide_ip_pool_silo_link`"
55
description = "The `id` attribute for the `oxide_ip_pool_silo_link` resource now uses the format `IP_POOL_ID/SILO_ID`, matching the `oxide_subnet_pool_silo_link` resource. [#794](https://github.com/oxidecomputer/terraform-provider-oxide/pull/794)"
66

77
[[enhancements]]
8+
title = "Validate UUID Attributes"
9+
description = "Attributes that expect UUIDs now validate whether their values are, in fact, valid UUIDs. This catches cases where names passed to attributes accidentally worked. [#795](https://github.com/oxidecomputer/terraform-provider-oxide/issues/795)."
810

911
[[bugs]]

internal/provider/anti_affinity_group/resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/oxidecomputer/oxide.go/oxide"
2222

2323
"github.com/oxidecomputer/terraform-provider-oxide/internal/provider/shared"
24+
oxidevalidator "github.com/oxidecomputer/terraform-provider-oxide/internal/provider/validator"
2425
)
2526

2627
// Ensure the implementation satisfies the expected interfaces.
@@ -96,6 +97,9 @@ This resource manages anti-affinity groups.
9697
"project_id": schema.StringAttribute{
9798
Required: true,
9899
Description: "ID of the project that will contain the anti-affinity group.",
100+
Validators: []validator.String{
101+
oxidevalidator.IsUUID(),
102+
},
99103
PlanModifiers: []planmodifier.String{
100104
stringplanmodifier.RequiresReplace(),
101105
},

internal/provider/disk/resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/oxidecomputer/oxide.go/oxide"
2727

2828
"github.com/oxidecomputer/terraform-provider-oxide/internal/provider/shared"
29+
oxidevalidator "github.com/oxidecomputer/terraform-provider-oxide/internal/provider/validator"
2930
)
3031

3132
// Ensure the implementation satisfies the expected interfaces.
@@ -121,6 +122,9 @@ To create a blank disk it's necessary to set ''block_size''. Otherwise, one of '
121122
"project_id": schema.StringAttribute{
122123
Required: true,
123124
Description: "ID of the project that will contain the disk.",
125+
Validators: []validator.String{
126+
oxidevalidator.IsUUID(),
127+
},
124128
PlanModifiers: []planmodifier.String{
125129
stringplanmodifier.RequiresReplace(),
126130
},
@@ -150,6 +154,7 @@ To create a blank disk it's necessary to set ''block_size''. Otherwise, one of '
150154
Optional: true,
151155
Description: "Image ID of the disk source if applicable.",
152156
Validators: []validator.String{
157+
oxidevalidator.IsUUID(),
153158
stringvalidator.ConflictsWith(path.Expressions{
154159
path.MatchRoot("block_size"),
155160
}...),
@@ -165,6 +170,7 @@ To create a blank disk it's necessary to set ''block_size''. Otherwise, one of '
165170
Optional: true,
166171
Description: "Snapshot ID of the disk source if applicable.",
167172
Validators: []validator.String{
173+
oxidevalidator.IsUUID(),
168174
stringvalidator.ConflictsWith(path.Expressions{
169175
path.MatchRoot("block_size"),
170176
}...),

internal/provider/external_subnet/resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/oxidecomputer/oxide.go/oxide"
2626

2727
"github.com/oxidecomputer/terraform-provider-oxide/internal/provider/shared"
28+
oxidevalidator "github.com/oxidecomputer/terraform-provider-oxide/internal/provider/validator"
2829
)
2930

3031
// Ensure the implementation satisfies the expected interfaces.
@@ -129,6 +130,9 @@ func (r *Resource) Schema(
129130
"project_id": schema.StringAttribute{
130131
Required: true,
131132
Description: "Project ID where this external subnet is located.",
133+
Validators: []validator.String{
134+
oxidevalidator.IsUUID(),
135+
},
132136
PlanModifiers: []planmodifier.String{
133137
stringplanmodifier.RequiresReplace(),
134138
},
@@ -168,6 +172,7 @@ func (r *Resource) Schema(
168172
stringplanmodifier.UseStateForUnknown(),
169173
},
170174
Validators: []validator.String{
175+
oxidevalidator.IsUUID(),
171176
stringvalidator.ConflictsWith(path.MatchRoot("subnet")),
172177
},
173178
},

internal/provider/external_subnet_attachment/resource.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import (
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1515
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1616
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
17+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1718
"github.com/hashicorp/terraform-plugin-framework/types"
1819
"github.com/hashicorp/terraform-plugin-log/tflog"
1920
"github.com/oxidecomputer/oxide.go/oxide"
2021

2122
"github.com/oxidecomputer/terraform-provider-oxide/internal/provider/shared"
23+
oxidevalidator "github.com/oxidecomputer/terraform-provider-oxide/internal/provider/validator"
2224
)
2325

2426
// Ensure the implementation satisfies the expected interfaces.
@@ -98,13 +100,19 @@ func (r *Resource) Schema(
98100
"external_subnet_id": schema.StringAttribute{
99101
Required: true,
100102
Description: "ID of the external subnet to attach.",
103+
Validators: []validator.String{
104+
oxidevalidator.IsUUID(),
105+
},
101106
PlanModifiers: []planmodifier.String{
102107
stringplanmodifier.RequiresReplace(),
103108
},
104109
},
105110
"instance_id": schema.StringAttribute{
106111
Required: true,
107112
Description: "ID of the instance to attach the external subnet to.",
113+
Validators: []validator.String{
114+
oxidevalidator.IsUUID(),
115+
},
108116
PlanModifiers: []planmodifier.String{
109117
stringplanmodifier.RequiresReplace(),
110118
},

internal/provider/floating_ip/resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/oxidecomputer/oxide.go/oxide"
2424

2525
"github.com/oxidecomputer/terraform-provider-oxide/internal/provider/shared"
26+
oxidevalidator "github.com/oxidecomputer/terraform-provider-oxide/internal/provider/validator"
2627
)
2728

2829
// ResourceModel represents the Terraform configuration and state for
@@ -144,6 +145,7 @@ This resource manages Oxide floating IPs.
144145
stringplanmodifier.RequiresReplaceIfConfigured(),
145146
},
146147
Validators: []validator.String{
148+
oxidevalidator.IsUUID(),
147149
stringvalidator.ConflictsWith(path.MatchRoot("ip")),
148150
stringvalidator.ConflictsWith(path.MatchRoot("ip_version")),
149151
},
@@ -168,6 +170,9 @@ This resource manages Oxide floating IPs.
168170
"project_id": schema.StringAttribute{
169171
Required: true,
170172
Description: "Project ID where this floating IP is located.",
173+
Validators: []validator.String{
174+
oxidevalidator.IsUUID(),
175+
},
171176
PlanModifiers: []planmodifier.String{
172177
stringplanmodifier.RequiresReplace(),
173178
},

internal/provider/image/resource.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import (
1515
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1616
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1717
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
18+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1819
"github.com/hashicorp/terraform-plugin-framework/types"
1920
"github.com/hashicorp/terraform-plugin-log/tflog"
2021
"github.com/oxidecomputer/oxide.go/oxide"
2122

2223
"github.com/oxidecomputer/terraform-provider-oxide/internal/provider/shared"
24+
oxidevalidator "github.com/oxidecomputer/terraform-provider-oxide/internal/provider/validator"
2325
)
2426

2527
// Ensure the implementation satisfies the expected interfaces.
@@ -111,6 +113,9 @@ This resource manages images.
111113
"project_id": schema.StringAttribute{
112114
Required: true,
113115
Description: "ID of the project that will contain the image.",
116+
Validators: []validator.String{
117+
oxidevalidator.IsUUID(),
118+
},
114119
PlanModifiers: []planmodifier.String{
115120
stringplanmodifier.RequiresReplace(),
116121
},
@@ -143,6 +148,9 @@ This resource manages images.
143148
"source_snapshot_id": schema.StringAttribute{
144149
Required: true,
145150
Description: "Snapshot ID of the image source if applicable.",
151+
Validators: []validator.String{
152+
oxidevalidator.IsUUID(),
153+
},
146154
PlanModifiers: []planmodifier.String{
147155
stringplanmodifier.RequiresReplace(),
148156
},

internal/provider/images/datasource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
1313
"github.com/hashicorp/terraform-plugin-framework/datasource"
1414
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
15+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1516
"github.com/hashicorp/terraform-plugin-framework/types"
1617
"github.com/hashicorp/terraform-plugin-log/tflog"
1718
"github.com/oxidecomputer/oxide.go/oxide"
1819

1920
"github.com/oxidecomputer/terraform-provider-oxide/internal/provider/shared"
21+
oxidevalidator "github.com/oxidecomputer/terraform-provider-oxide/internal/provider/validator"
2022
)
2123

2224
var (
@@ -92,6 +94,9 @@ Retrieve a list of all images belonging to a silo or project.
9294
"project_id": schema.StringAttribute{
9395
Optional: true,
9496
Description: "ID of the project which contains the images.",
97+
Validators: []validator.String{
98+
oxidevalidator.IsUUID(),
99+
},
95100
},
96101
"id": schema.StringAttribute{
97102
Computed: true,

internal/provider/instance/resource.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/oxidecomputer/oxide.go/oxide"
3636

3737
"github.com/oxidecomputer/terraform-provider-oxide/internal/provider/shared"
38+
oxidevalidator "github.com/oxidecomputer/terraform-provider-oxide/internal/provider/validator"
3839
)
3940

4041
// Ensure the implementation satisfies the expected interfaces.
@@ -242,6 +243,9 @@ This resource manages instances.
242243
"project_id": schema.StringAttribute{
243244
Required: true,
244245
Description: "ID for the project containing this instance.",
246+
Validators: []validator.String{
247+
oxidevalidator.IsUUID(),
248+
},
245249
PlanModifiers: []planmodifier.String{
246250
stringplanmodifier.RequiresReplace(),
247251
},
@@ -314,6 +318,7 @@ This resource manages instances.
314318
Optional: true,
315319
MarkdownDescription: "ID of the disk the instance should be booted from. Specifying a boot disk is optional but recommended to ensure predictable boot behavior. When provided, this ID must also be present in `disk_attachments`.",
316320
Validators: []validator.String{
321+
oxidevalidator.IsUUID(),
317322
stringvalidator.AlsoRequires(
318323
path.MatchRoot("disk_attachments"),
319324
),
@@ -379,6 +384,9 @@ This resource manages instances.
379384
"subnet_id": schema.StringAttribute{
380385
Required: true,
381386
Description: "ID of the VPC subnet in which to create the instance network interface.",
387+
Validators: []validator.String{
388+
oxidevalidator.IsUUID(),
389+
},
382390
PlanModifiers: []planmodifier.String{
383391
stringplanmodifier.RequiresReplaceIf(
384392
shared.RequiresReplaceUnlessEmptyStringOrNull(), "", "",
@@ -388,6 +396,9 @@ This resource manages instances.
388396
"vpc_id": schema.StringAttribute{
389397
Required: true,
390398
Description: "ID of the VPC in which to create the instance network interface.",
399+
Validators: []validator.String{
400+
oxidevalidator.IsUUID(),
401+
},
391402
PlanModifiers: []planmodifier.String{
392403
stringplanmodifier.RequiresReplaceIf(
393404
shared.RequiresReplaceUnlessEmptyStringOrNull(), "", "",
@@ -527,6 +538,7 @@ This resource manages instances.
527538
Computed: true,
528539
MarkdownDescription: "ID of the IP pool to allocate from. Conflicts with `ip_version`.",
529540
Validators: []validator.String{
541+
oxidevalidator.IsUUID(),
530542
stringvalidator.ConflictsWith(
531543
path.MatchRelative().AtParent().AtName("ip_version"),
532544
),

internal/provider/instance_external_ips/datasource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
1313
"github.com/hashicorp/terraform-plugin-framework/datasource"
1414
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
15+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1516
"github.com/hashicorp/terraform-plugin-framework/types"
1617
"github.com/hashicorp/terraform-plugin-log/tflog"
1718
"github.com/oxidecomputer/oxide.go/oxide"
1819

1920
"github.com/oxidecomputer/terraform-provider-oxide/internal/provider/shared"
21+
oxidevalidator "github.com/oxidecomputer/terraform-provider-oxide/internal/provider/validator"
2022
)
2123

2224
var (
@@ -79,6 +81,9 @@ Retrieve information of all external IPs associated to an instance.
7981
"instance_id": schema.StringAttribute{
8082
Required: true,
8183
Description: "ID of the instance to which the external IPs belong to.",
84+
Validators: []validator.String{
85+
oxidevalidator.IsUUID(),
86+
},
8287
},
8388
"id": schema.StringAttribute{
8489
Computed: true,

0 commit comments

Comments
 (0)