Skip to content

Commit 8d54ca1

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 10f4dd5 commit 8d54ca1

23 files changed

Lines changed: 226 additions & 0 deletions

File tree

.changelog/0.21.0.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
[[features]]
44

55
[[enhancements]]
6+
title = "Validate UUID Attributes"
7+
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)."
68

79
[[bugs]]

internal/provider/anti_affinity_group/resource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ This resource manages anti-affinity groups.
9696
"project_id": schema.StringAttribute{
9797
Required: true,
9898
Description: "ID of the project that will contain the anti-affinity group.",
99+
Validators: []validator.String{
100+
shared.UUID(),
101+
},
99102
PlanModifiers: []planmodifier.String{
100103
stringplanmodifier.RequiresReplace(),
101104
},

internal/provider/disk/resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ To create a blank disk it's necessary to set ''block_size''. Otherwise, one of '
121121
"project_id": schema.StringAttribute{
122122
Required: true,
123123
Description: "ID of the project that will contain the disk.",
124+
Validators: []validator.String{
125+
shared.UUID(),
126+
},
124127
PlanModifiers: []planmodifier.String{
125128
stringplanmodifier.RequiresReplace(),
126129
},
@@ -150,6 +153,7 @@ To create a blank disk it's necessary to set ''block_size''. Otherwise, one of '
150153
Optional: true,
151154
Description: "Image ID of the disk source if applicable.",
152155
Validators: []validator.String{
156+
shared.UUID(),
153157
stringvalidator.ConflictsWith(path.Expressions{
154158
path.MatchRoot("block_size"),
155159
}...),
@@ -165,6 +169,7 @@ To create a blank disk it's necessary to set ''block_size''. Otherwise, one of '
165169
Optional: true,
166170
Description: "Snapshot ID of the disk source if applicable.",
167171
Validators: []validator.String{
172+
shared.UUID(),
168173
stringvalidator.ConflictsWith(path.Expressions{
169174
path.MatchRoot("block_size"),
170175
}...),

internal/provider/external_subnet/resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ func (r *Resource) Schema(
129129
"project_id": schema.StringAttribute{
130130
Required: true,
131131
Description: "Project ID where this external subnet is located.",
132+
Validators: []validator.String{
133+
shared.UUID(),
134+
},
132135
PlanModifiers: []planmodifier.String{
133136
stringplanmodifier.RequiresReplace(),
134137
},
@@ -168,6 +171,7 @@ func (r *Resource) Schema(
168171
stringplanmodifier.UseStateForUnknown(),
169172
},
170173
Validators: []validator.String{
174+
shared.UUID(),
171175
stringvalidator.ConflictsWith(path.MatchRoot("subnet")),
172176
},
173177
},

internal/provider/external_subnet_attachment/resource.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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"
@@ -98,13 +99,19 @@ func (r *Resource) Schema(
9899
"external_subnet_id": schema.StringAttribute{
99100
Required: true,
100101
Description: "ID of the external subnet to attach.",
102+
Validators: []validator.String{
103+
shared.UUID(),
104+
},
101105
PlanModifiers: []planmodifier.String{
102106
stringplanmodifier.RequiresReplace(),
103107
},
104108
},
105109
"instance_id": schema.StringAttribute{
106110
Required: true,
107111
Description: "ID of the instance to attach the external subnet to.",
112+
Validators: []validator.String{
113+
shared.UUID(),
114+
},
108115
PlanModifiers: []planmodifier.String{
109116
stringplanmodifier.RequiresReplace(),
110117
},

internal/provider/floating_ip/resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ This resource manages Oxide floating IPs.
144144
stringplanmodifier.RequiresReplaceIfConfigured(),
145145
},
146146
Validators: []validator.String{
147+
shared.UUID(),
147148
stringvalidator.ConflictsWith(path.MatchRoot("ip")),
148149
stringvalidator.ConflictsWith(path.MatchRoot("ip_version")),
149150
},
@@ -168,6 +169,9 @@ This resource manages Oxide floating IPs.
168169
"project_id": schema.StringAttribute{
169170
Required: true,
170171
Description: "Project ID where this floating IP is located.",
172+
Validators: []validator.String{
173+
shared.UUID(),
174+
},
171175
PlanModifiers: []planmodifier.String{
172176
stringplanmodifier.RequiresReplace(),
173177
},

internal/provider/image/resource.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ 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"
@@ -111,6 +112,9 @@ This resource manages images.
111112
"project_id": schema.StringAttribute{
112113
Required: true,
113114
Description: "ID of the project that will contain the image.",
115+
Validators: []validator.String{
116+
shared.UUID(),
117+
},
114118
PlanModifiers: []planmodifier.String{
115119
stringplanmodifier.RequiresReplace(),
116120
},
@@ -143,6 +147,9 @@ This resource manages images.
143147
"source_snapshot_id": schema.StringAttribute{
144148
Required: true,
145149
Description: "Snapshot ID of the image source if applicable.",
150+
Validators: []validator.String{
151+
shared.UUID(),
152+
},
146153
PlanModifiers: []planmodifier.String{
147154
stringplanmodifier.RequiresReplace(),
148155
},

internal/provider/images/datasource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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"
@@ -92,6 +93,9 @@ Retrieve a list of all images belonging to a silo or project.
9293
"project_id": schema.StringAttribute{
9394
Optional: true,
9495
Description: "ID of the project which contains the images.",
96+
Validators: []validator.String{
97+
shared.UUID(),
98+
},
9599
},
96100
"id": schema.StringAttribute{
97101
Computed: true,

internal/provider/instance/resource.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ This resource manages instances.
242242
"project_id": schema.StringAttribute{
243243
Required: true,
244244
Description: "ID for the project containing this instance.",
245+
Validators: []validator.String{
246+
shared.UUID(),
247+
},
245248
PlanModifiers: []planmodifier.String{
246249
stringplanmodifier.RequiresReplace(),
247250
},
@@ -314,6 +317,7 @@ This resource manages instances.
314317
Optional: true,
315318
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`.",
316319
Validators: []validator.String{
320+
shared.UUID(),
317321
stringvalidator.AlsoRequires(
318322
path.MatchRoot("disk_attachments"),
319323
),
@@ -379,6 +383,9 @@ This resource manages instances.
379383
"subnet_id": schema.StringAttribute{
380384
Required: true,
381385
Description: "ID of the VPC subnet in which to create the instance network interface.",
386+
Validators: []validator.String{
387+
shared.UUID(),
388+
},
382389
PlanModifiers: []planmodifier.String{
383390
stringplanmodifier.RequiresReplaceIf(
384391
shared.RequiresReplaceUnlessEmptyStringOrNull(), "", "",
@@ -388,6 +395,9 @@ This resource manages instances.
388395
"vpc_id": schema.StringAttribute{
389396
Required: true,
390397
Description: "ID of the VPC in which to create the instance network interface.",
398+
Validators: []validator.String{
399+
shared.UUID(),
400+
},
391401
PlanModifiers: []planmodifier.String{
392402
stringplanmodifier.RequiresReplaceIf(
393403
shared.RequiresReplaceUnlessEmptyStringOrNull(), "", "",
@@ -527,6 +537,7 @@ This resource manages instances.
527537
Computed: true,
528538
MarkdownDescription: "ID of the IP pool to allocate from. Conflicts with `ip_version`.",
529539
Validators: []validator.String{
540+
shared.UUID(),
530541
stringvalidator.ConflictsWith(
531542
path.MatchRelative().AtParent().AtName("ip_version"),
532543
),

internal/provider/instance_external_ips/datasource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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"
@@ -79,6 +80,9 @@ Retrieve information of all external IPs associated to an instance.
7980
"instance_id": schema.StringAttribute{
8081
Required: true,
8182
Description: "ID of the instance to which the external IPs belong to.",
83+
Validators: []validator.String{
84+
shared.UUID(),
85+
},
8286
},
8387
"id": schema.StringAttribute{
8488
Computed: true,

0 commit comments

Comments
 (0)