Skip to content

fix: correctly assess quota for stopped resources #9201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ func newProvisionerDaemon(
Listener: terraformServer,
},
CachePath: tfDir,
Logger: logger,
Logger: logger.Named("terraform"),
Tracer: tracer,
})
if err != nil && !xerrors.Is(err, context.Canceled) {
Expand Down
29 changes: 28 additions & 1 deletion provisioner/terraform/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (e *executor) execWriteOutput(ctx, killCtx context.Context, args, env []str
cmd.Stdout = syncWriter{mut, stdOutWriter}
cmd.Stderr = syncWriter{mut, stdErrWriter}

e.server.logger.Debug(ctx, "executing terraform command",
slog.F("binary_path", e.binaryPath),
slog.F("args", args),
)
err = cmd.Start()
if err != nil {
return err
Expand Down Expand Up @@ -260,6 +264,20 @@ func (e *executor) plan(ctx, killCtx context.Context, env, vars []string, logr l
}, nil
}

func onlyDataResources(sm *tfjson.StateModule) *tfjson.StateModule {
sm2 := *sm
sm2.Resources = make([]*tfjson.StateResource, 0, len(sm.Resources))
for _, r := range sm.Resources {
if r.Mode == "data" {
sm2.Resources = append(sm2.Resources, r)
}
}
for _, c := range sm.ChildModules {
sm2.ChildModules = append(sm2.ChildModules, onlyDataResources(c))
}
return &sm2
}

// planResources must only be called while the lock is held.
func (e *executor) planResources(ctx, killCtx context.Context, planfilePath string) (*State, error) {
ctx, span := e.server.startTrace(ctx, tracing.FuncName())
Expand All @@ -276,7 +294,16 @@ func (e *executor) planResources(ctx, killCtx context.Context, planfilePath stri
}
modules := []*tfjson.StateModule{}
if plan.PriorState != nil {
modules = append(modules, plan.PriorState.Values.RootModule)
// We need the data resources for rich parameters. For some reason, they
// only show up in the PriorState.
//
// We don't want all prior resources, because Quotas (and
// future features) would never know which resources are getting
// deleted by a stop.
modules = append(
modules,
onlyDataResources(plan.PriorState.Values.RootModule),
)
}
modules = append(modules, plan.PlannedValues.RootModule)

Expand Down