@@ -101,14 +101,14 @@ func (api *API) handleDynamicParameters(rw http.ResponseWriter, r *http.Request,
101101
102102// Add the file first. Calling `Release` if it fails is a no-op, so this is safe.
103103templateFS ,err := api .FileCache .Acquire (fileCtx ,fileID )
104- defer api .FileCache .Release (fileID )
105104if err != nil {
106105httpapi .Write (ctx ,rw ,http .StatusNotFound , codersdk.Response {
107106Message :"Internal error fetching template version Terraform." ,
108107Detail :err .Error (),
109108})
110109return
111110}
111+ defer api .FileCache .Release (fileID )
112112
113113// Having the Terraform plan available for the evaluation engine is helpful
114114// for populating values from data blocks, but isn't strictly required. If
@@ -120,14 +120,14 @@ func (api *API) handleDynamicParameters(rw http.ResponseWriter, r *http.Request,
120120
121121if tf .CachedModuleFiles .Valid {
122122moduleFilesFS ,err := api .FileCache .Acquire (fileCtx ,tf .CachedModuleFiles .UUID )
123- defer api .FileCache .Release (tf .CachedModuleFiles .UUID )
124123if err != nil {
125124httpapi .Write (ctx ,rw ,http .StatusNotFound , codersdk.Response {
126125Message :"Internal error fetching Terraform modules." ,
127126Detail :err .Error (),
128127})
129128return
130129}
130+ defer api .FileCache .Release (tf .CachedModuleFiles .UUID )
131131
132132templateFS = files .NewOverlayFS (templateFS , []files.Overlay {{Path :".terraform/modules" ,FS :moduleFilesFS }})
133133}