Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e326c4

Browse files
committed
terraform: make plugin cache cleanup configurable via env vars\n\n- Replace hard-coded 30d retention with configurable var\n- Read env in provisioner Serve():\n - CODER_TERRAFORM_PLUGIN_CLEANUP (default true)\n - CODER_TERRAFORM_PLUGIN_RETENTION (e.g. 720h)\n- Guard cleanup call with toggle\n- Update docs: speed-up-templates to describe settings\n\nCo-authored-by: angrycub <464492+angrycub@users.noreply.github.com>
1 parentff930ad commit6e326c4

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

‎docs/tutorials/best-practices/speed-up-templates.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,15 @@ provider versions.
159159

160160
###Cache directory
161161

162-
Coder will instruct Terraform to cache its downloaded providers in the
163-
configured[`CODER_CACHE_DIRECTORY`](../../reference/cli/server.md#--cache-dir)
164-
directory.
162+
Coder will instruct Terraform to cache its downloaded providers in the configured[`CODER_CACHE_DIRECTORY`](../../reference/cli/server.md#--cache-dir) directory.
165163

166-
Ensure that this directory is set to a location on disk which will persist
167-
across restarts of Coder or
168-
[external provisioners](../../admin/provisioners/index.md), if you're using them.
164+
Ensure that this directory is set to a location on disk which will persist across restarts of Coder or[external provisioners](../../admin/provisioners/index.md), if you're using them.
165+
166+
####Cache cleanup configuration
167+
168+
Provisioner cache cleanup can be controlled at runtime via environment variables (on both built-in and external provisioners):
169+
170+
-`CODER_TERRAFORM_PLUGIN_CLEANUP` (default`true`): enable or disable cleanup.
171+
-`CODER_TERRAFORM_PLUGIN_RETENTION` (default`720h`): age threshold for considering a provider plugin stale, parsed with Go's`time.ParseDuration` (example:`720h`~30 days).
172+
173+
If unset, cleanup runs with a default 30-day retention.

‎provisioner/terraform/provision.go‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import (
2424
"github.com/coder/coder/v2/provisionersdk/proto"
2525
)
2626

27-
conststaleTerraformPluginRetention=30*24*time.Hour
27+
varstaleTerraformPluginRetention=30*24*time.Hour
28+
29+
// terraformPluginCleanupEnabled controls whether plugin cache cleanup runs.
30+
// Defaults to true.
31+
varterraformPluginCleanupEnabled=true
2832

2933
func (s*server)setupContexts(parent context.Context,canceledOrComplete<-chanstruct{}) (
3034
ctx context.Context,cancelfunc(),killCtx context.Context,killfunc(),
@@ -100,9 +104,11 @@ func (s *server) Plan(
100104
}
101105
}
102106

103-
err:=CleanStaleTerraformPlugins(sess.Context(),s.cachePath,afero.NewOsFs(),time.Now(),s.logger)
104-
iferr!=nil {
105-
returnprovisionersdk.PlanErrorf("unable to clean stale Terraform plugins: %s",err)
107+
ifterraformPluginCleanupEnabled {
108+
err:=CleanStaleTerraformPlugins(sess.Context(),s.cachePath,afero.NewOsFs(),time.Now(),s.logger)
109+
iferr!=nil {
110+
returnprovisionersdk.PlanErrorf("unable to clean stale Terraform plugins: %s",err)
111+
}
106112
}
107113

108114
s.logger.Debug(ctx,"running initialization")
@@ -112,6 +118,7 @@ func (s *server) Plan(
112118
initTimings:=newTimingAggregator(database.ProvisionerJobTimingStageInit)
113119
initTimings.ingest(createInitTimingsEvent(timingInitStart))
114120

121+
varerrerror
115122
err=e.init(ctx,killCtx,sess)
116123
iferr!=nil {
117124
initTimings.ingest(createInitTimingsEvent(timingInitErrored))

‎provisioner/terraform/serve.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package terraform
33
import (
44
"context"
55
"errors"
6+
"os"
67
"path/filepath"
8+
"strconv"
9+
"strings"
710
"sync"
811
"time"
912

@@ -86,6 +89,17 @@ func systemBinary(ctx context.Context) (*systemBinaryDetails, error) {
8689

8790
// Serve starts a dRPC server on the provided transport speaking Terraform provisioner.
8891
funcServe(ctx context.Context,options*ServeOptions)error {
92+
// Optional environment overrides for plugin cache cleanup behavior.
93+
ifv,ok:=os.LookupEnv("CODER_TERRAFORM_PLUGIN_CLEANUP");ok {
94+
ifb,err:=strconv.ParseBool(strings.TrimSpace(v));err==nil {
95+
terraformPluginCleanupEnabled=b
96+
}
97+
}
98+
ifv,ok:=os.LookupEnv("CODER_TERRAFORM_PLUGIN_RETENTION");ok {
99+
ifd,err:=time.ParseDuration(strings.TrimSpace(v));err==nil {
100+
staleTerraformPluginRetention=d
101+
}
102+
}
89103
ifoptions.BinaryPath=="" {
90104
binaryDetails,err:=systemBinary(ctx)
91105
iferr!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp