This commit is contained in:
Jon Perritt 2015-01-26 15:45:05 -07:00
parent d51ee3111e
commit 5d2fe153c0
7 changed files with 32 additions and 42 deletions

View File

@ -28,7 +28,6 @@ func resourceComputeInstanceV2() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
}, },
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -125,7 +124,6 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Error creating OpenStack compute client: %s", err) return fmt.Errorf("Error creating OpenStack compute client: %s", err)
} }
var createOpts servers.CreateOptsBuilder var createOpts servers.CreateOptsBuilder
serverCreateOpts := &servers.CreateOpts{ serverCreateOpts := &servers.CreateOpts{
@ -228,20 +226,16 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err
d.Set("metadata", server.Metadata) d.Set("metadata", server.Metadata)
var currentSG []string
err = secgroups.ListByServer(computeClient, 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) secGrpList, err := secgroups.ExtractSecurityGroups(page)
if err != nil { if err != nil {
return false, fmt.Errorf("Error setting security groups for OpenStack server: %s", err) return false, fmt.Errorf("Error getting security groups for OpenStack server: %s", err)
} }
for i, sg := range secGrpList {
for _, sg := range secGrpList { d.Set(fmt.Sprintf("security_groups.%d", i), sg.Name)
currentSG = append(currentSG, sg.Name)
} }
return true, nil return true, nil
}) })
d.Set("security_groups", currentSG)
newFlavor, ok := server.Flavor["id"].(string) newFlavor, ok := server.Flavor["id"].(string)
if !ok { if !ok {
@ -272,12 +266,12 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
updateOpts.AccessIPv4 = d.Get("access_ip_v6").(string) updateOpts.AccessIPv4 = d.Get("access_ip_v6").(string)
} }
log.Printf("[DEBUG] Updating Server %s with options: %+v", d.Id(), updateOpts) if updateOpts != (servers.UpdateOpts{}) {
_, err := servers.Update(computeClient, d.Id(), updateOpts).Extract()
_, err = servers.Update(computeClient, d.Id(), updateOpts).Extract()
if err != nil { if err != nil {
return fmt.Errorf("Error updating OpenStack server: %s", err) return fmt.Errorf("Error updating OpenStack server: %s", err)
} }
}
if d.HasChange("metadata") { if d.HasChange("metadata") {
var metadataOpts servers.MetadataOpts var metadataOpts servers.MetadataOpts

View File

@ -20,7 +20,6 @@ func resourceComputeKeypairV2() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
}, },
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,

View File

@ -22,7 +22,6 @@ func resourceComputeSecGroupV2() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
}, },
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"log" "log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack" "github.com/rackspace/gophercloud/openstack"
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/pools" "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/pools"

View File

@ -23,7 +23,6 @@ func resourceNetworkingNetworkV2() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
}, },
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,

View File

@ -5,8 +5,8 @@ import (
"log" "log"
"strconv" "strconv"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack" "github.com/rackspace/gophercloud/openstack"
"github.com/rackspace/gophercloud/openstack/networking/v2/subnets" "github.com/rackspace/gophercloud/openstack/networking/v2/subnets"
@ -24,7 +24,6 @@ func resourceNetworkingSubnetV2() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
}, },
"network_id": &schema.Schema{ "network_id": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,