How to configure Terraform provider with a Terraform generated file as a configuration value?

386 Views Asked by At

The Helm provider in principle can be configured as

provider "helm" {
  kubernetes {
    config_path = local_sensitive_file.kubeconfig.filename
  }
}

resource "local_sensitive_file" "kubeconfig" {
    content_base64  = linode_lke_cluster.this.kubeconfig
    filename = "${path.module}/kubeconfig"
}

The above works for an empty state file, but terraform plan fails when the state file already exists.

Error: Kubernetes cluster unreachable: stat ./kubeconfig: no such file or directory

The issue is that initially the file does not exist. It would be created by Terraform, once it reaches out to (in this case) linode_lke_cluster.this resource.

The Terraform docs says that

You can use expressions in the values of these configuration arguments, but can only reference values that are known before the configuration is applied. This means you can safely reference input variables, but not attributes exported by resources (with an exception for resource arguments that are specified directly in the configuration).

The filename needed for the provider is already known. Thus we are good with the docs. Still, as the file does not exist, the terraform plan command fails.

How can I work around this? Is this a bug that would need to be reported?

0

There are 0 best solutions below