terraformopenstackterraform-provider-openstack

Terraform - Error creating OpenStack loadbalancer: Resource not found


I'm trying to create an OpenStack load balancer with Terraform but I get the following error upon terraform apply:

Error: Error creating openstack_lb_loadbalancer_v2: Resource not found

on load-balancer/main.tf line 71, in resource "openstack_lb_loadbalancer_v2" "lb_1": 71: resource "openstack_lb_loadbalancer_v2" "lb_1" {

My template looks like the following.

resource "openstack_lb_loadbalancer_v2" "lb_1" {
  name          = "loadbalancer"
  vip_subnet_id = openstack_networking_subnet_v2.public.id
}

resource "openstack_lb_listener_v2" "listener_1" {
  name                      = "https"
  protocol                  = "TERMINATED_HTTPS"
  protocol_port             = 443
  loadbalancer_id           = openstack_lb_loadbalancer_v2.lb_1.id
  default_tls_container_ref = openstack_keymanager_container_v1.tls_1.container_ref
}

resource "openstack_networking_network_v2" "lb_network" {
  name = "lb-network"
  port_security_enabled = "true"
}

resource "openstack_networking_subnet_v2" "public" {
  name = "lb-subnet"
  network_id = openstack_networking_network_v2.lb_network.id
  cidr = "10.0.0.0/24"
  ip_version = 4
}

I have no clue about how to debug further. Does it mean that vip_subnet_id isn't found? Or is openstack_lb_loadbalancer_v2 an unknown resource type?

I'm using Terraform v0.13.5 and terraform-provider-openstack v1.33.0.

Update

I created a LB manually via the web interface and now I tried to import it via Terraform CLI and got the following response

Error: Cannot import non-existent remote object

While attempting to import an existing object to openstack_lb_loadbalancer_v2.lb_1, the provider detected that no object exists with the given id. Only pre-existing objects can be imported; check that the id is correct and that it is associated with the provider's configured region or endpoint, or use "terraform apply" to create a new remote object for this resource.

I start to suspect that this may be something wrong on the OpenStack server side.


Solution

  • Finally figured it out you need to set use_octiva = true in the openstack terraform provider settings. See relevant docs here: https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs#use_octavia

    Example config:

    cat main.tf
    provider "openstack" {
      user_name     = var.os_user_name
      tenant_name   = var.os_tenant_name
      password      = var.os_password
      auth_url      = var.os_auth_url
      region        = var.os_region
      endpoint_type = var.os_endpoint_type
      use_octavia   = true
    }
    

    Here is the relevant bug report: https://github.com/terraform-provider-openstack/terraform-provider-openstack/issues/1100