func TestRequiredPoolCreateOpts(t *testing.T) { res := pools.Create(fake.ServiceClient(), pools.CreateOpts{}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = pools.Create(fake.ServiceClient(), pools.CreateOpts{ LBMethod: pools.LBMethod("invalid"), Protocol: pools.ProtocolHTTPS, LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a", }) if res.Err == nil { t.Fatalf("Expected error, but got none") } res = pools.Create(fake.ServiceClient(), pools.CreateOpts{ LBMethod: pools.LBMethodRoundRobin, Protocol: pools.Protocol("invalid"), LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a", }) if res.Err == nil { t.Fatalf("Expected error, but got none") } res = pools.Create(fake.ServiceClient(), pools.CreateOpts{ LBMethod: pools.LBMethodRoundRobin, Protocol: pools.ProtocolHTTPS, }) if res.Err == nil { t.Fatalf("Expected error, but got none") } }
func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) networkingClient, err := config.networkingV2Client(d.Get("region").(string)) if err != nil { return fmt.Errorf("Error creating OpenStack networking client: %s", err) } adminStateUp := d.Get("admin_state_up").(bool) var persistence pools.SessionPersistence if p, ok := d.GetOk("persistence"); ok { pV := (p.([]interface{}))[0].(map[string]interface{}) persistence = pools.SessionPersistence{ Type: pV["type"].(string), CookieName: pV["cookie_name"].(string), } } createOpts := pools.CreateOpts{ TenantID: d.Get("tenant_id").(string), Name: d.Get("name").(string), Description: d.Get("description").(string), Protocol: pools.Protocol(d.Get("protocol").(string)), LoadbalancerID: d.Get("loadbalancer_id").(string), ListenerID: d.Get("listener_id").(string), LBMethod: pools.LBMethod(d.Get("lb_method").(string)), AdminStateUp: &adminStateUp, } // Must omit if not set if persistence != (pools.SessionPersistence{}) { createOpts.Persistence = &persistence } log.Printf("[DEBUG] Create Options: %#v", createOpts) pool, err := pools.Create(networkingClient, createOpts).Extract() if err != nil { return fmt.Errorf("Error creating OpenStack LBaaSV2 pool: %s", err) } log.Printf("[INFO] pool ID: %s", pool.ID) log.Printf("[DEBUG] Waiting for Openstack LBaaSV2 pool (%s) to become available.", pool.ID) stateConf := &resource.StateChangeConf{ Pending: []string{"PENDING_CREATE"}, Target: []string{"ACTIVE"}, Refresh: waitForPoolActive(networkingClient, pool.ID), Timeout: 2 * time.Minute, Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } _, err = stateConf.WaitForState() if err != nil { return err } d.SetId(pool.ID) return resourcePoolV2Read(d, meta) }