Allows "self" to be discovered and recorded correctly.

This commit is contained in:
Joe Topjian 2015-03-04 04:41:15 +00:00 committed by Jon Perritt
parent ba880b136b
commit f5feb7fbbb
1 changed files with 12 additions and 2 deletions

View File

@ -72,6 +72,7 @@ func resourceComputeSecGroupV2() *schema.Resource {
"self": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: false,
},
},
@ -126,8 +127,16 @@ func resourceComputeSecGroupV2Read(d *schema.ResourceData, meta interface{}) err
d.Set("region", d.Get("region").(string))
d.Set("name", sg.Name)
d.Set("description", sg.Description)
log.Printf("[DEBUG] rulesToMap(sg.Rules): %+v", rulesToMap(sg.Rules))
d.Set("rule", rulesToMap(sg.Rules))
rtm := rulesToMap(sg.Rules)
for _, v := range rtm {
if v["group"] == d.Get("name") {
v["self"] = "1"
} else {
v["self"] = "0"
}
}
log.Printf("[DEBUG] rulesToMap(sg.Rules): %+v", rtm)
d.Set("rule", rtm)
return nil
}
@ -267,6 +276,7 @@ func rulesToMap(sgrs []secgroups.Rule) []map[string]interface{} {
"to_port": sgr.ToPort,
"ip_protocol": sgr.IPProtocol,
"cidr": sgr.IPRange.CIDR,
"group": sgr.Group.Name,
}
}
return sgrMap