| 37 | } |
| 38 | |
| 39 | func DynamicParameterTemplate(t *testing.T, client *codersdk.Client, org uuid.UUID, args DynamicParameterTemplateParams) (codersdk.Template, codersdk.TemplateVersion) { |
| 40 | t.Helper() |
| 41 | |
| 42 | // Start with main.tf |
| 43 | extraFiles := map[string][]byte{ |
| 44 | "main.tf": []byte(args.MainTF), |
| 45 | } |
| 46 | |
| 47 | // Add any additional files |
| 48 | for name, content := range args.ExtraFiles { |
| 49 | extraFiles[name] = content |
| 50 | } |
| 51 | |
| 52 | files := echo.WithExtraFiles(extraFiles) |
| 53 | files.ProvisionInit = []*proto.Response{{ |
| 54 | Type: &proto.Response_Init{ |
| 55 | Init: &proto.InitComplete{ |
| 56 | ModuleFiles: args.ModulesArchive, |
| 57 | }, |
| 58 | }, |
| 59 | }} |
| 60 | files.ProvisionPlan = []*proto.Response{{ |
| 61 | Type: &proto.Response_Plan{ |
| 62 | Plan: &proto.PlanComplete{ |
| 63 | Plan: args.Plan, |
| 64 | }, |
| 65 | }, |
| 66 | }} |
| 67 | files.ProvisionGraph = []*proto.Response{{ |
| 68 | Type: &proto.Response_Graph{ |
| 69 | Graph: &proto.GraphComplete{ |
| 70 | Parameters: args.StaticParams, |
| 71 | }, |
| 72 | }, |
| 73 | }} |
| 74 | |
| 75 | userVars := make([]codersdk.VariableValue, 0, len(args.Variables)) |
| 76 | parseVars := make([]*proto.TemplateVariable, 0, len(args.Variables)) |
| 77 | for _, argv := range args.Variables { |
| 78 | parseVars = append(parseVars, &proto.TemplateVariable{ |
| 79 | Name: argv.Name, |
| 80 | Description: argv.Description, |
| 81 | Type: argv.Type, |
| 82 | DefaultValue: argv.DefaultValue, |
| 83 | Required: argv.Required, |
| 84 | Sensitive: argv.Sensitive, |
| 85 | }) |
| 86 | |
| 87 | userVars = append(userVars, codersdk.VariableValue{ |
| 88 | Name: argv.Name, |
| 89 | Value: argv.Value, |
| 90 | }) |
| 91 | } |
| 92 | |
| 93 | files.Parse = []*proto.Response{{ |
| 94 | Type: &proto.Response_Parse{ |
| 95 | Parse: &proto.ParseComplete{ |
| 96 | TemplateVariables: parseVars, |