remche / terraform-openstack-rke

Terraform Openstack RKE
Mozilla Public License 2.0
37 stars 20 forks source link

[bug] Error when enabling loadbalancer #80

Closed aledegano closed 3 years ago

aledegano commented 3 years ago

Hello, first of all let me thank you very much for sharing this awesome module!

I have a small issue when using the latest release of the module (0.6.0) and Terraform 0.14.2 when setting enable_loadbalancer to true.

The simplest way to demonstrate it is to start from the first example of the README, after sourcing my openrc file, terraform init then terraform apply. The config is:

variable "os_auth_url" {}
variable "os_password" {}

module "rke" {
  source             = "remche/rke/openstack"
  image_name         = "ubuntu-20.04-docker-x86_64" #An actual image in my Openstack project
  public_net_name    = "public"
  master_flavor_name = "m1.small"
  worker_flavor_name = "m1.small"
  os_auth_url        = var.os_auth_url
  os_password        = var.os_password

  enable_loadbalancer = true
}

Will result in the following output:

Error: Unsupported attribute

  on .terraform/modules/rke/output.tf line 33, in output "loadbalancer_floating_ip":
  33:   value       = var.enable_loadbalancer ? module.loadbalancer.floating_ip : ""
    |----------------
    | module.loadbalancer is tuple with 1 element

This value does not have any attributes.

I have done some experiment on my own and the culprit seems to be the fact that the module loadbalancer is conditionally instantiated (through count = var.enable_loadbalancer ? 1 : 0) and that confuses somehow Terraform that doesn't recognize the output within the module.

Unfortunately I wasn't able to devise a reasonable fix to the issue, otherwise I would have opened a PR myself.

Do you have any idea on how we can workaround this problem? (for the time being I'm using the module from a local clone where I've removed the output :D )

Thank you!

remche commented 3 years ago

Hello @aledegano,

Thanks for the bug report!

Unfortunately, I do not have access to any Openstack instance with Octavia and can't test by myself, the work on LB was done by @hfrenzel.

Anyway, I did the change for conditional LB instantiation and am the guy to blame ;) I bet that the following change will fix the issue, could you test it and confirm :

output "loadbalancer_floating_ip" {
  value       = var.enable_loadbalancer ? module.loadbalancer[0].floating_ip : ""
  description = "The floating ip of the loadbalancer"
}
aledegano commented 3 years ago

Hello @aledegano,

Thanks for the bug report!

Unfortunately, I do not have access to any Openstack instance with Octavia and can't test by myself, the work on LB was done by @hfrenzel.

Anyway, I did the change for conditional LB instantiation and am the guy to blame ;) I bet that the following change will fix the issue, could you test it and confirm :

output "loadbalancer_floating_ip" {
  value       = var.enable_loadbalancer ? module.loadbalancer[0].floating_ip : ""
  description = "The floating ip of the loadbalancer"
}

Yes! That works, I'll open a PR in a moment!