MCPcopy Index your code
hub / github.com/coder/coder / WriteTFCliConfig

Function WriteTFCliConfig

testutil/terraform_cache.go:67–86  ·  view source on GitHub ↗

WriteTFCliConfig writes a Terraform CLI config file (`terraform.rc`) in `dir` to enforce using the local provider mirror. This blocks network access for providers, forcing Terraform to use only what's cached in `dir`. Returns the path to the generated config file.

(t *testing.T, dir string)

Source from the content-addressed store, hash-verified

65// This blocks network access for providers, forcing Terraform to use only what's cached in `dir`.
66// Returns the path to the generated config file.
67func WriteTFCliConfig(t *testing.T, dir string) string {
68 t.Helper()
69
70 cliConfigPath := filepath.Join(dir, terraformConfigFileName)
71 require.NoError(t, os.MkdirAll(filepath.Dir(cliConfigPath), 0o700))
72
73 content := fmt.Sprintf(`
74 provider_installation {
75 filesystem_mirror {
76 path = "%s"
77 include = ["*/*"]
78 }
79 direct {
80 exclude = ["*/*"]
81 }
82 }
83 `, filepath.Join(dir, cacheProvidersDirName))
84 require.NoError(t, os.WriteFile(cliConfigPath, []byte(content), 0o600))
85 return cliConfigPath
86}
87
88func runCmd(t *testing.T, dir string, args ...string) {
89 t.Helper()

Callers 1

CacheTFProvidersFunction · 0.85

Calls 3

MkdirAllMethod · 0.80
HelperMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected