fix diff bug in 'Read' functions

This commit is contained in:
Jon Perritt 2015-01-26 18:28:01 -07:00
parent 5d2fe153c0
commit d86cb6be1c
9 changed files with 51 additions and 85 deletions

View File

@ -28,6 +28,7 @@ func resourceComputeInstanceV2() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
},
"name": &schema.Schema{
Type: schema.TypeString,
@ -226,16 +227,19 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err
d.Set("metadata", server.Metadata)
secGrpNum := 0
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 getting security groups for OpenStack server: %s", err)
}
for i, sg := range secGrpList {
d.Set(fmt.Sprintf("security_groups.%d", i), sg.Name)
for _, sg := range secGrpList {
d.Set(fmt.Sprintf("security_groups.%d", secGrpNum), sg.Name)
secGrpNum++
}
return true, nil
})
d.Set("security_groups.#", secGrpNum)
newFlavor, ok := server.Flavor["id"].(string)
if !ok {

View File

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

View File

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

View File

@ -102,10 +102,8 @@ func resourceLBMemberV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("port", p.ProtocolPort)
d.Set("pool_id", p.PoolID)
if _, exists := d.GetOk("tenant_id"); exists {
if d.HasChange("tenant_id") {
d.Set("tenant_id", p.TenantID)
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", p.TenantID)
} else {
d.Set("tenant_id", "")
}

View File

@ -137,42 +137,32 @@ func resourceLBMonitorV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("timeout", m.Timeout)
d.Set("max_retries", m.MaxRetries)
if _, exists := d.GetOk("tenant_id"); exists {
if d.HasChange("tenant_id") {
d.Set("tenant_id", m.TenantID)
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", m.TenantID)
} else {
d.Set("tenant_id", "")
}
if _, exists := d.GetOk("url_path"); exists {
if d.HasChange("url_path") {
d.Set("url_path", m.URLPath)
}
if t, exists := d.GetOk("url_path"); exists && t != "" {
d.Set("url_path", m.URLPath)
} else {
d.Set("url_path", "")
}
if _, exists := d.GetOk("http_method"); exists {
if d.HasChange("http_method") {
d.Set("http_method", m.HTTPMethod)
}
if t, exists := d.GetOk("http_method"); exists && t != "" {
d.Set("http_method", m.HTTPMethod)
} else {
d.Set("http_method", "")
}
if _, exists := d.GetOk("expected_codes"); exists {
if d.HasChange("expected_codes") {
d.Set("expected_codes", m.ExpectedCodes)
}
if t, exists := d.GetOk("expected_codes"); exists && t != "" {
d.Set("expected_codes", m.ExpectedCodes)
} else {
d.Set("expected_codes", "")
}
if _, exists := d.GetOk("admin_state_up"); exists {
if d.HasChange("admin_state_up") {
d.Set("admin_state_up", strconv.FormatBool(m.AdminStateUp))
}
if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
d.Set("admin_state_up", strconv.FormatBool(m.AdminStateUp))
} else {
d.Set("admin_state_up", "")
}

View File

@ -124,10 +124,8 @@ func resourceLBPoolV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("subnet_id", p.SubnetID)
d.Set("lb_method", p.LBMethod)
if _, exists := d.GetOk("tenant_id"); exists {
if d.HasChange("tenant_id") {
d.Set("tenant_id", p.TenantID)
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", p.TenantID)
} else {
d.Set("tenant_id", "")
}

View File

@ -150,48 +150,36 @@ func resourceLBVipV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("port", p.ProtocolPort)
d.Set("pool_id", p.PoolID)
if _, exists := d.GetOk("tenant_id"); exists {
if d.HasChange("tenant_id") {
d.Set("tenant_id", p.TenantID)
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", p.TenantID)
} else {
d.Set("tenant_id", "")
}
if _, exists := d.GetOk("address"); exists {
if d.HasChange("address") {
d.Set("address", p.Address)
}
if t, exists := d.GetOk("address"); exists && t != "" {
d.Set("address", p.Address)
} else {
d.Set("address", "")
}
if _, exists := d.GetOk("description"); exists {
if d.HasChange("description") {
d.Set("description", p.Description)
}
if t, exists := d.GetOk("description"); exists && t != "" {
d.Set("description", p.Description)
} else {
d.Set("description", "")
}
if _, exists := d.GetOk("persistence"); exists {
if d.HasChange("persistence") {
if t, exists := d.GetOk("persistence"); exists && t != "" {
d.Set("persistence", p.Description)
}
}
if _, exists := d.GetOk("conn_limit"); exists {
if d.HasChange("conn_limit") {
d.Set("conn_limit", p.ConnLimit)
}
if t, exists := d.GetOk("conn_limit"); exists && t != "" {
d.Set("conn_limit", p.ConnLimit)
} else {
d.Set("conn_limit", "")
}
if _, exists := d.GetOk("admin_state_up"); exists {
if d.HasChange("admin_state_up") {
d.Set("admin_state_up", strconv.FormatBool(p.AdminStateUp))
}
if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
d.Set("admin_state_up", strconv.FormatBool(p.AdminStateUp))
} else {
d.Set("admin_state_up", "")
}

View File

@ -23,6 +23,7 @@ func resourceNetworkingNetworkV2() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
},
"name": &schema.Schema{
Type: schema.TypeString,
@ -110,34 +111,26 @@ func resourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) e
d.Set("region", d.Get("region").(string))
if _, exists := d.GetOk("name"); exists {
if d.HasChange("name") {
d.Set("name", n.Name)
}
if t, exists := d.GetOk("name"); exists && t != ""{
d.Set("name", n.Name)
} else {
d.Set("name", "")
}
if _, exists := d.GetOk("admin_state_up"); exists {
if d.HasChange("admin_state_up") {
d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp))
}
if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp))
} else {
d.Set("admin_state_up", "")
}
if _, exists := d.GetOk("shared"); exists {
if d.HasChange("shared") {
d.Set("shared", strconv.FormatBool(n.Shared))
}
if t, exists := d.GetOk("shared"); exists && t != "" {
d.Set("shared", strconv.FormatBool(n.Shared))
} else {
d.Set("shared", "")
}
if _, exists := d.GetOk("tenant_id"); exists {
if d.HasChange("tenant_id") {
d.Set("tenant_id", n.TenantID)
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", n.TenantID)
} else {
d.Set("tenant_id", "")
}

View File

@ -24,6 +24,7 @@ func resourceNetworkingSubnetV2() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
},
"network_id": &schema.Schema{
Type: schema.TypeString,
@ -170,18 +171,14 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
d.Set("cidr", s.CIDR)
d.Set("ip_version", s.IPVersion)
if _, exists := d.GetOk("name"); exists {
if d.HasChange("name") {
d.Set("name", s.Name)
}
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", s.Name)
} else {
d.Set("name", "")
}
if _, exists := d.GetOk("tenant_id"); exists {
if d.HasChange("tenant_id") {
d.Set("tenant_id", s.Name)
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", s.TenantID)
} else {
d.Set("tenant_id", "")
}
@ -190,18 +187,14 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
d.Set("allocation_pools", s.AllocationPools)
}
if _, exists := d.GetOk("gateway_ip"); exists {
if d.HasChange("gateway_ip") {
d.Set("gateway_ip", s.Name)
}
if t, exists := d.GetOk("gateway_ip"); exists && t != "" {
d.Set("gateway_ip", s.GatewayIP)
} else {
d.Set("gateway_ip", "")
}
if _, exists := d.GetOk("enable_dhcp"); exists {
if d.HasChange("enable_dhcp") {
d.Set("enable_dhcp", strconv.FormatBool(s.EnableDHCP))
}
if t, exists := d.GetOk("enable_dhcp"); exists && t != "" {
d.Set("enable_dhcp", strconv.FormatBool(s.EnableDHCP))
} else {
d.Set("enable_dhcp", "")
}