cloud-native-toolkit / terraform-k8s-olm

Terraform module to install Operator Lifecycle Manager on the cluster
6 stars 6 forks source link

cluster_config_file does not work with ~ or $HOME #13

Closed martintietz closed 2 years ago

martintietz commented 2 years ago

Unfortunately the example from the README does not work for me. I get an error when I try to use cluster_config_file = "~/.kube/db2u-config":

module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager: Creating...
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager: Provisioning with 'local-exec'...
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager (local-exec): Executing: ["/bin/sh" "-c" ".terraform/modules/dev_software_olm_release/scripts/deploy-olm.sh v0.20.0"]
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager (local-exec): CLUSTER_TYPE: kubernetes
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager (local-exec): W0204 15:37:49.822295   31842 loader.go:221] Config not found: ~/.kube/db2u-config
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager (local-exec): The connection to the server localhost:8080 was refused - did you specify the right host or port?
╷
│ Error: local-exec provisioner error
│ 
│   with module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager,
│   on .terraform/modules/dev_software_olm_release/main.tf line 15, in resource "null_resource" "deploy_operator_lifecycle_manager":
│   15:   provisioner "local-exec" {
│ 
│ Error running command '.terraform/modules/dev_software_olm_release/scripts/deploy-olm.sh v0.20.0': exit status 1. Output: CLUSTER_TYPE: kubernetes
│ W0204 15:37:49.822295   31842 loader.go:221] Config not found: ~/.kube/db2u-config
│ The connection to the server localhost:8080 was refused - did you specify the right host or port?

The same happens for cluster_config_file = "$HOME/.kube/db2u-config":

module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager: Creating...
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager: Provisioning with 'local-exec'...
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager (local-exec): Executing: ["/bin/sh" "-c" ".terraform/modules/dev_software_olm_release/scripts/deploy-olm.sh v0.20.0"]
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager (local-exec): CLUSTER_TYPE: kubernetes
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager (local-exec): W0204 15:38:23.680582   31899 loader.go:221] Config not found: $HOME/.kube/db2u-config
module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager (local-exec): The connection to the server localhost:8080 was refused - did you specify the right host or port?
╷
│ Error: local-exec provisioner error
│ 
│   with module.dev_software_olm_release.null_resource.deploy_operator_lifecycle_manager,
│   on .terraform/modules/dev_software_olm_release/main.tf line 15, in resource "null_resource" "deploy_operator_lifecycle_manager":
│   15:   provisioner "local-exec" {
│ 
│ Error running command '.terraform/modules/dev_software_olm_release/scripts/deploy-olm.sh v0.20.0': exit status 1. Output: CLUSTER_TYPE: kubernetes
│ W0204 15:38:23.680582   31899 loader.go:221] Config not found: $HOME/.kube/db2u-config
│ The connection to the server localhost:8080 was refused - did you specify the right host or port?

Here is the terraform snippet I'm using:

module "dev_software_olm_release" {
  source = "github.com/cloud-native-toolkit/terraform-k8s-olm"

  cluster_config_file = "~/.kube/db2u-config"
  cluster_version     = "1.20"
  cluster_type        = "kubernetes"
  olm_version         = "v0.20.0"
}

When I switch to cluster_config_file = "/home/<username>/.kube/db2u-config" it runs without any issue.

martintietz commented 2 years ago

Fixed by using pathexpand (https://www.terraform.io/language/functions/pathexpand):

module "dev_software_olm_release" {
  source = "github.com/cloud-native-toolkit/terraform-k8s-olm"

  cluster_config_file = pathexpand("~/.kube/db2u-config")
  cluster_version     = "1.20"
  cluster_type        = "kubernetes"
  olm_version         = "v0.20.0"
}