Use d.GetOk to populate data in read operations

This commit is contained in:
Guillaume Giamarchi 2015-02-18 01:27:45 +01:00 committed by Jon Perritt
parent ed31588b84
commit 1efaaeeca6
3 changed files with 106 additions and 18 deletions

View File

@ -118,11 +118,35 @@ func resourceFirewallRead(d *schema.ResourceData, meta interface{}) error {
return err
}
d.Set("name", firewall.Name)
d.Set("description", firewall.Description)
d.Set("policy_id", firewall.PolicyID)
d.Set("admin_state_up", firewall.AdminStateUp)
d.Set("tenant_id", firewall.TenantID)
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", firewall.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("description"); exists && t != "" {
d.Set("description", firewall.Description)
} else {
d.Set("description", "")
}
if t, exists := d.GetOk("policy_id"); exists && t != "" {
d.Set("policy_id", firewall.PolicyID)
} else {
d.Set("policy_id", "")
}
if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
d.Set("admin_state_up", firewall.AdminStateUp)
} else {
d.Set("admin_state_up", "")
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", firewall.TenantID)
} else {
d.Set("tenant_id", "")
}
return nil
}

View File

@ -130,11 +130,35 @@ func resourceFirewallPolicyRead(d *schema.ResourceData, meta interface{}) error
return err
}
d.Set("name", policy.Name)
d.Set("description", policy.Description)
d.Set("shared", policy.Shared)
d.Set("audited", policy.Audited)
d.Set("tenant_id", policy.TenantID)
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", policy.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("description"); exists && t != "" {
d.Set("description", policy.Description)
} else {
d.Set("description", "")
}
if t, exists := d.GetOk("shared"); exists && t != "" {
d.Set("shared", policy.Shared)
} else {
d.Set("shared", "")
}
if t, exists := d.GetOk("audited"); exists && t != "" {
d.Set("audited", policy.Audited)
} else {
d.Set("audited", "")
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", policy.TenantID)
} else {
d.Set("tenant_id", "")
}
return nil
}

View File

@ -137,16 +137,56 @@ func resourceFirewallRuleRead(d *schema.ResourceData, meta interface{}) error {
return err
}
d.Set("name", rule.Name)
d.Set("description", rule.Description)
d.Set("protocol", rule.Protocol)
d.Set("action", rule.Action)
d.Set("ip_version", rule.IPVersion)
d.Set("source_ip_address", rule.SourceIPAddress)
d.Set("destination_ip_address", rule.DestinationIPAddress)
d.Set("source_port", rule.SourcePort)
d.Set("destination_port", rule.DestinationPort)
d.Set("enabled", rule.Enabled)
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", rule.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("description"); exists && t != "" {
d.Set("description", rule.Description)
} else {
d.Set("description", "")
}
if t, exists := d.GetOk("ip_version"); exists && t != "" {
d.Set("ip_version", rule.IPVersion)
} else {
d.Set("ip_version", "")
}
if t, exists := d.GetOk("source_ip_address"); exists && t != "" {
d.Set("source_ip_address", rule.SourceIPAddress)
} else {
d.Set("source_ip_address", "")
}
if t, exists := d.GetOk("destination_ip_address"); exists && t != "" {
d.Set("destination_ip_address", rule.DestinationIPAddress)
} else {
d.Set("destination_ip_address", "")
}
if t, exists := d.GetOk("source_port"); exists && t != "" {
d.Set("source_port", rule.SourcePort)
} else {
d.Set("source_port", "")
}
if t, exists := d.GetOk("destination_port"); exists && t != "" {
d.Set("destination_port", rule.DestinationPort)
} else {
d.Set("destination_port", "")
}
if t, exists := d.GetOk("enabled"); exists && t != "" {
d.Set("enabled", rule.Enabled)
} else {
d.Set("enabled", "")
}
return nil
}