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, 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,
@ -226,16 +227,19 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err
d.Set("metadata", server.Metadata) d.Set("metadata", server.Metadata)
secGrpNum := 0
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 getting 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) d.Set(fmt.Sprintf("security_groups.%d", secGrpNum), sg.Name)
secGrpNum++
} }
return true, nil return true, nil
}) })
d.Set("security_groups.#", secGrpNum)
newFlavor, ok := server.Flavor["id"].(string) newFlavor, ok := server.Flavor["id"].(string)
if !ok { if !ok {

View File

@ -20,6 +20,7 @@ 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,6 +22,7 @@ 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

@ -102,10 +102,8 @@ func resourceLBMemberV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("port", p.ProtocolPort) d.Set("port", p.ProtocolPort)
d.Set("pool_id", p.PoolID) d.Set("pool_id", p.PoolID)
if _, exists := d.GetOk("tenant_id"); exists { if t, exists := d.GetOk("tenant_id"); exists && t != "" {
if d.HasChange("tenant_id") {
d.Set("tenant_id", p.TenantID) d.Set("tenant_id", p.TenantID)
}
} else { } else {
d.Set("tenant_id", "") 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("timeout", m.Timeout)
d.Set("max_retries", m.MaxRetries) d.Set("max_retries", m.MaxRetries)
if _, exists := d.GetOk("tenant_id"); exists { if t, exists := d.GetOk("tenant_id"); exists && t != "" {
if d.HasChange("tenant_id") {
d.Set("tenant_id", m.TenantID) d.Set("tenant_id", m.TenantID)
}
} else { } else {
d.Set("tenant_id", "") d.Set("tenant_id", "")
} }
if _, exists := d.GetOk("url_path"); exists { if t, exists := d.GetOk("url_path"); exists && t != "" {
if d.HasChange("url_path") {
d.Set("url_path", m.URLPath) d.Set("url_path", m.URLPath)
}
} else { } else {
d.Set("url_path", "") d.Set("url_path", "")
} }
if _, exists := d.GetOk("http_method"); exists { if t, exists := d.GetOk("http_method"); exists && t != "" {
if d.HasChange("http_method") {
d.Set("http_method", m.HTTPMethod) d.Set("http_method", m.HTTPMethod)
}
} else { } else {
d.Set("http_method", "") d.Set("http_method", "")
} }
if _, exists := d.GetOk("expected_codes"); exists { if t, exists := d.GetOk("expected_codes"); exists && t != "" {
if d.HasChange("expected_codes") {
d.Set("expected_codes", m.ExpectedCodes) d.Set("expected_codes", m.ExpectedCodes)
}
} else { } else {
d.Set("expected_codes", "") d.Set("expected_codes", "")
} }
if _, exists := d.GetOk("admin_state_up"); exists { if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
if d.HasChange("admin_state_up") {
d.Set("admin_state_up", strconv.FormatBool(m.AdminStateUp)) d.Set("admin_state_up", strconv.FormatBool(m.AdminStateUp))
}
} else { } else {
d.Set("admin_state_up", "") 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("subnet_id", p.SubnetID)
d.Set("lb_method", p.LBMethod) d.Set("lb_method", p.LBMethod)
if _, exists := d.GetOk("tenant_id"); exists { if t, exists := d.GetOk("tenant_id"); exists && t != "" {
if d.HasChange("tenant_id") {
d.Set("tenant_id", p.TenantID) d.Set("tenant_id", p.TenantID)
}
} else { } else {
d.Set("tenant_id", "") 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("port", p.ProtocolPort)
d.Set("pool_id", p.PoolID) d.Set("pool_id", p.PoolID)
if _, exists := d.GetOk("tenant_id"); exists { if t, exists := d.GetOk("tenant_id"); exists && t != "" {
if d.HasChange("tenant_id") {
d.Set("tenant_id", p.TenantID) d.Set("tenant_id", p.TenantID)
}
} else { } else {
d.Set("tenant_id", "") d.Set("tenant_id", "")
} }
if _, exists := d.GetOk("address"); exists { if t, exists := d.GetOk("address"); exists && t != "" {
if d.HasChange("address") {
d.Set("address", p.Address) d.Set("address", p.Address)
}
} else { } else {
d.Set("address", "") d.Set("address", "")
} }
if _, exists := d.GetOk("description"); exists { if t, exists := d.GetOk("description"); exists && t != "" {
if d.HasChange("description") {
d.Set("description", p.Description) d.Set("description", p.Description)
}
} else { } else {
d.Set("description", "") d.Set("description", "")
} }
if _, exists := d.GetOk("persistence"); exists { if t, exists := d.GetOk("persistence"); exists && t != "" {
if d.HasChange("persistence") {
d.Set("persistence", p.Description) d.Set("persistence", p.Description)
} }
}
if _, exists := d.GetOk("conn_limit"); exists { if t, exists := d.GetOk("conn_limit"); exists && t != "" {
if d.HasChange("conn_limit") {
d.Set("conn_limit", p.ConnLimit) d.Set("conn_limit", p.ConnLimit)
}
} else { } else {
d.Set("conn_limit", "") d.Set("conn_limit", "")
} }
if _, exists := d.GetOk("admin_state_up"); exists { if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
if d.HasChange("admin_state_up") {
d.Set("admin_state_up", strconv.FormatBool(p.AdminStateUp)) d.Set("admin_state_up", strconv.FormatBool(p.AdminStateUp))
}
} else { } else {
d.Set("admin_state_up", "") d.Set("admin_state_up", "")
} }

View File

@ -23,6 +23,7 @@ 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,
@ -110,34 +111,26 @@ func resourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) e
d.Set("region", d.Get("region").(string)) d.Set("region", d.Get("region").(string))
if _, exists := d.GetOk("name"); exists { if t, exists := d.GetOk("name"); exists && t != ""{
if d.HasChange("name") {
d.Set("name", n.Name) d.Set("name", n.Name)
}
} else { } else {
d.Set("name", "") d.Set("name", "")
} }
if _, exists := d.GetOk("admin_state_up"); exists { if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
if d.HasChange("admin_state_up") {
d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp)) d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp))
}
} else { } else {
d.Set("admin_state_up", "") d.Set("admin_state_up", "")
} }
if _, exists := d.GetOk("shared"); exists { if t, exists := d.GetOk("shared"); exists && t != "" {
if d.HasChange("shared") {
d.Set("shared", strconv.FormatBool(n.Shared)) d.Set("shared", strconv.FormatBool(n.Shared))
}
} else { } else {
d.Set("shared", "") d.Set("shared", "")
} }
if _, exists := d.GetOk("tenant_id"); exists { if t, exists := d.GetOk("tenant_id"); exists && t != "" {
if d.HasChange("tenant_id") {
d.Set("tenant_id", n.TenantID) d.Set("tenant_id", n.TenantID)
}
} else { } else {
d.Set("tenant_id", "") d.Set("tenant_id", "")
} }

View File

@ -24,6 +24,7 @@ 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,
@ -170,18 +171,14 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
d.Set("cidr", s.CIDR) d.Set("cidr", s.CIDR)
d.Set("ip_version", s.IPVersion) d.Set("ip_version", s.IPVersion)
if _, exists := d.GetOk("name"); exists { if t, exists := d.GetOk("name"); exists && t != "" {
if d.HasChange("name") {
d.Set("name", s.Name) d.Set("name", s.Name)
}
} else { } else {
d.Set("name", "") d.Set("name", "")
} }
if _, exists := d.GetOk("tenant_id"); exists { if t, exists := d.GetOk("tenant_id"); exists && t != "" {
if d.HasChange("tenant_id") { d.Set("tenant_id", s.TenantID)
d.Set("tenant_id", s.Name)
}
} else { } else {
d.Set("tenant_id", "") d.Set("tenant_id", "")
} }
@ -190,18 +187,14 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
d.Set("allocation_pools", s.AllocationPools) d.Set("allocation_pools", s.AllocationPools)
} }
if _, exists := d.GetOk("gateway_ip"); exists { if t, exists := d.GetOk("gateway_ip"); exists && t != "" {
if d.HasChange("gateway_ip") { d.Set("gateway_ip", s.GatewayIP)
d.Set("gateway_ip", s.Name)
}
} else { } else {
d.Set("gateway_ip", "") d.Set("gateway_ip", "")
} }
if _, exists := d.GetOk("enable_dhcp"); exists { if t, exists := d.GetOk("enable_dhcp"); exists && t != "" {
if d.HasChange("enable_dhcp") {
d.Set("enable_dhcp", strconv.FormatBool(s.EnableDHCP)) d.Set("enable_dhcp", strconv.FormatBool(s.EnableDHCP))
}
} else { } else {
d.Set("enable_dhcp", "") d.Set("enable_dhcp", "")
} }