Skip to content

Commit

Permalink
fix: a TF breaking change to enable reusing cached providers (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkYuan committed Jul 4, 2024
1 parent 1ba096b commit db7f6f1
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions pkg/engine/runtime/terraform/tfops/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,27 @@ const (
)

const (
envLog = "TF_LOG"
envPluginCacheDir = "TF_PLUGIN_CACHE_DIR"
tfDebugLOG = "DEBUG"
envLogPath = "TF_LOG_PATH"
LockHCLFile = ".terraform.lock.hcl"
mainTFFile = "main.tf.json"
tfPlanFile = "plan.out"
tfStateFile = "terraform.tfstate"
tfProviderPrefix = "terraform-provider"
terraformD = ".terraform.d"
pluginCache = "plugin-cache"
envLog = "TF_LOG"
// According to this issue(https://github.com/hashicorp/terraform/issues/35345),
// the description of `TF_PLUGIN_CACHE_DIR` is out of date and won't work as we expected.
// we have to set TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE to ignore the dependency lock file to reuse the plugin cache.
envBreakDependencyLockFile = "TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE"
envPluginCacheDir = "TF_PLUGIN_CACHE_DIR"
tfDebugLOG = "DEBUG"
envLogPath = "TF_LOG_PATH"
LockHCLFile = ".terraform.lock.hcl"
mainTFFile = "main.tf.json"
tfPlanFile = "plan.out"
tfStateFile = "terraform.tfstate"
tfProviderPrefix = "terraform-provider"
terraformD = ".terraform.d"
pluginCache = "plugin-cache"
)

var envTFLog = fmt.Sprintf("%s=%s", envLog, tfDebugLOG)
var (
envTFLog = fmt.Sprintf("%s=%s", envLog, tfDebugLOG)
envPluginCacheBreakDependencyLockFile = fmt.Sprintf("%s=%s", envBreakDependencyLockFile, "true")
)

type WorkSpace struct {
resource *v1.Resource
Expand Down Expand Up @@ -230,7 +237,7 @@ func (w *WorkSpace) initEnvs() ([]string, error) {
if err != nil {
return nil, err
}
result := append(os.Environ(), envTFLog, providerCachePath, logPath)
result := append(os.Environ(), envTFLog, envPluginCacheBreakDependencyLockFile, providerCachePath, logPath)
return result, nil
}

Expand Down

0 comments on commit db7f6f1

Please sign in to comment.