Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita533bc8

Browse files
committed
fix: skip validating unknown version names
1 parent39ce21c commita533bc8

File tree

2 files changed

+74
-13
lines changed

2 files changed

+74
-13
lines changed

‎internal/provider/template_resource.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -896,9 +896,27 @@ func (a *activeVersionValidator) ValidateList(ctx context.Context, req validator
896896
return
897897
}
898898

899+
// Check all versions have unique names
900+
uniqueNames:=make(map[string]struct{})
901+
for_,version:=rangedata {
902+
ifversion.Name.IsNull()||version.Name.IsUnknown() {
903+
continue
904+
}
905+
if_,ok:=uniqueNames[version.Name.ValueString()];ok {
906+
resp.Diagnostics.AddError("Client Error",fmt.Sprintf("Template version names must be unique. `%s` appears twice.",version.Name.ValueString()))
907+
return
908+
}
909+
uniqueNames[version.Name.ValueString()]=struct{}{}
910+
}
911+
899912
// Check if only one item in Version has active set to true
900913
active:=false
901914
for_,version:=rangedata {
915+
// `active` is required, so if it's null or unknown, this is Terraform
916+
// requesting an early validation.
917+
ifversion.Active.IsNull()||version.Active.IsUnknown() {
918+
return
919+
}
902920
ifversion.Active.ValueBool() {
903921
ifactive {
904922
resp.Diagnostics.AddError("Client Error","Only one template version can be active at a time.")
@@ -910,19 +928,6 @@ func (a *activeVersionValidator) ValidateList(ctx context.Context, req validator
910928
if!active {
911929
resp.Diagnostics.AddError("Client Error","At least one template version must be active.")
912930
}
913-
914-
// Check all versions have unique names
915-
uniqueNames:=make(map[string]struct{})
916-
for_,version:=rangedata {
917-
ifversion.Name.IsNull() {
918-
continue
919-
}
920-
if_,ok:=uniqueNames[version.Name.ValueString()];ok {
921-
resp.Diagnostics.AddError("Client Error","Template version names must be unique.")
922-
return
923-
}
924-
uniqueNames[version.Name.ValueString()]=struct{}{}
925-
}
926931
}
927932

928933
var_ validator.List=&activeVersionValidator{}

‎internal/provider/template_resource_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,62 @@ func TestAccTemplateResourceAGPL(t *testing.T) {
648648
})
649649
}
650650

651+
funcTestAccTemplateResourceVariables(t*testing.T) {
652+
cfg:=`
653+
provider coderd {
654+
url = "%s"
655+
token = "%s"
656+
}
657+
658+
data "coderd_organization" "default" {
659+
is_default = true
660+
}
661+
662+
variable "PRIOR_GIT_COMMIT_SHA" {
663+
default = "abcdef"
664+
}
665+
666+
variable "CURRENT_GIT_COMMIT_SHA" {
667+
default = "ghijkl"
668+
}
669+
670+
variable "ACTIVE" {
671+
default = true
672+
}
673+
674+
resource "coderd_template" "sample" {
675+
name = "example-template"
676+
versions = [
677+
{
678+
name = "${var.PRIOR_GIT_COMMIT_SHA}"
679+
directory = "../../integration/template-test/example-template"
680+
active = var.ACTIVE
681+
},
682+
{
683+
name = "${var.CURRENT_GIT_COMMIT_SHA}"
684+
directory = "../../integration/template-test/example-template"
685+
active = false
686+
}
687+
]
688+
}`
689+
690+
ctx:=context.Background()
691+
client:=integration.StartCoder(ctx,t,"template_acc",false)
692+
693+
cfg=fmt.Sprintf(cfg,client.URL.String(),client.SessionToken())
694+
695+
resource.Test(t, resource.TestCase{
696+
PreCheck:func() {testAccPreCheck(t) },
697+
IsUnitTest:true,
698+
ProtoV6ProviderFactories:testAccProtoV6ProviderFactories,
699+
Steps: []resource.TestStep{
700+
{
701+
Config:cfg,
702+
},
703+
},
704+
})
705+
}
706+
651707
typetestAccTemplateResourceConfigstruct {
652708
URLstring
653709
Tokenstring

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp