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

Skip to content

Commit 58fc371

Browse files
committed
WIP
1 parent 4493649 commit 58fc371

10 files changed

+757
-526
lines changed

coderd/database/dump.sql

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE template_version_variables;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE TABLE IF NOT EXISTS template_version_variables (
2+
template_version_id uuid not null references template_versions (id) on delete cascade,
3+
name text not null,
4+
description text not null,
5+
type text not null,
6+
value text not null,
7+
default_value text not null,
8+
required boolean not null,
9+
sensitive boolean not null,
10+
unique (template_version_id, name)
11+
);
12+
13+
COMMENT ON COLUMN template_version_variables.name IS 'Variable name';
14+
COMMENT ON COLUMN template_version_variables.description IS 'Variable description';
15+
COMMENT ON COLUMN template_version_variables.type IS 'Variable type';
16+
COMMENT ON COLUMN template_version_variables.value IS 'Variable value';
17+
COMMENT ON COLUMN template_version_variables.default_value IS 'Variable default value';
18+
COMMENT ON COLUMN template_version_variables.required IS 'Is variable required?';
19+
COMMENT ON COLUMN template_version_variables.sensitive IS 'Is variable sensitive?';

coderd/database/models.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/unique_constraint.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/parse.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func (*server) Parse(request *proto.Parse_Request, stream proto.DRPCProvisioner_
2323
return xerrors.Errorf("load module: %s", formatDiagnostics(request.Directory, diags))
2424
}
2525

26+
fmt.Println(module.ProviderConfigs["coder"].Name)
27+
2628
// Sort variables by (filename, line) to make the ordering consistent
2729
variables := make([]*tfconfig.Variable, 0, len(module.Variables))
2830
for _, v := range module.Variables {

provisioner/terraform/parse_test.go

Lines changed: 141 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build linux
2-
31
package terraform_test
42

53
import (
@@ -26,11 +24,150 @@ func TestParse(t *testing.T) {
2624
// error containing this string before a Complete response is returned.
2725
ErrorContains string
2826
}{
27+
// {
28+
// Name: "single-variable",
29+
// Files: map[string]string{
30+
// "main.tf": `variable "A" {
31+
// description = "Testing!"
32+
// }`,
33+
// },
34+
// Response: &proto.Parse_Response{
35+
// Type: &proto.Parse_Response_Complete{
36+
// Complete: &proto.Parse_Complete{
37+
// ParameterSchemas: []*proto.ParameterSchema{{
38+
// Name: "A",
39+
// RedisplayValue: true,
40+
// AllowOverrideSource: true,
41+
// Description: "Testing!",
42+
// DefaultDestination: &proto.ParameterDestination{
43+
// Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
44+
// },
45+
// }},
46+
// },
47+
// },
48+
// },
49+
// },
50+
// {
51+
// Name: "default-variable-value",
52+
// Files: map[string]string{
53+
// "main.tf": `variable "A" {
54+
// default = "wow"
55+
// }`,
56+
// },
57+
// Response: &proto.Parse_Response{
58+
// Type: &proto.Parse_Response_Complete{
59+
// Complete: &proto.Parse_Complete{
60+
// ParameterSchemas: []*proto.ParameterSchema{{
61+
// Name: "A",
62+
// RedisplayValue: true,
63+
// AllowOverrideSource: true,
64+
// DefaultSource: &proto.ParameterSource{
65+
// Scheme: proto.ParameterSource_DATA,
66+
// Value: "wow",
67+
// },
68+
// DefaultDestination: &proto.ParameterDestination{
69+
// Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
70+
// },
71+
// }},
72+
// },
73+
// },
74+
// },
75+
// },
76+
// {
77+
// Name: "variable-validation",
78+
// Files: map[string]string{
79+
// "main.tf": `variable "A" {
80+
// validation {
81+
// condition = var.A == "value"
82+
// }
83+
// }`,
84+
// },
85+
// Response: &proto.Parse_Response{
86+
// Type: &proto.Parse_Response_Complete{
87+
// Complete: &proto.Parse_Complete{
88+
// ParameterSchemas: []*proto.ParameterSchema{{
89+
// Name: "A",
90+
// RedisplayValue: true,
91+
// ValidationCondition: `var.A == "value"`,
92+
// ValidationTypeSystem: proto.ParameterSchema_HCL,
93+
// AllowOverrideSource: true,
94+
// DefaultDestination: &proto.ParameterDestination{
95+
// Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
96+
// },
97+
// }},
98+
// },
99+
// },
100+
// },
101+
// },
102+
// {
103+
// Name: "bad-syntax",
104+
// Files: map[string]string{
105+
// "main.tf": "a;sd;ajsd;lajsd;lasjdf;a",
106+
// },
107+
// ErrorContains: `The ";" character is not valid.`,
108+
// },
109+
// {
110+
// Name: "multiple-variables",
111+
// Files: map[string]string{
112+
// "main1.tf": `variable "foo" { }
113+
// variable "bar" { }`,
114+
// "main2.tf": `variable "baz" { }
115+
// variable "quux" { }`,
116+
// },
117+
// Response: &proto.Parse_Response{
118+
// Type: &proto.Parse_Response_Complete{
119+
// Complete: &proto.Parse_Complete{
120+
// ParameterSchemas: []*proto.ParameterSchema{
121+
// {
122+
// Name: "foo",
123+
// RedisplayValue: true,
124+
// AllowOverrideSource: true,
125+
// Description: "",
126+
// DefaultDestination: &proto.ParameterDestination{
127+
// Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
128+
// },
129+
// },
130+
// {
131+
// Name: "bar",
132+
// RedisplayValue: true,
133+
// AllowOverrideSource: true,
134+
// Description: "",
135+
// DefaultDestination: &proto.ParameterDestination{
136+
// Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
137+
// },
138+
// },
139+
// {
140+
// Name: "baz",
141+
// RedisplayValue: true,
142+
// AllowOverrideSource: true,
143+
// Description: "",
144+
// DefaultDestination: &proto.ParameterDestination{
145+
// Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
146+
// },
147+
// },
148+
// {
149+
// Name: "quux",
150+
// RedisplayValue: true,
151+
// AllowOverrideSource: true,
152+
// Description: "",
153+
// DefaultDestination: &proto.ParameterDestination{
154+
// Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
155+
// },
156+
// },
157+
// },
158+
// },
159+
// },
160+
// },
161+
// },
29162
{
30-
Name: "single-variable",
163+
Name: "enable-managed-variables",
31164
Files: map[string]string{
32165
"main.tf": `variable "A" {
33166
description = "Testing!"
167+
}
168+
169+
provider "coder" {
170+
enable_managed_variables = "true"
34171
}`,
35172
},
36173
Response: &proto.Parse_Response{
@@ -48,118 +185,7 @@ func TestParse(t *testing.T) {
48185
},
49186
},
50187
},
51-
},
52-
{
53-
Name: "default-variable-value",
54-
Files: map[string]string{
55-
"main.tf": `variable "A" {
56-
default = "wow"
57-
}`,
58-
},
59-
Response: &proto.Parse_Response{
60-
Type: &proto.Parse_Response_Complete{
61-
Complete: &proto.Parse_Complete{
62-
ParameterSchemas: []*proto.ParameterSchema{{
63-
Name: "A",
64-
RedisplayValue: true,
65-
AllowOverrideSource: true,
66-
DefaultSource: &proto.ParameterSource{
67-
Scheme: proto.ParameterSource_DATA,
68-
Value: "wow",
69-
},
70-
DefaultDestination: &proto.ParameterDestination{
71-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
72-
},
73-
}},
74-
},
75-
},
76-
},
77-
},
78-
{
79-
Name: "variable-validation",
80-
Files: map[string]string{
81-
"main.tf": `variable "A" {
82-
validation {
83-
condition = var.A == "value"
84-
}
85-
}`,
86-
},
87-
Response: &proto.Parse_Response{
88-
Type: &proto.Parse_Response_Complete{
89-
Complete: &proto.Parse_Complete{
90-
ParameterSchemas: []*proto.ParameterSchema{{
91-
Name: "A",
92-
RedisplayValue: true,
93-
ValidationCondition: `var.A == "value"`,
94-
ValidationTypeSystem: proto.ParameterSchema_HCL,
95-
AllowOverrideSource: true,
96-
DefaultDestination: &proto.ParameterDestination{
97-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
98-
},
99-
}},
100-
},
101-
},
102-
},
103-
},
104-
{
105-
Name: "bad-syntax",
106-
Files: map[string]string{
107-
"main.tf": "a;sd;ajsd;lajsd;lasjdf;a",
108-
},
109-
ErrorContains: `The ";" character is not valid.`,
110-
},
111-
{
112-
Name: "multiple-variables",
113-
Files: map[string]string{
114-
"main1.tf": `variable "foo" { }
115-
variable "bar" { }`,
116-
"main2.tf": `variable "baz" { }
117-
variable "quux" { }`,
118-
},
119-
Response: &proto.Parse_Response{
120-
Type: &proto.Parse_Response_Complete{
121-
Complete: &proto.Parse_Complete{
122-
ParameterSchemas: []*proto.ParameterSchema{
123-
{
124-
Name: "foo",
125-
RedisplayValue: true,
126-
AllowOverrideSource: true,
127-
Description: "",
128-
DefaultDestination: &proto.ParameterDestination{
129-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
130-
},
131-
},
132-
{
133-
Name: "bar",
134-
RedisplayValue: true,
135-
AllowOverrideSource: true,
136-
Description: "",
137-
DefaultDestination: &proto.ParameterDestination{
138-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
139-
},
140-
},
141-
{
142-
Name: "baz",
143-
RedisplayValue: true,
144-
AllowOverrideSource: true,
145-
Description: "",
146-
DefaultDestination: &proto.ParameterDestination{
147-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
148-
},
149-
},
150-
{
151-
Name: "quux",
152-
RedisplayValue: true,
153-
AllowOverrideSource: true,
154-
Description: "",
155-
DefaultDestination: &proto.ParameterDestination{
156-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
157-
},
158-
},
159-
},
160-
},
161-
},
162-
},
188+
ErrorContains: "blah",
163189
},
164190
}
165191

0 commit comments

Comments
 (0)