Skip to content

Commit a48a37f

Browse files
committed
fix: skip XOR validation when directory/archive_path values are unknown
Per Terraform framework guidance, validators should not emit errors for unknown values. When either directory or archive_path is unknown (e.g., referencing a computed value from another resource), the XOR check is skipped. Terraform will re-run validators once values resolve during apply.
1 parent 1f8930d commit a48a37f

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

internal/provider/template_resource.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,25 +1000,31 @@ func (a *versionsValidator) ValidateList(ctx context.Context, req validator.List
10001000
uniqueNames := make(map[string]struct{})
10011001
for i, version := range data {
10021002
// Exactly one of directory or archive_path must be set.
1003+
// Skip validation when either value is unknown (depends on another
1004+
// resource). Terraform will re-run validators once values resolve.
10031005
dirSet := !version.Directory.IsNull()
10041006
archiveSet := !version.ArchivePath.IsNull()
1005-
if !dirSet && !archiveSet {
1006-
resp.Diagnostics.AddAttributeError(
1007-
req.Path.AtListIndex(i),
1008-
"Invalid Version Source",
1009-
"Exactly one of `directory` or `archive_path` must be specified for each template version.",
1010-
)
1011-
return
1012-
}
1013-
if dirSet && archiveSet {
1014-
resp.Diagnostics.AddAttributeError(
1015-
req.Path.AtListIndex(i),
1016-
"Invalid Version Source",
1017-
"`directory` and `archive_path` are mutually exclusive for each template version.",
1018-
)
1019-
return
1007+
dirUnknown := version.Directory.IsUnknown()
1008+
archiveUnknown := version.ArchivePath.IsUnknown()
1009+
if !dirUnknown && !archiveUnknown {
1010+
if !dirSet && !archiveSet {
1011+
resp.Diagnostics.AddAttributeError(
1012+
req.Path.AtListIndex(i),
1013+
"Invalid Version Source",
1014+
"Exactly one of `directory` or `archive_path` must be specified for each template version.",
1015+
)
1016+
return
1017+
}
1018+
if dirSet && archiveSet {
1019+
resp.Diagnostics.AddAttributeError(
1020+
req.Path.AtListIndex(i),
1021+
"Invalid Version Source",
1022+
"`directory` and `archive_path` are mutually exclusive for each template version.",
1023+
)
1024+
return
1025+
}
10201026
}
1021-
if archiveSet && !version.ArchivePath.IsUnknown() {
1027+
if archiveSet && !archiveUnknown {
10221028
archivePath := version.ArchivePath.ValueString()
10231029
if !strings.HasSuffix(archivePath, ".tar") && !strings.HasSuffix(archivePath, ".zip") {
10241030
resp.Diagnostics.AddAttributeError(

0 commit comments

Comments
 (0)