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:
Kyle Carberry
2022-01-29 17:45:42 -06:00
committed by GitHub
parent b503c8b099
commit b3c5bb3576
9 changed files with 990 additions and 212 deletions
+9 -2
View File
@@ -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 {
+9 -2
View File
@@ -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",
},
}},
},
}, {
+15 -2
View File
@@ -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)
+3 -2
View File
@@ -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{},