hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.36k stars 9.49k forks source link

openstack_lb_member_v2 fails with fixed_ip_v6 from instance #30731

Closed mstinsky closed 2 years ago

mstinsky commented 2 years ago

Terraform Version

Terraform v1.1.7
on darwin_amd64
+ provider registry.terraform.io/terraform-provider-openstack/openstack v1.42.0

Expected Behavior

Loadbalancer member with the instance ipv6 address is created.

Actual Behavior

octavia error for Invalid input.

│ Error: Error creating member: Bad request with: [POST https://***/v2.0/lbaas/pools/d919da00-3da0-45d5-85b5-f1947406bbbe/members], error message: {"faultcode": "Client", "faultstring": "Invalid input for field/attribute address. Value: '[2001:db8::181]'. Value should be IPv4 or IPv6 format", "debuginfo": null}
│
│   with openstack_lb_member_v2.tf-lb-members,
│   on main.tf line 75, in resource "openstack_lb_member_v2" "tf-lb-members":
│   75: resource "openstack_lb_member_v2" "tf-lb-members" {

Code to Reproduce

terraform {
required_version = ">= v1.1.7"
  required_providers {
    openstack = {
      source = "terraform-provider-openstack/openstack"
      version = "~> 1.42.0"
    }
  }
}

provider "openstack" {
    use_octavia = true
}

variable "flavor" {
    type = string
}

variable "image" {
    type = string
}

resource "openstack_networking_network_v2" "tf-network" {
  name = "tf-network"
}

resource "openstack_networking_subnet_v2" "tf-subnet" {
  name                  = "tf-subnet"
  network_id            = openstack_networking_network_v2.tf-network.id
  ip_version            = 6
  cidr                  = "2001:db8::/48"
  ipv6_address_mode     = "dhcpv6-stateful"
  ipv6_ra_mode          = "dhcpv6-stateful"
}

resource "openstack_compute_instance_v2" "tf-instance" {
  name              = "tf-instance"
  image_name        = var.image
  flavor_name       = var.flavor
  network {
    uuid = openstack_networking_network_v2.tf-network.id
  }
}

resource "openstack_lb_loadbalancer_v2" "tf-lb" {
  name          = "tf-lb"
  vip_subnet_id = openstack_networking_subnet_v2.tf-subnet.id
}

resource "openstack_lb_listener_v2" "tf-lb-listener" {
  name            = "tf-lb-listener"
  protocol        = "HTTP"
  protocol_port   = 80
  loadbalancer_id = openstack_lb_loadbalancer_v2.tf-lb.id
}

resource "openstack_lb_pool_v2" "tf-lb-pool" {
  name        = "tf-lb-pool"
  protocol    = "HTTP"
  lb_method   = "ROUND_ROBIN"
  listener_id = openstack_lb_listener_v2.tf-lb-listener.id
}

resource "openstack_lb_monitor_v2" "tf-lb-monitor" {
  pool_id           = "${openstack_lb_pool_v2.tf-lb-pool.id}"
  type              = "HTTP"
  delay             = 5
  timeout           = 5
  max_retries       = 3
  max_retries_down  = 3
}

resource "openstack_lb_member_v2" "tf-lb-members" {
  name          = "tf-lb-member"
  pool_id       = openstack_lb_pool_v2.tf-lb-pool.id
  subnet_id     = openstack_networking_subnet_v2.tf-subnet.id
  address       = openstack_compute_instance_v2.tf-instance.network.0.fixed_ip_v6
  protocol_port = 80
} 

Additional Context

The attributes references network/fixed_ip_v6 and access_ip_v6 from openstack_compute_instance_v2 are returning ipv6 addresses with bracket notation. The ip type validation in octavia uses the python netaddr library to verify a valid ipv4 or ipv6 address which fails on bracket notation.

network/fixed_ip_v6 and access_ip_v6 should return ipv6 addresses without bracket notation.

Workaround

This can be worked around by creating a ipv6 member in the following way with trim:

resource "openstack_lb_member_v2" "tf-lb-members" {
  name          = "tf-lb-member"
  pool_id       = openstack_lb_pool_v2.tf-lb-pool.id
  subnet_id     = openstack_networking_subnet_v2.tf-subnet.id
  address       = trim(openstack_compute_instance_v2.tf-instance.network.0.fixed_ip_v6, "[]")
  protocol_port = 80
} 
mstinsky commented 2 years ago

Opened in the wrong project. Sorry!

github-actions[bot] commented 2 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.