Skip to content

Commit e9d000c

Browse files
committed
chore(workers_script): use resourcevalidator.ExactlyOneOf() to ensure content or content_file is provided
1 parent 757b98f commit e9d000c

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

internal/services/workers_script/custom.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ func (v contentSHA256Validator) ValidateString(ctx context.Context, req validato
128128
hasContentFile = true
129129
}
130130

131-
if !hasContent && !hasContentFile {
132-
resp.Diagnostics.AddError("Missing required attributes", "One of `content` or `content_file` is required")
133-
return
134-
}
135-
136131
var actualHash string
137132
var err error
138133

internal/services/workers_script/schema.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
1313
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
1414
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
15+
"github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator"
1516
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1617
"github.com/hashicorp/terraform-plugin-framework/path"
1718
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -650,5 +651,10 @@ func (r *WorkersScriptResource) Schema(ctx context.Context, req resource.SchemaR
650651
}
651652

652653
func (r *WorkersScriptResource) ConfigValidators(_ context.Context) []resource.ConfigValidator {
653-
return []resource.ConfigValidator{}
654+
return []resource.ConfigValidator{
655+
resourcevalidator.ExactlyOneOf(
656+
path.MatchRoot("content"),
657+
path.MatchRoot("content_file"),
658+
),
659+
}
654660
}

0 commit comments

Comments
 (0)