| 67 | func (*staticRender) Close() {} |
| 68 | |
| 69 | func TemplateVersionParameter(it database.TemplateVersionParameter) previewtypes.Parameter { |
| 70 | param := previewtypes.Parameter{ |
| 71 | ParameterData: previewtypes.ParameterData{ |
| 72 | Name: it.Name, |
| 73 | DisplayName: it.DisplayName, |
| 74 | Description: it.Description, |
| 75 | Type: previewtypes.ParameterType(it.Type), |
| 76 | FormType: provider.ParameterFormType(it.FormType), |
| 77 | Styling: previewtypes.ParameterStyling{}, |
| 78 | Mutable: it.Mutable, |
| 79 | DefaultValue: previewtypes.StringLiteral(it.DefaultValue), |
| 80 | Icon: it.Icon, |
| 81 | Options: make([]*previewtypes.ParameterOption, 0), |
| 82 | Validations: make([]*previewtypes.ParameterValidation, 0), |
| 83 | Required: it.Required, |
| 84 | Order: int64(it.DisplayOrder), |
| 85 | Ephemeral: it.Ephemeral, |
| 86 | Source: nil, |
| 87 | }, |
| 88 | // Always use the default, since we used to assume the empty string |
| 89 | Value: previewtypes.StringLiteral(it.DefaultValue), |
| 90 | Diagnostics: make(previewtypes.Diagnostics, 0), |
| 91 | } |
| 92 | |
| 93 | if it.ValidationError != "" || it.ValidationRegex != "" || it.ValidationMonotonic != "" { |
| 94 | var reg *string |
| 95 | if it.ValidationRegex != "" { |
| 96 | reg = ptr.Ref(it.ValidationRegex) |
| 97 | } |
| 98 | |
| 99 | var vMin *int64 |
| 100 | if it.ValidationMin.Valid { |
| 101 | vMin = ptr.Ref(int64(it.ValidationMin.Int32)) |
| 102 | } |
| 103 | |
| 104 | var vMax *int64 |
| 105 | if it.ValidationMax.Valid { |
| 106 | vMax = ptr.Ref(int64(it.ValidationMax.Int32)) |
| 107 | } |
| 108 | |
| 109 | var monotonic *string |
| 110 | if it.ValidationMonotonic != "" { |
| 111 | monotonic = ptr.Ref(it.ValidationMonotonic) |
| 112 | } |
| 113 | |
| 114 | param.Validations = append(param.Validations, &previewtypes.ParameterValidation{ |
| 115 | Error: it.ValidationError, |
| 116 | Regex: reg, |
| 117 | Min: vMin, |
| 118 | Max: vMax, |
| 119 | Monotonic: monotonic, |
| 120 | }) |
| 121 | } |
| 122 | |
| 123 | var protoOptions []*sdkproto.RichParameterOption |
| 124 | err := json.Unmarshal(it.Options, &protoOptions) |
| 125 | if err != nil { |
| 126 | param.Diagnostics = append(param.Diagnostics, &hcl.Diagnostic{ |