func resourceNetworkingRouterV2Create(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) } createOpts := routers.CreateOpts{ Name: d.Get("name").(string), TenantID: d.Get("tenant_id").(string), } if asuRaw, ok := d.GetOk("admin_state_up"); ok { asu := asuRaw.(bool) createOpts.AdminStateUp = &asu } externalGateway := d.Get("external_gateway").(string) if externalGateway != "" { gatewayInfo := routers.GatewayInfo{ NetworkID: externalGateway, } createOpts.GatewayInfo = &gatewayInfo } log.Printf("[DEBUG] Create Options: %#v", createOpts) n, err := routers.Create(networkingClient, createOpts).Extract() if err != nil { return fmt.Errorf("Error creating OpenStack Neutron router: %s", err) } log.Printf("[INFO] Router ID: %s", n.ID) log.Printf("[DEBUG] Waiting for OpenStack Neutron Router (%s) to become available", n.ID) stateConf := &resource.StateChangeConf{ Pending: []string{"BUILD", "PENDING_CREATE", "PENDING_UPDATE"}, Target: "ACTIVE", Refresh: waitForRouterActive(networkingClient, n.ID), Timeout: 2 * time.Minute, Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } _, err = stateConf.WaitForState() d.SetId(n.ID) return resourceNetworkingRouterV2Read(d, meta) }
func resourceNetworkingRouterV2Create(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) } createOpts := routers.CreateOpts{ Name: d.Get("name").(string), TenantID: d.Get("tenant_id").(string), } asuRaw := d.Get("admin_state_up").(string) if asuRaw != "" { asu, err := strconv.ParseBool(asuRaw) if err != nil { return fmt.Errorf("admin_state_up, if provided, must be either 'true' or 'false'") } createOpts.AdminStateUp = &asu } externalGateway := d.Get("external_gateway").(string) if externalGateway != "" { gatewayInfo := routers.GatewayInfo{ NetworkID: externalGateway, } createOpts.GatewayInfo = &gatewayInfo } log.Printf("[DEBUG] Create Options: %#v", createOpts) n, err := routers.Create(networkingClient, createOpts).Extract() if err != nil { return fmt.Errorf("Error creating OpenStack Neutron router: %s", err) } log.Printf("[INFO] Router ID: %s", n.ID) d.SetId(n.ID) return resourceNetworkingRouterV2Read(d, meta) }