revive:disable-next-line:flag-parameter
(ctx, killCtx context.Context, env, vars []string, logr logSink, req *proto.PlanRequest)
| 289 | |
| 290 | // revive:disable-next-line:flag-parameter |
| 291 | func (e *executor) plan(ctx, killCtx context.Context, env, vars []string, logr logSink, req *proto.PlanRequest) (*proto.PlanComplete, error) { |
| 292 | ctx, span := e.server.startTrace(ctx, tracing.FuncName()) |
| 293 | defer span.End() |
| 294 | |
| 295 | e.mut.Lock() |
| 296 | defer e.mut.Unlock() |
| 297 | |
| 298 | metadata := req.Metadata |
| 299 | |
| 300 | planfilePath := e.files.PlanFilePath() |
| 301 | args := []string{ |
| 302 | "plan", |
| 303 | "-no-color", |
| 304 | "-input=false", |
| 305 | "-json", |
| 306 | "-refresh=true", |
| 307 | "-out=" + planfilePath, |
| 308 | } |
| 309 | destroy := metadata.GetWorkspaceTransition() == proto.WorkspaceTransition_DESTROY |
| 310 | if destroy { |
| 311 | args = append(args, "-destroy") |
| 312 | } |
| 313 | for _, variable := range vars { |
| 314 | args = append(args, "-var", variable) |
| 315 | } |
| 316 | |
| 317 | outWriter, doneOut := e.provisionLogWriter(logr) |
| 318 | errWriter, doneErr := logWriter(logr, proto.LogLevel_ERROR) |
| 319 | defer func() { |
| 320 | _ = outWriter.Close() |
| 321 | _ = errWriter.Close() |
| 322 | <-doneOut |
| 323 | <-doneErr |
| 324 | }() |
| 325 | |
| 326 | err := e.execWriteOutput(ctx, killCtx, args, env, outWriter, errWriter) |
| 327 | if err != nil { |
| 328 | return nil, xerrors.Errorf("terraform plan: %w", err) |
| 329 | } |
| 330 | |
| 331 | plan, err := e.parsePlan(ctx, killCtx, planfilePath) |
| 332 | if err != nil { |
| 333 | return nil, xerrors.Errorf("show terraform plan file: %w", err) |
| 334 | } |
| 335 | |
| 336 | planJSON, err := json.Marshal(plan) |
| 337 | if err != nil { |
| 338 | return nil, xerrors.Errorf("marshal plan: %w", err) |
| 339 | } |
| 340 | |
| 341 | isPrebuildClaimAttempt := !destroy && |
| 342 | metadata.GetPrebuiltWorkspaceBuildStage().IsPrebuiltWorkspaceClaim() |
| 343 | if isPrebuildClaimAttempt { |
| 344 | // When a prebuild claim attempt is made, log a warning if a |
| 345 | // resource is due to be replaced, since this will obviate the |
| 346 | // point of prebuilding if the expensive resource is replaced |
| 347 | // once claimed! |
| 348 | if hasResourceReplacement(plan) { |
no test coverage detected