mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Compute project build parameters (#82)
* feat: Add parameter and jobs database schema This modifies a prior migration which is typically forbidden, but because we're pre-production deployment I felt grouping would be helpful to future contributors. This adds database functions that are required for the provisioner daemon and job queue logic. * feat: Compute project build parameters Adds a projectparameter package to compute build-time project values for a provided scope. This package will be used to return which variables are being used for a build, and can visually indicate the hierarchy to a user. * Fix terraform provisioner * Improve naming, abstract inject to consume scope * Run CI on all branches
This commit is contained in:
@@ -37,7 +37,7 @@ func convertVariableToParameter(variable *tfconfig.Variable) (*proto.ParameterSc
|
||||
schema := &proto.ParameterSchema{
|
||||
Name: variable.Name,
|
||||
Description: variable.Description,
|
||||
Sensitive: variable.Sensitive,
|
||||
RedisplayValue: variable.Sensitive,
|
||||
ValidationValueType: variable.Type,
|
||||
}
|
||||
|
||||
@@ -46,7 +46,14 @@ func convertVariableToParameter(variable *tfconfig.Variable) (*proto.ParameterSc
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("parse variable %q default: %w", variable.Name, err)
|
||||
}
|
||||
schema.DefaultValue = string(defaultData)
|
||||
schema.DefaultSource = &proto.ParameterSource{
|
||||
Scheme: proto.ParameterSource_DATA,
|
||||
Value: string(defaultData),
|
||||
}
|
||||
schema.DefaultDestination = &proto.ParameterDestination{
|
||||
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
|
||||
Value: variable.Name,
|
||||
}
|
||||
}
|
||||
|
||||
if len(variable.Validations) > 0 && variable.Validations[0].Condition != nil {
|
||||
|
||||
@@ -63,8 +63,15 @@ func TestParse(t *testing.T) {
|
||||
},
|
||||
Response: &proto.Parse_Response{
|
||||
ParameterSchemas: []*proto.ParameterSchema{{
|
||||
Name: "A",
|
||||
DefaultValue: "\"wow\"",
|
||||
Name: "A",
|
||||
DefaultSource: &proto.ParameterSource{
|
||||
Scheme: proto.ParameterSource_DATA,
|
||||
Value: "\"wow\"",
|
||||
},
|
||||
DefaultDestination: &proto.ParameterDestination{
|
||||
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
|
||||
Value: "A",
|
||||
},
|
||||
}},
|
||||
},
|
||||
}, {
|
||||
|
||||
@@ -37,10 +37,23 @@ func (t *terraform) Provision(ctx context.Context, request *proto.Provision_Requ
|
||||
return nil, xerrors.Errorf("initialize terraform: %w", err)
|
||||
}
|
||||
|
||||
env := map[string]string{}
|
||||
options := make([]tfexec.ApplyOption, 0)
|
||||
for _, params := range request.ParameterValues {
|
||||
options = append(options, tfexec.Var(fmt.Sprintf("%s=%s", params.Name, params.Value)))
|
||||
for _, param := range request.ParameterValues {
|
||||
switch param.DestinationScheme {
|
||||
case proto.ParameterDestination_ENVIRONMENT_VARIABLE:
|
||||
env[param.Name] = param.Value
|
||||
case proto.ParameterDestination_PROVISIONER_VARIABLE:
|
||||
options = append(options, tfexec.Var(fmt.Sprintf("%s=%s", param.Name, param.Value)))
|
||||
default:
|
||||
return nil, xerrors.Errorf("unsupported parameter type %q for %q", param.DestinationScheme, param.Name)
|
||||
}
|
||||
}
|
||||
err = terraform.SetEnv(env)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("apply environment variables: %w", err)
|
||||
}
|
||||
|
||||
err = terraform.Apply(ctx, options...)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("apply terraform: %w", err)
|
||||
|
||||
@@ -63,8 +63,9 @@ func TestProvision(t *testing.T) {
|
||||
},
|
||||
Request: &proto.Provision_Request{
|
||||
ParameterValues: []*proto.ParameterValue{{
|
||||
Name: "A",
|
||||
Value: "example",
|
||||
DestinationScheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
|
||||
Name: "A",
|
||||
Value: "example",
|
||||
}},
|
||||
},
|
||||
Response: &proto.Provision_Response{},
|
||||
|
||||
Reference in New Issue
Block a user