Skip to content

fix: reduce size of terraform modules archive #17749

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 12 commits into from
May 12, 2025
Prev Previous commit
Next Next commit
better size check
  • Loading branch information
aslilac committed May 12, 2025
commit 00cc35f1cdd982ff23d5323adbc288993b32b243
13 changes: 11 additions & 2 deletions provisioner/terraform/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import (
tfjson "github.com/hashicorp/terraform-json"
"go.opentelemetry.io/otel/attribute"
"golang.org/x/xerrors"
protobuf "google.golang.org/protobuf/proto"

"cdr.dev/slog"

"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/tracing"
"github.com/coder/coder/v2/codersdk/drpcsdk"
"github.com/coder/coder/v2/provisionersdk/proto"
)

Expand Down Expand Up @@ -313,15 +315,22 @@ func (e *executor) plan(ctx, killCtx context.Context, env, vars []string, logr l
e.logger.Warn(ctx, "failed to archive terraform modules", slog.Error(err))
}

return &proto.PlanComplete{
msg := &proto.PlanComplete{
Parameters: state.Parameters,
Resources: state.Resources,
ExternalAuthProviders: state.ExternalAuthProviders,
Timings: append(e.timings.aggregate(), graphTimings.aggregate()...),
Presets: state.Presets,
Plan: plan,
ModuleFiles: moduleFiles,
}, nil
}

if protobuf.Size(msg) > drpcsdk.MaxMessageSize {
e.logger.Warn(ctx, "cannot persist terraform modules, message payload too big", slog.F("archive_size", len(msg.ModuleFiles)))
msg.ModuleFiles = nil
}

return msg, nil
}

func onlyDataResources(sm tfjson.StateModule) tfjson.StateModule {
Expand Down
5 changes: 0 additions & 5 deletions provisioner/terraform/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"golang.org/x/xerrors"

"github.com/coder/coder/v2/codersdk/drpcsdk"
"github.com/coder/coder/v2/provisionersdk/proto"
)

Expand Down Expand Up @@ -147,9 +146,5 @@ func getModulesArchive(root fs.FS) ([]byte, error) {
if empty {
return []byte{}, nil
}

if b.Len() > drpcsdk.MaxMessageSize {
return nil, xerrors.New("modules archive exceeds max message size, modules will not be persisted")
}
return b.Bytes(), nil
}
Loading