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)
| 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. |
| 67 | func 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 | |
| 88 | func runCmd(t *testing.T, dir string, args ...string) { |
| 89 | t.Helper() |
no test coverage detected