make 'region' resource-specific; create new client for each crud operation
This commit is contained in:
parent
bfe492d407
commit
8579c8693a
|
@ -1,25 +0,0 @@
|
|||
package openstack
|
||||
|
||||
import (
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
)
|
||||
|
||||
func newClient(c *Config, service, region string, version int) (*gophercloud.ServiceClient, error) {
|
||||
var serviceClient *gophercloud.ServiceClient
|
||||
switch service {
|
||||
case "compute":
|
||||
if version == 2 {
|
||||
serviceClient, err = openstack.NewComputeV2(c.osClient, gophercloud.EndpointOpts{
|
||||
Region: region,
|
||||
})
|
||||
}
|
||||
case "networking":
|
||||
if version == 2 {
|
||||
serviceClient, err = openstack.NewNetworkV2(c.osClient, gophercloud.EndpointOpts{
|
||||
Region: region,
|
||||
})
|
||||
}
|
||||
}
|
||||
return serviceClient, err
|
||||
}
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
|
||||
|
@ -23,24 +24,27 @@ func resourceComputeInstance() *schema.Resource {
|
|||
Delete: resourceComputeInstanceDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"image_ref": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"flavor_ref": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"security_groups": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
|
@ -50,13 +54,11 @@ func resourceComputeInstance() *schema.Resource {
|
|||
return hashcode.String(v.(string))
|
||||
},
|
||||
},
|
||||
|
||||
"availability_zone": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"networks": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
|
@ -67,12 +69,10 @@ func resourceComputeInstance() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"port": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"fixed_ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -80,39 +80,33 @@ func resourceComputeInstance() *schema.Resource {
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
"metadata": &schema.Schema{
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"config_drive": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"admin_pass": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"access_ip_v4": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"access_ip_v6": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"key_pair": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -124,7 +118,13 @@ func resourceComputeInstance() *schema.Resource {
|
|||
|
||||
func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
|
||||
var createOpts servers.CreateOptsBuilder
|
||||
|
||||
|
@ -148,7 +148,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
|
|||
}
|
||||
|
||||
log.Printf("[INFO] Requesting instance creation")
|
||||
server, err := servers.Create(osClient, createOpts).Extract()
|
||||
server, err := servers.Create(computeClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack server: %s", err)
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
|
|||
stateConf := &resource.StateChangeConf{
|
||||
Pending: []string{"BUILD"},
|
||||
Target: "ACTIVE",
|
||||
Refresh: ServerStateRefreshFunc(osClient, server.ID),
|
||||
Refresh: ServerStateRefreshFunc(computeClient, server.ID),
|
||||
Timeout: 10 * time.Minute,
|
||||
Delay: 10 * time.Second,
|
||||
MinTimeout: 3 * time.Second,
|
||||
|
@ -184,9 +184,14 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
|
|||
|
||||
func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
server, err := servers.Get(osClient, d.Id()).Extract()
|
||||
server, err := servers.Get(computeClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error retrieving OpenStack server: %s", err)
|
||||
}
|
||||
|
@ -223,7 +228,7 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
|
|||
d.Set("metadata", server.Metadata)
|
||||
|
||||
var currentSG []string
|
||||
err = secgroups.ListByServer(osClient, d.Id()).EachPage(func(page pagination.Page) (bool, error) {
|
||||
err = secgroups.ListByServer(computeClient, d.Id()).EachPage(func(page pagination.Page) (bool, error) {
|
||||
secGrpList, err := secgroups.ExtractSecurityGroups(page)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Error setting security groups for OpenStack server: %s", err)
|
||||
|
@ -248,7 +253,12 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
|
|||
|
||||
func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
var updateOpts servers.UpdateOpts
|
||||
if d.HasChange("name") {
|
||||
|
@ -263,7 +273,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
|
||||
log.Printf("[DEBUG] Updating Server %s with options: %+v", d.Id(), updateOpts)
|
||||
|
||||
_, err := servers.Update(osClient, d.Id(), updateOpts).Extract()
|
||||
_, err = servers.Update(computeClient, d.Id(), updateOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack server: %s", err)
|
||||
}
|
||||
|
@ -276,7 +286,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
metadataOpts[k] = v.(string)
|
||||
}
|
||||
|
||||
_, err := servers.UpdateMetadata(osClient, d.Id(), metadataOpts).Extract()
|
||||
_, err := servers.UpdateMetadata(computeClient, d.Id(), metadataOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack server (%s) metadata: %s", d.Id(), err)
|
||||
}
|
||||
|
@ -293,7 +303,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
log.Printf("[DEBUG] Security groups to remove: %v", secgroupsToRemove)
|
||||
|
||||
for _, g := range secgroupsToAdd.List() {
|
||||
err := secgroups.AddServerToGroup(osClient, d.Id(), g.(string)).ExtractErr()
|
||||
err := secgroups.AddServerToGroup(computeClient, d.Id(), g.(string)).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error adding security group to OpenStack server (%s): %s", d.Id(), err)
|
||||
}
|
||||
|
@ -301,7 +311,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
}
|
||||
|
||||
for _, g := range secgroupsToRemove.List() {
|
||||
err := secgroups.RemoveServerFromGroup(osClient, d.Id(), g.(string)).ExtractErr()
|
||||
err := secgroups.RemoveServerFromGroup(computeClient, d.Id(), g.(string)).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error removing security group from OpenStack server (%s): %s", d.Id(), err)
|
||||
}
|
||||
|
@ -311,7 +321,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
|
||||
if d.HasChange("admin_pass") {
|
||||
if newPwd, ok := d.Get("admin_pass").(string); ok {
|
||||
err := servers.ChangeAdminPassword(osClient, d.Id(), newPwd).ExtractErr()
|
||||
err := servers.ChangeAdminPassword(computeClient, d.Id(), newPwd).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error changing admin password of OpenStack server (%s): %s", d.Id(), err)
|
||||
}
|
||||
|
@ -322,7 +332,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
resizeOpts := &servers.ResizeOpts{
|
||||
FlavorRef: d.Get("flavor_ref").(string),
|
||||
}
|
||||
err := servers.Resize(osClient, d.Id(), resizeOpts).ExtractErr()
|
||||
err := servers.Resize(computeClient, d.Id(), resizeOpts).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error resizing OpenStack server: %s", err)
|
||||
}
|
||||
|
@ -333,7 +343,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
stateConf := &resource.StateChangeConf{
|
||||
Pending: []string{"RESIZE"},
|
||||
Target: "VERIFY_RESIZE",
|
||||
Refresh: ServerStateRefreshFunc(osClient, d.Id()),
|
||||
Refresh: ServerStateRefreshFunc(computeClient, d.Id()),
|
||||
Timeout: 3 * time.Minute,
|
||||
Delay: 10 * time.Second,
|
||||
MinTimeout: 3 * time.Second,
|
||||
|
@ -346,7 +356,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
|
||||
// Confirm resize.
|
||||
log.Printf("[DEBUG] Confirming resize")
|
||||
err = servers.ConfirmResize(osClient, d.Id()).ExtractErr()
|
||||
err = servers.ConfirmResize(computeClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error confirming resize of OpenStack server: %s", err)
|
||||
}
|
||||
|
@ -354,7 +364,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
stateConf = &resource.StateChangeConf{
|
||||
Pending: []string{"VERIFY_RESIZE"},
|
||||
Target: "ACTIVE",
|
||||
Refresh: ServerStateRefreshFunc(osClient, d.Id()),
|
||||
Refresh: ServerStateRefreshFunc(computeClient, d.Id()),
|
||||
Timeout: 3 * time.Minute,
|
||||
Delay: 10 * time.Second,
|
||||
MinTimeout: 3 * time.Second,
|
||||
|
@ -371,9 +381,14 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
|
||||
func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
err := servers.Delete(osClient, d.Id()).ExtractErr()
|
||||
err = servers.Delete(computeClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack server: %s", err)
|
||||
}
|
||||
|
@ -383,7 +398,7 @@ func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) err
|
|||
|
||||
stateConf := &resource.StateChangeConf{
|
||||
Target: "",
|
||||
Refresh: ServerStateRefreshFunc(osClient, d.Id()),
|
||||
Refresh: ServerStateRefreshFunc(computeClient, d.Id()),
|
||||
Timeout: 10 * time.Minute,
|
||||
Delay: 10 * time.Second,
|
||||
MinTimeout: 3 * time.Second,
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
|
||||
)
|
||||
|
||||
|
@ -14,12 +16,17 @@ func resourceComputeKeypair() *schema.Resource {
|
|||
Delete: resourceComputeKeypairDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"public_key": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -31,14 +38,19 @@ func resourceComputeKeypair() *schema.Resource {
|
|||
|
||||
func resourceComputeKeypairCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
createOpts := keypairs.CreateOpts{
|
||||
Name: d.Get("name").(string),
|
||||
PublicKey: d.Get("public_key").(string),
|
||||
}
|
||||
|
||||
kp, err := keypairs.Create(osClient, createOpts).Extract()
|
||||
kp, err := keypairs.Create(computeClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack keypair: %s", err)
|
||||
}
|
||||
|
@ -50,9 +62,14 @@ func resourceComputeKeypairCreate(d *schema.ResourceData, meta interface{}) erro
|
|||
|
||||
func resourceComputeKeypairRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
kp, err := keypairs.Get(osClient, d.Id()).Extract()
|
||||
kp, err := keypairs.Get(computeClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error retrieving OpenStack keypair: %s", err)
|
||||
}
|
||||
|
@ -65,9 +82,14 @@ func resourceComputeKeypairRead(d *schema.ResourceData, meta interface{}) error
|
|||
|
||||
func resourceComputeKeypairDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
err := keypairs.Delete(osClient, d.Id()).ExtractErr()
|
||||
err = keypairs.Delete(computeClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack keypair: %s", err)
|
||||
}
|
|
@ -5,6 +5,8 @@ import (
|
|||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups"
|
||||
)
|
||||
|
||||
|
@ -16,12 +18,17 @@ func resourceComputeSecGroup() *schema.Resource {
|
|||
Delete: resourceComputeSecGroupDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"description": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
|
@ -33,14 +40,19 @@ func resourceComputeSecGroup() *schema.Resource {
|
|||
|
||||
func resourceComputeSecGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
createOpts := secgroups.CreateOpts{
|
||||
Name: d.Get("name").(string),
|
||||
Description: d.Get("description").(string),
|
||||
}
|
||||
|
||||
sg, err := secgroups.Create(osClient, createOpts).Extract()
|
||||
sg, err := secgroups.Create(computeClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack security group: %s", err)
|
||||
}
|
||||
|
@ -52,9 +64,14 @@ func resourceComputeSecGroupCreate(d *schema.ResourceData, meta interface{}) err
|
|||
|
||||
func resourceComputeSecGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
sg, err := secgroups.Get(osClient, d.Id()).Extract()
|
||||
sg, err := secgroups.Get(computeClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error retrieving OpenStack security group: %s", err)
|
||||
}
|
||||
|
@ -67,7 +84,12 @@ func resourceComputeSecGroupRead(d *schema.ResourceData, meta interface{}) error
|
|||
|
||||
func resourceComputeSecGroupUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
var updateOpts secgroups.UpdateOpts
|
||||
if d.HasChange("name") {
|
||||
|
@ -77,24 +99,26 @@ func resourceComputeSecGroupUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
updateOpts.Description = d.Get("description").(string)
|
||||
}
|
||||
|
||||
// If there's nothing to update, don't waste an HTTP call.
|
||||
if updateOpts != (secgroups.UpdateOpts{}) {
|
||||
log.Printf("[DEBUG] Updating Security Group (%s) with options: %+v", d.Id(), updateOpts)
|
||||
|
||||
_, err := secgroups.Update(osClient, d.Id(), updateOpts).Extract()
|
||||
_, err = secgroups.Update(computeClient, d.Id(), updateOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack security group (%s): %s", d.Id(), err)
|
||||
}
|
||||
}
|
||||
|
||||
return resourceComputeSecGroupRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceComputeSecGroupDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
err := secgroups.Delete(osClient, d.Id()).ExtractErr()
|
||||
err = secgroups.Delete(computeClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack security group: %s", err)
|
||||
}
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups"
|
||||
)
|
||||
|
||||
|
@ -14,36 +16,37 @@ func resourceComputeSecGroupRule() *schema.Resource {
|
|||
Delete: resourceComputeSecGroupRuleDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"group_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"from_port": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"to_port": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"ip_protocol": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"cidr": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"from_group_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -55,7 +58,12 @@ func resourceComputeSecGroupRule() *schema.Resource {
|
|||
|
||||
func resourceComputeSecGroupRuleCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
createOpts := secgroups.CreateRuleOpts{
|
||||
ParentGroupID: d.Get("group_id").(string),
|
||||
|
@ -66,7 +74,7 @@ func resourceComputeSecGroupRuleCreate(d *schema.ResourceData, meta interface{})
|
|||
FromGroupID: d.Get("from_group_id").(string),
|
||||
}
|
||||
|
||||
sgr, err := secgroups.CreateRule(osClient, createOpts).Extract()
|
||||
sgr, err := secgroups.CreateRule(computeClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack security group rule: %s", err)
|
||||
}
|
||||
|
@ -88,9 +96,14 @@ func resourceComputeSecGroupRuleRead(d *schema.ResourceData, meta interface{}) e
|
|||
|
||||
func resourceComputeSecGroupRuleDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.computeV2Client
|
||||
computeClient, err := openstack.NewComputeV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
|
||||
}
|
||||
|
||||
err := secgroups.DeleteRule(osClient, d.Id()).ExtractErr()
|
||||
err = secgroups.DeleteRule(computeClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack security group rule: %s", err)
|
||||
}
|
|
@ -5,6 +5,8 @@ import (
|
|||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/members"
|
||||
)
|
||||
|
||||
|
@ -16,30 +18,32 @@ func resourceLBMember() *schema.Resource {
|
|||
Delete: resourceLBMemberDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"tenant_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"address": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"port": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"pool_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"admin_state_up": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Required: true,
|
||||
|
@ -51,7 +55,12 @@ func resourceLBMember() *schema.Resource {
|
|||
|
||||
func resourceLBMemberCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
createOpts := members.CreateOpts{
|
||||
//TenantID: d.Get("tenant_id").(string),
|
||||
|
@ -61,7 +70,7 @@ func resourceLBMemberCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
log.Printf("[INFO] Requesting lb member creation")
|
||||
p, err := members.Create(osClient, createOpts).Extract()
|
||||
p, err := members.Create(networkingClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack LB member: %s", err)
|
||||
}
|
||||
|
@ -74,9 +83,14 @@ func resourceLBMemberCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBMemberRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
p, err := members.Get(osClient, d.Id()).Extract()
|
||||
p, err := members.Get(networkingClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error retrieving OpenStack LB Member: %s", err)
|
||||
}
|
||||
|
@ -100,7 +114,12 @@ func resourceLBMemberRead(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBMemberUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
var updateOpts members.UpdateOpts
|
||||
if d.HasChange("admin_state_up") {
|
||||
|
@ -109,7 +128,7 @@ func resourceLBMemberUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
log.Printf("[DEBUG] Updating OpenStack LB Member %s with options: %+v", d.Id(), updateOpts)
|
||||
|
||||
_, err := members.Update(osClient, d.Id(), updateOpts).Extract()
|
||||
_, err = members.Update(networkingClient, d.Id(), updateOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack LB Member: %s", err)
|
||||
}
|
||||
|
@ -119,9 +138,14 @@ func resourceLBMemberUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBMemberDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
err := members.Delete(osClient, d.Id()).ExtractErr()
|
||||
err = members.Delete(networkingClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack LB Member: %s", err)
|
||||
}
|
|
@ -6,6 +6,8 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/monitors"
|
||||
)
|
||||
|
||||
|
@ -17,54 +19,52 @@ func resourceLBMonitor() *schema.Resource {
|
|||
Delete: resourceLBMonitorDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"tenant_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"type": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"delay": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"timeout": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"max_retries": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"url_path": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"http_method": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"expected_codes": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"admin_state_up": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -76,7 +76,12 @@ func resourceLBMonitor() *schema.Resource {
|
|||
|
||||
func resourceLBMonitorCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
createOpts := monitors.CreateOpts{
|
||||
TenantID: d.Get("tenant_id").(string),
|
||||
|
@ -99,7 +104,7 @@ func resourceLBMonitorCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
log.Printf("[INFO] Requesting lb monitor creation")
|
||||
m, err := monitors.Create(osClient, createOpts).Extract()
|
||||
m, err := monitors.Create(networkingClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack LB Monitor: %s", err)
|
||||
}
|
||||
|
@ -112,9 +117,14 @@ func resourceLBMonitorCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBMonitorRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
m, err := monitors.Get(osClient, d.Id()).Extract()
|
||||
m, err := monitors.Get(networkingClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error retrieving OpenStack LB Monitor: %s", err)
|
||||
}
|
||||
|
@ -171,7 +181,12 @@ func resourceLBMonitorRead(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBMonitorUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
var updateOpts monitors.UpdateOpts
|
||||
if d.HasChange("delay") {
|
||||
|
@ -205,7 +220,7 @@ func resourceLBMonitorUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
log.Printf("[DEBUG] Updating OpenStack LB Monitor %s with options: %+v", d.Id(), updateOpts)
|
||||
|
||||
_, err := monitors.Update(osClient, d.Id(), updateOpts).Extract()
|
||||
_, err = monitors.Update(networkingClient, d.Id(), updateOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack LB Monitor: %s", err)
|
||||
}
|
||||
|
@ -215,9 +230,14 @@ func resourceLBMonitorUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBMonitorDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
err := monitors.Delete(osClient, d.Id()).ExtractErr()
|
||||
err = monitors.Delete(networkingClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack LB Monitor: %s", err)
|
||||
}
|
|
@ -5,7 +5,9 @@ import (
|
|||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/jrperritt/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/pools"
|
||||
)
|
||||
|
||||
|
@ -17,18 +19,22 @@ func resourceLBPool() *schema.Resource {
|
|||
Delete: resourceLBPoolDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"protocol": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"subnet_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
|
@ -40,13 +46,11 @@ func resourceLBPool() *schema.Resource {
|
|||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"tenant_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"monitor_ids": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
|
@ -62,7 +66,12 @@ func resourceLBPool() *schema.Resource {
|
|||
|
||||
func resourceLBPoolCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
createOpts := pools.CreateOpts{
|
||||
Name: d.Get("name").(string),
|
||||
|
@ -73,7 +82,7 @@ func resourceLBPoolCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
log.Printf("[INFO] Requesting lb pool creation")
|
||||
p, err := pools.Create(osClient, createOpts).Extract()
|
||||
p, err := pools.Create(networkingClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack LB pool: %s", err)
|
||||
}
|
||||
|
@ -83,7 +92,7 @@ func resourceLBPoolCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
if mIDs := resourcePoolMonitorIDs(d); mIDs != nil {
|
||||
for _, mID := range mIDs {
|
||||
_, err := pools.AssociateMonitor(osClient, p.ID, mID).Extract()
|
||||
_, err := pools.AssociateMonitor(networkingClient, p.ID, mID).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error associating monitor (%s) with OpenStack LB pool (%s): %s", mID, p.ID, err)
|
||||
}
|
||||
|
@ -95,9 +104,14 @@ func resourceLBPoolCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBPoolRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
p, err := pools.Get(osClient, d.Id()).Extract()
|
||||
p, err := pools.Get(networkingClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error retrieving OpenStack LB Pool: %s", err)
|
||||
}
|
||||
|
@ -124,7 +138,12 @@ func resourceLBPoolRead(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBPoolUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
var updateOpts pools.UpdateOpts
|
||||
if d.HasChange("name") {
|
||||
|
@ -136,7 +155,7 @@ func resourceLBPoolUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
log.Printf("[DEBUG] Updating OpenStack LB Pool %s with options: %+v", d.Id(), updateOpts)
|
||||
|
||||
_, err := pools.Update(osClient, d.Id(), updateOpts).Extract()
|
||||
_, err = pools.Update(networkingClient, d.Id(), updateOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack LB Pool: %s", err)
|
||||
}
|
||||
|
@ -152,7 +171,7 @@ func resourceLBPoolUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
log.Printf("[DEBUG] Monitors to remove: %v", monitorsToRemove)
|
||||
|
||||
for _, m := range monitorsToAdd.List() {
|
||||
_, err := pools.AssociateMonitor(osClient, d.Id(), m.(string)).Extract()
|
||||
_, err := pools.AssociateMonitor(networkingClient, d.Id(), m.(string)).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error associating monitor (%s) with OpenStack server (%s): %s", m.(string), d.Id(), err)
|
||||
}
|
||||
|
@ -160,7 +179,7 @@ func resourceLBPoolUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
for _, m := range monitorsToRemove.List() {
|
||||
_, err := pools.DisassociateMonitor(osClient, d.Id(), m.(string)).Extract()
|
||||
_, err := pools.DisassociateMonitor(networkingClient, d.Id(), m.(string)).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error disassociating monitor (%s) from OpenStack server (%s): %s", m.(string), d.Id(), err)
|
||||
}
|
||||
|
@ -173,9 +192,14 @@ func resourceLBPoolUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBPoolDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
err := pools.Delete(osClient, d.Id()).ExtractErr()
|
||||
err = pools.Delete(networkingClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack LB Pool: %s", err)
|
||||
}
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/vips"
|
||||
)
|
||||
|
||||
|
@ -18,66 +19,62 @@ func resourceLBVip() *schema.Resource {
|
|||
Delete: resourceLBVipDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"subnet_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"protocol": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"port": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"pool_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"tenant_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"address": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"description": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"persistence": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"conn_limit": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"admin_state_up": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -89,7 +86,12 @@ func resourceLBVip() *schema.Resource {
|
|||
|
||||
func resourceLBVipCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
createOpts := vips.CreateOpts{
|
||||
Name: d.Get("name").(string),
|
||||
|
@ -114,7 +116,7 @@ func resourceLBVipCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
log.Printf("[INFO] Requesting lb vip creation")
|
||||
p, err := vips.Create(osClient, createOpts).Extract()
|
||||
p, err := vips.Create(networkingClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack LB VIP: %s", err)
|
||||
}
|
||||
|
@ -127,9 +129,14 @@ func resourceLBVipCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBVipRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
p, err := vips.Get(osClient, d.Id()).Extract()
|
||||
p, err := vips.Get(networkingClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error retrieving OpenStack LB VIP: %s", err)
|
||||
}
|
||||
|
@ -193,7 +200,12 @@ func resourceLBVipRead(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBVipUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
var updateOpts vips.UpdateOpts
|
||||
if d.HasChange("name") {
|
||||
|
@ -224,7 +236,7 @@ func resourceLBVipUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
log.Printf("[DEBUG] Updating OpenStack LB VIP %s with options: %+v", d.Id(), updateOpts)
|
||||
|
||||
_, err := vips.Update(osClient, d.Id(), updateOpts).Extract()
|
||||
_, err = vips.Update(networkingClient, d.Id(), updateOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack LB VIP: %s", err)
|
||||
}
|
||||
|
@ -234,9 +246,14 @@ func resourceLBVipUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
func resourceLBVipDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
err := vips.Delete(osClient, d.Id()).ExtractErr()
|
||||
err = vips.Delete(networkingClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack LB VIP: %s", err)
|
||||
}
|
|
@ -6,6 +6,8 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/networks"
|
||||
)
|
||||
|
||||
|
@ -17,24 +19,27 @@ func resourceNetworkingNetwork() *schema.Resource {
|
|||
Delete: resourceNetworkingNetworkDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"admin_state_up": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"shared": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"tenant_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -46,7 +51,12 @@ func resourceNetworkingNetwork() *schema.Resource {
|
|||
|
||||
func resourceNetworkingNetworkCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
createOpts := networks.CreateOpts{
|
||||
Name: d.Get("name").(string),
|
||||
|
@ -72,7 +82,7 @@ func resourceNetworkingNetworkCreate(d *schema.ResourceData, meta interface{}) e
|
|||
}
|
||||
|
||||
log.Printf("[INFO] Requesting network creation")
|
||||
n, err := networks.Create(osClient, createOpts).Extract()
|
||||
n, err := networks.Create(networkingClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack Neutron network: %s", err)
|
||||
}
|
||||
|
@ -85,9 +95,14 @@ func resourceNetworkingNetworkCreate(d *schema.ResourceData, meta interface{}) e
|
|||
|
||||
func resourceNetworkingNetworkRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
n, err := networks.Get(osClient, d.Id()).Extract()
|
||||
n, err := networks.Get(networkingClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error retrieving OpenStack Neutron Network: %s", err)
|
||||
}
|
||||
|
@ -131,7 +146,12 @@ func resourceNetworkingNetworkRead(d *schema.ResourceData, meta interface{}) err
|
|||
|
||||
func resourceNetworkingNetworkUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
var updateOpts networks.UpdateOpts
|
||||
if d.HasChange("name") {
|
||||
|
@ -160,7 +180,7 @@ func resourceNetworkingNetworkUpdate(d *schema.ResourceData, meta interface{}) e
|
|||
|
||||
log.Printf("[DEBUG] Updating Network %s with options: %+v", d.Id(), updateOpts)
|
||||
|
||||
_, err := networks.Update(osClient, d.Id(), updateOpts).Extract()
|
||||
_, err = networks.Update(networkingClient, d.Id(), updateOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack Neutron Network: %s", err)
|
||||
}
|
||||
|
@ -170,9 +190,14 @@ func resourceNetworkingNetworkUpdate(d *schema.ResourceData, meta interface{}) e
|
|||
|
||||
func resourceNetworkingNetworkDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
err := networks.Delete(osClient, d.Id()).ExtractErr()
|
||||
err = networks.Delete(networkingClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack Neutron Network: %s", err)
|
||||
}
|
|
@ -6,7 +6,9 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/jrperritt/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/subnets"
|
||||
)
|
||||
|
||||
|
@ -18,30 +20,32 @@ func resourceNetworkingSubnet() *schema.Resource {
|
|||
Delete: resourceNetworkingSubnetDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
||||
},
|
||||
"network_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"cidr": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"tenant_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"allocation_pools": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
|
@ -52,7 +56,6 @@ func resourceNetworkingSubnet() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"end": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
|
@ -60,25 +63,21 @@ func resourceNetworkingSubnet() *schema.Resource {
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
"gateway_ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"ip_version": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"enable_dhcp": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
},
|
||||
|
||||
"dns_nameservers": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
|
@ -88,7 +87,6 @@ func resourceNetworkingSubnet() *schema.Resource {
|
|||
return hashcode.String(v.(string))
|
||||
},
|
||||
},
|
||||
|
||||
"host_routes": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
|
@ -99,7 +97,6 @@ func resourceNetworkingSubnet() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"next_hop": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
|
@ -113,7 +110,12 @@ func resourceNetworkingSubnet() *schema.Resource {
|
|||
|
||||
func resourceNetworkingSubnetCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
createOpts := subnets.CreateOpts{
|
||||
NetworkID: d.Get("network_id").(string),
|
||||
|
@ -137,7 +139,7 @@ func resourceNetworkingSubnetCreate(d *schema.ResourceData, meta interface{}) er
|
|||
}
|
||||
|
||||
log.Printf("[INFO] Requesting subnet creation")
|
||||
s, err := subnets.Create(osClient, createOpts).Extract()
|
||||
s, err := subnets.Create(networkingClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack Neutron subnet: %s", err)
|
||||
}
|
||||
|
@ -150,9 +152,14 @@ func resourceNetworkingSubnetCreate(d *schema.ResourceData, meta interface{}) er
|
|||
|
||||
func resourceNetworkingSubnetRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
s, err := subnets.Get(osClient, d.Id()).Extract()
|
||||
s, err := subnets.Get(networkingClient, d.Id()).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error retrieving OpenStack Neutron Subnet: %s", err)
|
||||
}
|
||||
|
@ -212,7 +219,12 @@ func resourceNetworkingSubnetRead(d *schema.ResourceData, meta interface{}) erro
|
|||
|
||||
func resourceNetworkingSubnetUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
var updateOpts subnets.UpdateOpts
|
||||
|
||||
|
@ -245,7 +257,7 @@ func resourceNetworkingSubnetUpdate(d *schema.ResourceData, meta interface{}) er
|
|||
|
||||
log.Printf("[DEBUG] Updating Subnet %s with options: %+v", d.Id(), updateOpts)
|
||||
|
||||
_, err := subnets.Update(osClient, d.Id(), updateOpts).Extract()
|
||||
_, err = subnets.Update(networkingClient, d.Id(), updateOpts).Extract()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error updating OpenStack Neutron Subnet: %s", err)
|
||||
}
|
||||
|
@ -255,9 +267,14 @@ func resourceNetworkingSubnetUpdate(d *schema.ResourceData, meta interface{}) er
|
|||
|
||||
func resourceNetworkingSubnetDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
osClient := config.networkingV2Client
|
||||
networkingClient, err := openstack.NewNetworkV2(config.osClient, gophercloud.EndpointOpts{
|
||||
Region: d.Get("region").(string),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||
}
|
||||
|
||||
err := subnets.Delete(osClient, d.Id()).ExtractErr()
|
||||
err = subnets.Delete(networkingClient, d.Id()).ExtractErr()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting OpenStack Neutron Subnet: %s", err)
|
||||
}
|
Loading…
Reference in New Issue