fluxcd/terraform-provider-flux

[Bug]: Embedded manifests fails on Windows when TMP folder is on a different drive to local

Opened this issue · 0 comments

Describe the bug

Attempting to create a new bootstrap resource following e.g. examples/github-via-ssh, on Windows (11) where my TF files are on a different drive (V:) to my TMP folder (C:), fails with an error

Steps to reproduce

On a Windows system with more than one drive configured:

  1. Determine the location of the default temp directory, e.g. $env:TMP in PowerShell
  2. Create a new folder on a different drive to the temp directory, and copy the github-via-ssh example in there, and configure the variables
  3. Run terraform/tofu apply

Observe the error, e.g.:

flux_bootstrap_git.this: Creating...
╷
│ Error: Bootstrap run error
│
│   with flux_bootstrap_git.this,
│   on main.tf line 63, in resource "flux_bootstrap_git" "this":
│   63: resource "flux_bootstrap_git" "this" {
│
│ component manifest generation failed: Rel: can't make C:\Users\XXXX\AppData\Local\Temp\flux-manifests-1341206813
│ relative to V:\MyProject\tofu

Expected behavior

For the flux_bootstrap_git resource to be created successfully

Screenshots and recordings

No response

Terraform and provider versions

OpenTofu v1.8.0
on windows_amd64
+ provider registry.opentofu.org/fluxcd/flux v1.3.0
+ provider registry.opentofu.org/hashicorp/tls v4.0.5
+ provider registry.opentofu.org/integrations/github v6.2.3
+ provider registry.opentofu.org/tehcyx/kind v0.5.1

Terraform provider configurations

provider "flux" {
kubernetes = {
host = kind_cluster.this.endpoint
client_certificate = kind_cluster.this.client_certificate
client_key = kind_cluster.this.client_key
cluster_ca_certificate = kind_cluster.this.cluster_ca_certificate
}
git = {
url = "https://github.com/${var.github_org}/${var.github_repository}.git"
http = {
username = "git" # This can be any string when using a personal access token
password = var.github_token
}
}
}

provider "github" {
owner = var.github_org
token = var.github_token
}

provider "kind" {}

flux_bootstrap_git resource

resource "flux_bootstrap_git" "this" {
depends_on = [github_repository_deploy_key.this]

embedded_manifests = true
path = "clusters/my-cluster"
}

Flux version

v2.3.0

Additional context

I think the source of the problem is that in:

tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-")

passing "" as the first parameter ultimately causes Go to use the os.TempDir function (https://pkg.go.dev/os#TempDir)

A workaround is to set TMP to a folder on the same drive as the project, e.g. $env:TMP = 'V:\Temp' - this causes the apply command to complete successfully.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Would you like to implement a fix?

None