Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ed1bad

Browse files
committed
Block pushing templates with legacy parameters
1 parent 217ea69 commit 0ed1bad

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

provisioner/terraform/parse.go

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ func (s *server) Parse(request *proto.Parse_Request, stream proto.DRPCProvisione
7575
}
7676
templateVariables = append(templateVariables, mv)
7777
}
78+
} else if len(variables) > 0 {
79+
return xerrors.Errorf("legacy parameters are not supported anymore, use %q flag to enable managed Terraform variables", featureUseManagedVariables)
7880
}
7981
return stream.Send(&proto.Parse_Response{
8082
Type: &proto.Parse_Response_Complete{

provisioner/terraform/parse_test.go

+57-8
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,21 @@ func TestParse(t *testing.T) {
3131
Files: map[string]string{
3232
"main.tf": `variable "A" {
3333
description = "Testing!"
34-
}`,
34+
}
35+
36+
provider "coder" { feature_use_managed_variables = "true" }`,
3537
},
3638
Response: &proto.Parse_Response{
3739
Type: &proto.Parse_Response_Complete{
38-
Complete: &proto.Parse_Complete{},
40+
Complete: &proto.Parse_Complete{
41+
TemplateVariables: []*proto.TemplateVariable{
42+
{
43+
Name: "A",
44+
Description: "Testing!",
45+
Required: true,
46+
},
47+
},
48+
},
3949
},
4050
},
4151
},
@@ -44,11 +54,20 @@ func TestParse(t *testing.T) {
4454
Files: map[string]string{
4555
"main.tf": `variable "A" {
4656
default = "wow"
47-
}`,
57+
}
58+
59+
provider "coder" { feature_use_managed_variables = "true" }`,
4860
},
4961
Response: &proto.Parse_Response{
5062
Type: &proto.Parse_Response_Complete{
51-
Complete: &proto.Parse_Complete{},
63+
Complete: &proto.Parse_Complete{
64+
TemplateVariables: []*proto.TemplateVariable{
65+
{
66+
Name: "A",
67+
DefaultValue: "wow",
68+
},
69+
},
70+
},
5271
},
5372
},
5473
},
@@ -59,11 +78,20 @@ func TestParse(t *testing.T) {
5978
validation {
6079
condition = var.A == "value"
6180
}
62-
}`,
81+
}
82+
83+
provider "coder" { feature_use_managed_variables = "true" }`,
6384
},
6485
Response: &proto.Parse_Response{
6586
Type: &proto.Parse_Response_Complete{
66-
Complete: &proto.Parse_Complete{},
87+
Complete: &proto.Parse_Complete{
88+
TemplateVariables: []*proto.TemplateVariable{
89+
{
90+
Name: "A",
91+
Required: true,
92+
},
93+
},
94+
},
6795
},
6896
},
6997
},
@@ -78,13 +106,34 @@ func TestParse(t *testing.T) {
78106
Name: "multiple-variables",
79107
Files: map[string]string{
80108
"main1.tf": `variable "foo" { }
81-
variable "bar" { }`,
109+
variable "bar" { }
110+
111+
provider "coder" { feature_use_managed_variables = "true" }`,
82112
"main2.tf": `variable "baz" { }
83113
variable "quux" { }`,
84114
},
85115
Response: &proto.Parse_Response{
86116
Type: &proto.Parse_Response_Complete{
87-
Complete: &proto.Parse_Complete{},
117+
Complete: &proto.Parse_Complete{
118+
TemplateVariables: []*proto.TemplateVariable{
119+
{
120+
Name: "foo",
121+
Required: true,
122+
},
123+
{
124+
Name: "bar",
125+
Required: true,
126+
},
127+
{
128+
Name: "baz",
129+
Required: true,
130+
},
131+
{
132+
Name: "quux",
133+
Required: true,
134+
},
135+
},
136+
},
88137
},
89138
},
90139
},

0 commit comments

Comments
 (0)