Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow settings tags for lb_listener_v2 #1438

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions openstack/lb_v2_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ func chooseLBV2ListenerCreateOpts(d *schema.ResourceData, config *Config) (neutr
opts.TimeoutTCPInspect = &timeoutTCPInspect
}

if v, ok := d.GetOk("tags"); ok {
tags := v.(*schema.Set).List()
opts.Tags = expandToStringSlice(tags)
}

// Get and check insert headers map.
rawHeaders := d.Get("insert_headers").(map[string]interface{})
headers, err := expandLBV2ListenerHeadersMap(rawHeaders)
Expand Down Expand Up @@ -338,6 +343,17 @@ func chooseLBV2ListenerUpdateOpts(d *schema.ResourceData, config *Config) (neutr
opts.AllowedCIDRs = &allowedCidrs
}

if d.HasChange("tags") {
hasChange = true
if v, ok := d.GetOk("tags"); ok {
tags := v.(*schema.Set).List()
tagsToUpdate := expandToStringSlice(tags)
opts.Tags = &tagsToUpdate
} else {
opts.Tags = &[]string{}
}
}

if hasChange {
return opts, nil
}
Expand Down
8 changes: 8 additions & 0 deletions openstack/resource_openstack_lb_listener_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ func resourceListenerV2() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"tags": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
},
}
}
Expand Down Expand Up @@ -223,6 +230,7 @@ func resourceListenerV2Read(ctx context.Context, d *schema.ResourceData, meta in
d.Set("default_tls_container_ref", listener.DefaultTlsContainerRef)
d.Set("allowed_cidrs", listener.AllowedCIDRs)
d.Set("region", GetRegion(d, config))
d.Set("tags", listener.Tags)

// Required by import.
if len(listener.Loadbalancers) > 0 {
Expand Down
6 changes: 6 additions & 0 deletions openstack/resource_openstack_lb_listener_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func TestAccLBV2Listener_octavia(t *testing.T) {
Config: testAccLbV2ListenerConfigOctavia,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV2ListenerExists("openstack_lb_listener_v2.listener_1", &listener),
resource.TestCheckResourceAttr(
"openstack_lb_listener_v2.listener_1", "tags.#", "1"),
resource.TestCheckResourceAttr(
"openstack_lb_listener_v2.listener_1", "connection_limit", "5"),
resource.TestCheckResourceAttr(
Expand All @@ -77,6 +79,8 @@ func TestAccLBV2Listener_octavia(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"openstack_lb_listener_v2.listener_1", "name", "listener_1_updated"),
resource.TestCheckResourceAttr(
"openstack_lb_listener_v2.listener_1", "tags.#", "2"),
resource.TestCheckResourceAttr(
"openstack_lb_listener_v2.listener_1", "connection_limit", "100"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -346,6 +350,7 @@ resource "openstack_lb_listener_v2" "listener_1" {
timeout_tcp_inspect = 4000
default_pool_id = "${openstack_lb_pool_v2.pool_1.id}"
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
tags = ["tag1"]

timeouts {
create = "5m"
Expand Down Expand Up @@ -398,6 +403,7 @@ resource "openstack_lb_listener_v2" "listener_1" {
admin_state_up = "true"
default_pool_id = "${openstack_lb_pool_v2.pool_1.id}"
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
tags = ["tag1", "tag2"]

timeouts {
create = "5m"
Expand Down