Skip to content

Conversation

@Emyrk
Copy link
Member

@Emyrk Emyrk commented Dec 2, 2025

⚠️ Test fixes are in the next PR in the stack. The diff gets too complicated with the fixes in here.

Provisioner steps broken into smaller granular actions.

message Request {
  oneof type {
    Config config = 1;
    ParseRequest parse = 2;
+    InitRequest init = 3;
    PlanRequest plan = 4;
    ApplyRequest apply = 5;
+    GraphRequest graph = 6;
    CancelRequest cancel = 7;
  }
}

Changes

  • ExtractArchive moved to init request (was in configure)
  • Writing tfstate moved to plan (was in configure)
  • Moved most plan/apply outputs to GraphComplete

Why do this?

To remove the need to run terraform graph twice. This allows the provisionersdk to run a plan or apply without a graph. Running graph as it's own step at the end of a build/import.

Copy link
Member Author

Emyrk commented Dec 2, 2025

@Emyrk Emyrk changed the base branch from main to graphite-base/21064 December 2, 2025 18:23
@Emyrk Emyrk force-pushed the stevenmasley/terraform_al_la_carte_feat branch from 03de57d to 4a270f4 Compare December 2, 2025 18:23
@Emyrk Emyrk changed the base branch from graphite-base/21064 to stevenmasley/provisioner_script_shebangs December 2, 2025 18:23
@Emyrk Emyrk changed the title chore: distinct operations for provisioner's tf operations chore: distinct operations for provisioner's 'parse', 'init', 'plan', 'apply', 'graph' Dec 2, 2025
@Emyrk Emyrk changed the base branch from stevenmasley/provisioner_script_shebangs to graphite-base/21064 December 2, 2025 19:02
@Emyrk Emyrk force-pushed the stevenmasley/terraform_al_la_carte_feat branch from 4a270f4 to 24d4837 Compare December 2, 2025 19:02
@Emyrk Emyrk changed the base branch from graphite-base/21064 to stevenmasley/provisioner_script_race December 2, 2025 19:02
@Emyrk Emyrk force-pushed the stevenmasley/provisioner_script_race branch 2 times, most recently from b1f75f3 to eed2f12 Compare December 2, 2025 19:04
@Emyrk Emyrk force-pushed the stevenmasley/terraform_al_la_carte_feat branch from 24d4837 to 98ad5d4 Compare December 2, 2025 19:04
@Emyrk Emyrk force-pushed the stevenmasley/provisioner_script_race branch from eed2f12 to 56dffc9 Compare December 3, 2025 12:04
@Emyrk Emyrk force-pushed the stevenmasley/terraform_al_la_carte_feat branch 2 times, most recently from 834b599 to ec54ef3 Compare December 3, 2025 12:07
@Emyrk Emyrk force-pushed the stevenmasley/provisioner_script_race branch from 56dffc9 to cf94b5d Compare December 9, 2025 14:43
@Emyrk Emyrk force-pushed the stevenmasley/terraform_al_la_carte_feat branch from ec54ef3 to 4efa20c Compare December 9, 2025 14:43
@Emyrk Emyrk changed the base branch from stevenmasley/provisioner_script_race to graphite-base/21064 December 9, 2025 15:23
@Emyrk Emyrk force-pushed the graphite-base/21064 branch from cf94b5d to 6b8d466 Compare December 9, 2025 15:23
@Emyrk Emyrk force-pushed the stevenmasley/terraform_al_la_carte_feat branch from 4efa20c to 3c9ea20 Compare December 9, 2025 15:23
@Emyrk Emyrk changed the base branch from graphite-base/21064 to stevenmasley/provisioner_script_race December 9, 2025 15:23
@Emyrk Emyrk force-pushed the stevenmasley/terraform_al_la_carte_feat branch 2 times, most recently from 3b5d651 to 04bc86a Compare December 9, 2025 15:51
@Emyrk Emyrk marked this pull request as ready for review December 9, 2025 17:53
// TODO: These are defined as different, but can they be?
// Terraform downloads modules regardless of `count`, so this should be the same
StartModules: initResp.Modules,
StopModules: initResp.Modules,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were added for telemetry --- I think likely just a mistaken belief that they could be different, since we returned it on Plan and run 2 different plans for the different transitions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. This lives in the provisionerd proto. So I won't touch this in this PR

Issue made to track: #21206

Comment on lines -347 to -360
graphTimings.ingest(createGraphTimingsEvent(timingGraphComplete))

var moduleFiles []byte
// Skipping modules archiving is useful if the caller does not need it, eg during
// a workspace build. This removes some added costs of sending the modules
// payload back to coderd if coderd is just going to ignore it.
if !req.OmitModuleFiles {
moduleFiles, err = GetModulesArchive(os.DirFS(e.files.WorkDirectory()))
if err != nil {
// TODO: we probably want to persist this error or make it louder eventually
e.logger.Warn(ctx, "failed to archive terraform modules", slog.Error(err))
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the init step, where modules are downloaded.

Comment on lines -421 to -455
// planResources must only be called while the lock is held.
func (e *executor) planResources(ctx, killCtx context.Context, planfilePath string) (*State, *tfjson.Plan, error) {
ctx, span := e.server.startTrace(ctx, tracing.FuncName())
defer span.End()

plan, err := e.parsePlan(ctx, killCtx, planfilePath)
if err != nil {
return nil, nil, xerrors.Errorf("show terraform plan file: %w", err)
}

rawGraph, err := e.graph(ctx, killCtx)
if err != nil {
return nil, nil, xerrors.Errorf("graph: %w", err)
}
modules := []*tfjson.StateModule{}
if plan.PriorState != nil {
// 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.

filtered := onlyDataResources(*plan.PriorState.Values.RootModule)
modules = append(modules, &filtered)
}
modules = append(modules, plan.PlannedValues.RootModule)

state, err := ConvertState(ctx, modules, rawGraph, e.server.logger)
if err != nil {
return nil, nil, err
}

return state, plan, nil
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to graph

Comment on lines -605 to -609
// `terraform show` & `terraform graph`
state, err := e.stateResources(ctx, killCtx)
if err != nil {
return nil, err
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to graph

// TODO: These are defined as different, but can they be?
// Terraform downloads modules regardless of `count`, so this should be the same
StartModules: initResp.Modules,
StopModules: initResp.Modules,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. This lives in the provisionerd proto. So I won't touch this in this PR

Issue made to track: #21206

@Emyrk Emyrk force-pushed the stevenmasley/provisioner_script_race branch from 6b8d466 to f06c861 Compare December 12, 2025 13:45
@Emyrk Emyrk force-pushed the stevenmasley/terraform_al_la_carte_feat branch from 4ba2b34 to 9f2ddb8 Compare December 12, 2025 13:45
'parse', 'init', 'plan', 'apply', 'graph'
More granular provisioner options.
Quotas are not used in template imports, only builds
@Emyrk Emyrk force-pushed the stevenmasley/provisioner_script_race branch from f06c861 to c905ed3 Compare December 12, 2025 13:47
@Emyrk Emyrk force-pushed the stevenmasley/terraform_al_la_carte_feat branch from 9f2ddb8 to 077c0a7 Compare December 12, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants