Skip to content

Commit a450f90

Browse files
committed
Adjust provisionerd
1 parent a5aae3a commit a450f90

File tree

13 files changed

+704
-1644
lines changed

13 files changed

+704
-1644
lines changed

provisioner/echo/serve.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,6 @@ var (
7272
Complete: &proto.Provision_Complete{},
7373
},
7474
}}
75-
76-
ParameterSuccess = []*proto.ParameterSchema{
77-
{
78-
AllowOverrideSource: true,
79-
Name: ParameterExecKey,
80-
Description: "description 1",
81-
DefaultSource: &proto.ParameterSource{
82-
Scheme: proto.ParameterSource_DATA,
83-
Value: formatExecValue(successKey, ""),
84-
},
85-
DefaultDestination: &proto.ParameterDestination{
86-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
87-
},
88-
},
89-
}
9075
)
9176

9277
// Serve starts the echo provisioner.
@@ -151,22 +136,6 @@ func (e *echo) Provision(stream proto.DRPCProvisioner_ProvisionStream) error {
151136
return nil
152137
}
153138

154-
for _, param := range msg.GetPlan().GetParameterValues() {
155-
if param.Name == ParameterExecKey {
156-
toks := strings.Split(param.Value, "=")
157-
if len(toks) < 2 {
158-
break
159-
}
160-
161-
switch toks[0] {
162-
case errorKey:
163-
return xerrors.Errorf("returning error: %v", toks[1])
164-
default:
165-
// Do nothing
166-
}
167-
}
168-
}
169-
170139
for index := 0; ; index++ {
171140
var extension string
172141
if msg.GetPlan() != nil {

provisioner/echo/serve_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ func TestEcho(t *testing.T) {
4949
},
5050
}, {
5151
Type: &proto.Parse_Response_Complete{
52-
Complete: &proto.Parse_Complete{
53-
ParameterSchemas: []*proto.ParameterSchema{{
54-
Name: "parameter-schema",
55-
}},
56-
},
52+
Complete: &proto.Parse_Complete{},
5753
},
5854
}}
5955
data, err := echo.Tar(&echo.Responses{
@@ -69,8 +65,7 @@ func TestEcho(t *testing.T) {
6965
require.Equal(t, responses[0].GetLog().Output, log.GetLog().Output)
7066
complete, err := client.Recv()
7167
require.NoError(t, err)
72-
require.Equal(t, responses[1].GetComplete().ParameterSchemas[0].Name,
73-
complete.GetComplete().ParameterSchemas[0].Name)
68+
require.NotNil(t, complete)
7469
})
7570

7671
t.Run("Provision", func(t *testing.T) {

provisioner/terraform/parse.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ func (s *server) Parse(request *proto.Parse_Request, stream proto.DRPCProvisione
6464
return compareSourcePos(variables[i].Pos, variables[j].Pos)
6565
})
6666

67-
var parameters []*proto.ParameterSchema
6867
var templateVariables []*proto.TemplateVariable
6968

7069
useManagedVariables := flags != nil && flags[featureUseManagedVariables]
@@ -76,20 +75,10 @@ func (s *server) Parse(request *proto.Parse_Request, stream proto.DRPCProvisione
7675
}
7776
templateVariables = append(templateVariables, mv)
7877
}
79-
} else {
80-
for _, v := range variables {
81-
schema, err := convertVariableToParameter(v)
82-
if err != nil {
83-
return xerrors.Errorf("convert variable %q: %w", v.Name, err)
84-
}
85-
86-
parameters = append(parameters, schema)
87-
}
8878
}
8979
return stream.Send(&proto.Parse_Response{
9080
Type: &proto.Parse_Response_Complete{
9181
Complete: &proto.Parse_Complete{
92-
ParameterSchemas: parameters,
9382
TemplateVariables: templateVariables,
9483
},
9584
},
@@ -164,51 +153,6 @@ func parseFeatures(hclFilepath string) (map[string]bool, bool, hcl.Diagnostics)
164153
return flags, found, diags
165154
}
166155

167-
// Converts a Terraform variable to a provisioner parameter.
168-
func convertVariableToParameter(variable *tfconfig.Variable) (*proto.ParameterSchema, error) {
169-
schema := &proto.ParameterSchema{
170-
Name: variable.Name,
171-
Description: variable.Description,
172-
RedisplayValue: !variable.Sensitive,
173-
AllowOverrideSource: !variable.Sensitive,
174-
ValidationValueType: variable.Type,
175-
DefaultDestination: &proto.ParameterDestination{
176-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
177-
},
178-
}
179-
180-
if variable.Default != nil {
181-
defaultData, valid := variable.Default.(string)
182-
if !valid {
183-
defaultDataRaw, err := json.Marshal(variable.Default)
184-
if err != nil {
185-
return nil, xerrors.Errorf("parse variable %q default: %w", variable.Name, err)
186-
}
187-
defaultData = string(defaultDataRaw)
188-
}
189-
190-
schema.DefaultSource = &proto.ParameterSource{
191-
Scheme: proto.ParameterSource_DATA,
192-
Value: defaultData,
193-
}
194-
}
195-
196-
if len(variable.Validations) > 0 && variable.Validations[0].Condition != nil {
197-
// Terraform can contain multiple validation blocks, but it's used sparingly
198-
// from what it appears.
199-
validation := variable.Validations[0]
200-
filedata, err := os.ReadFile(variable.Pos.Filename)
201-
if err != nil {
202-
return nil, xerrors.Errorf("read file %q: %w", variable.Pos.Filename, err)
203-
}
204-
schema.ValidationCondition = string(filedata[validation.Condition.Range().Start.Byte:validation.Condition.Range().End.Byte])
205-
schema.ValidationError = validation.ErrorMessage
206-
schema.ValidationTypeSystem = proto.ParameterSchema_HCL
207-
}
208-
209-
return schema, nil
210-
}
211-
212156
// Converts a Terraform variable to a managed variable.
213157
func convertTerraformVariableToManagedVariable(variable *tfconfig.Variable) (*proto.TemplateVariable, error) {
214158
var defaultData string

provisioner/terraform/parse_test.go

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,7 @@ func TestParse(t *testing.T) {
3535
},
3636
Response: &proto.Parse_Response{
3737
Type: &proto.Parse_Response_Complete{
38-
Complete: &proto.Parse_Complete{
39-
ParameterSchemas: []*proto.ParameterSchema{{
40-
Name: "A",
41-
RedisplayValue: true,
42-
AllowOverrideSource: true,
43-
Description: "Testing!",
44-
DefaultDestination: &proto.ParameterDestination{
45-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
46-
},
47-
}},
48-
},
38+
Complete: &proto.Parse_Complete{},
4939
},
5040
},
5141
},
@@ -58,20 +48,7 @@ func TestParse(t *testing.T) {
5848
},
5949
Response: &proto.Parse_Response{
6050
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-
},
51+
Complete: &proto.Parse_Complete{},
7552
},
7653
},
7754
},
@@ -86,18 +63,7 @@ func TestParse(t *testing.T) {
8663
},
8764
Response: &proto.Parse_Response{
8865
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-
},
66+
Complete: &proto.Parse_Complete{},
10167
},
10268
},
10369
},
@@ -118,46 +84,7 @@ func TestParse(t *testing.T) {
11884
},
11985
Response: &proto.Parse_Response{
12086
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-
},
87+
Complete: &proto.Parse_Complete{},
16188
},
16289
},
16390
},

provisioner/terraform/provision.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (s *server) Provision(stream proto.DRPCProvisioner_ProvisionStream) error {
140140
return xerrors.Errorf("initialize terraform: %w", err)
141141
}
142142
s.logger.Debug(ctx, "ran initialization")
143-
env, err := provisionEnv(config, request.GetPlan().GetParameterValues(), request.GetPlan().GetRichParameterValues(), request.GetPlan().GetGitAuthProviders())
143+
env, err := provisionEnv(config, request.GetPlan().GetRichParameterValues(), request.GetPlan().GetGitAuthProviders())
144144
if err != nil {
145145
return err
146146
}
@@ -193,23 +193,13 @@ func (s *server) Provision(stream proto.DRPCProvisioner_ProvisionStream) error {
193193

194194
func planVars(plan *proto.Provision_Plan) ([]string, error) {
195195
vars := []string{}
196-
for _, param := range plan.ParameterValues {
197-
switch param.DestinationScheme {
198-
case proto.ParameterDestination_ENVIRONMENT_VARIABLE:
199-
continue
200-
case proto.ParameterDestination_PROVISIONER_VARIABLE:
201-
vars = append(vars, fmt.Sprintf("%s=%s", param.Name, param.Value))
202-
default:
203-
return nil, xerrors.Errorf("unsupported parameter type %q for %q", param.DestinationScheme, param.Name)
204-
}
205-
}
206196
for _, variable := range plan.VariableValues {
207197
vars = append(vars, fmt.Sprintf("%s=%s", variable.Name, variable.Value))
208198
}
209199
return vars, nil
210200
}
211201

212-
func provisionEnv(config *proto.Provision_Config, params []*proto.ParameterValue, richParams []*proto.RichParameterValue, gitAuth []*proto.GitAuthProvider) ([]string, error) {
202+
func provisionEnv(config *proto.Provision_Config, richParams []*proto.RichParameterValue, gitAuth []*proto.GitAuthProvider) ([]string, error) {
213203
env := safeEnviron()
214204
env = append(env,
215205
"CODER_AGENT_URL="+config.Metadata.CoderUrl,
@@ -225,16 +215,6 @@ func provisionEnv(config *proto.Provision_Config, params []*proto.ParameterValue
225215
for key, value := range provisionersdk.AgentScriptEnv() {
226216
env = append(env, key+"="+value)
227217
}
228-
for _, param := range params {
229-
switch param.DestinationScheme {
230-
case proto.ParameterDestination_ENVIRONMENT_VARIABLE:
231-
env = append(env, fmt.Sprintf("%s=%s", param.Name, param.Value))
232-
case proto.ParameterDestination_PROVISIONER_VARIABLE:
233-
continue
234-
default:
235-
return nil, xerrors.Errorf("unsupported parameter type %q for %q", param.DestinationScheme, param.Name)
236-
}
237-
}
238218
for _, param := range richParams {
239219
env = append(env, provider.ParameterEnvironmentVariable(param.Name)+"="+param.Value)
240220
}

provisioner/terraform/provision_test.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,6 @@ func TestProvision(t *testing.T) {
203203
ExpectLogContains string
204204
Apply bool
205205
}{
206-
{
207-
Name: "single-variable",
208-
Files: map[string]string{
209-
"main.tf": `variable "A" {
210-
description = "Testing!"
211-
}`,
212-
},
213-
Request: &proto.Provision_Plan{
214-
ParameterValues: []*proto.ParameterValue{{
215-
DestinationScheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
216-
Name: "A",
217-
Value: "example",
218-
}},
219-
},
220-
Response: &proto.Provision_Response{
221-
Type: &proto.Provision_Response_Complete{
222-
Complete: &proto.Provision_Complete{},
223-
},
224-
},
225-
Apply: true,
226-
},
227206
{
228207
Name: "missing-variable",
229208
Files: map[string]string{
@@ -305,22 +284,6 @@ func TestProvision(t *testing.T) {
305284
},
306285
ExpectLogContains: "nothing to do",
307286
},
308-
{
309-
Name: "unsupported-parameter-scheme",
310-
Files: map[string]string{
311-
"main.tf": "",
312-
},
313-
Request: &proto.Provision_Plan{
314-
ParameterValues: []*proto.ParameterValue{
315-
{
316-
DestinationScheme: 88,
317-
Name: "UNSUPPORTED",
318-
Value: "sadface",
319-
},
320-
},
321-
},
322-
ErrorContains: "unsupported parameter type",
323-
},
324287
{
325288
Name: "rich-parameter-with-value",
326289
Files: map[string]string{
@@ -462,7 +425,6 @@ func TestProvision(t *testing.T) {
462425
if planRequest.GetPlan().GetConfig() == nil {
463426
planRequest.GetPlan().Config = &proto.Provision_Config{}
464427
}
465-
planRequest.GetPlan().ParameterValues = testCase.Request.ParameterValues
466428
planRequest.GetPlan().RichParameterValues = testCase.Request.RichParameterValues
467429
planRequest.GetPlan().GitAuthProviders = testCase.Request.GitAuthProviders
468430
if testCase.Request.Config != nil {

0 commit comments

Comments
 (0)