openstack: set region in cluster cloud client (#3375)

This commit is contained in:
3u13r 2024-09-26 11:08:06 +02:00 committed by GitHub
parent d65987cb15
commit 882d602524
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 0 deletions

View File

@ -172,6 +172,20 @@ func (c *imdsClient) userDomainName(ctx context.Context) (string, error) {
return c.userDataCache.UserDomainName, nil
}
func (c *imdsClient) regionName(ctx context.Context) (string, error) {
if c.timeForUpdate(c.cacheTime) || c.userDataCache.RegionName == "" {
if err := c.update(ctx); err != nil {
return "", err
}
}
if c.userDataCache.RegionName == "" {
return "", errors.New("unable to get user domain name")
}
return c.userDataCache.RegionName, nil
}
func (c *imdsClient) username(ctx context.Context) (string, error) {
if c.timeForUpdate(c.cacheTime) || c.userDataCache.Username == "" {
if err := c.update(ctx); err != nil {
@ -295,6 +309,7 @@ type metadataTags struct {
type userDataResponse struct {
AuthURL string `json:"openstack-auth-url,omitempty"`
UserDomainName string `json:"openstack-user-domain-name,omitempty"`
RegionName string `json:"openstack-region-name,omitempty"`
Username string `json:"openstack-username,omitempty"`
Password string `json:"openstack-password,omitempty"`
LoadBalancerEndpoint string `json:"openstack-load-balancer-endpoint,omitempty"`

View File

@ -54,6 +54,10 @@ func New(ctx context.Context) (*MetadataClient, error) {
if err != nil {
return nil, fmt.Errorf("getting user domain name: %w", err)
}
regionName, err := imds.regionName(ctx)
if err != nil {
return nil, fmt.Errorf("getting region name: %w", err)
}
clientOpts := &clientconfig.ClientOpts{
AuthType: clientconfig.AuthV3Password,
@ -63,6 +67,7 @@ func New(ctx context.Context) (*MetadataClient, error) {
Username: username,
Password: password,
},
RegionName: regionName,
}
serversClient, err := clientconfig.NewServiceClient(ctx, "compute", clientOpts)

View File

@ -242,6 +242,7 @@ module "instance_group" {
openstack_username = local.cloudyaml["auth"]["username"]
openstack_password = local.cloudyaml["auth"]["password"]
openstack_user_domain_name = local.cloudyaml["auth"]["user_domain_name"]
openstack_region_name = local.cloudyaml["region_name"]
openstack_load_balancer_endpoint = openstack_networking_floatingip_v2.public_ip.address
}

View File

@ -80,6 +80,7 @@ resource "openstack_compute_instance_v2" "instance_group_member" {
openstack-username = var.openstack_username
openstack-password = var.openstack_password
openstack-user-domain-name = var.openstack_user_domain_name
openstack-region-name = var.openstack_region_name
openstack-load-balancer-endpoint = var.openstack_load_balancer_endpoint
})
availability_zone_hints = length(var.availability_zone) > 0 ? var.availability_zone : null

View File

@ -97,6 +97,11 @@ variable "openstack_password" {
description = "OpenStack password."
}
variable "openstack_region_name" {
type = string
description = "OpenStack region name."
}
variable "openstack_load_balancer_endpoint" {
type = string
description = "OpenStack load balancer endpoint."