providers/aws: ingress and egress rules
This commit is contained in:
parent
1277c324d0
commit
637d68140c
|
@ -37,14 +37,20 @@ func resource_aws_security_group_create(
|
||||||
group := createResp.SecurityGroup
|
group := createResp.SecurityGroup
|
||||||
|
|
||||||
log.Printf("[INFO] Security Group ID: %s", rs.ID)
|
log.Printf("[INFO] Security Group ID: %s", rs.ID)
|
||||||
|
ingressRules := []ec2.IPPerm{}
|
||||||
|
egressRules := []ec2.IPPerm{}
|
||||||
|
|
||||||
// Expand the "ingress" array to goamz compat []ec2.IPPerm
|
// Expand the "ingress" array to goamz compat []ec2.IPPerm
|
||||||
v := flatmap.Expand(rs.Attributes, "ingress").([]interface{})
|
v, ok := flatmap.Expand(rs.Attributes, "ingress").([]interface{})
|
||||||
ingressRules := expandIPPerms(v)
|
if ok {
|
||||||
|
ingressRules = expandIPPerms(v)
|
||||||
|
}
|
||||||
|
|
||||||
// Expand the "egress" array to goamz compat []ec2.IPPerm
|
// Expand the "egress" array to goamz compat []ec2.IPPerm
|
||||||
v = flatmap.Expand(rs.Attributes, "egress").([]interface{})
|
v, ok = flatmap.Expand(rs.Attributes, "egress").([]interface{})
|
||||||
egressRules := expandIPPerms(v)
|
if ok {
|
||||||
|
egressRules = expandIPPerms(v)
|
||||||
|
}
|
||||||
|
|
||||||
if len(egressRules) > 0 {
|
if len(egressRules) > 0 {
|
||||||
_, err = ec2conn.AuthorizeSecurityGroupEgress(group, egressRules)
|
_, err = ec2conn.AuthorizeSecurityGroupEgress(group, egressRules)
|
||||||
|
@ -53,7 +59,7 @@ func resource_aws_security_group_create(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(egressRules) > 0 {
|
if len(ingressRules) > 0 {
|
||||||
_, err = ec2conn.AuthorizeSecurityGroup(group, ingressRules)
|
_, err = ec2conn.AuthorizeSecurityGroup(group, ingressRules)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rs, fmt.Errorf("Error authorizing security group ingress rules: %s", err)
|
return rs, fmt.Errorf("Error authorizing security group ingress rules: %s", err)
|
||||||
|
@ -126,6 +132,8 @@ func resource_aws_security_group_diff(
|
||||||
"name": diff.AttrTypeCreate,
|
"name": diff.AttrTypeCreate,
|
||||||
"description": diff.AttrTypeCreate,
|
"description": diff.AttrTypeCreate,
|
||||||
"vpc_id": diff.AttrTypeUpdate,
|
"vpc_id": diff.AttrTypeUpdate,
|
||||||
|
"ingress": diff.AttrTypeUpdate,
|
||||||
|
"egress": diff.AttrTypeUpdate,
|
||||||
},
|
},
|
||||||
|
|
||||||
ComputedAttrs: []string{
|
ComputedAttrs: []string{
|
||||||
|
@ -140,8 +148,6 @@ func resource_aws_security_group_update_state(
|
||||||
s *terraform.ResourceState,
|
s *terraform.ResourceState,
|
||||||
sg *ec2.SecurityGroupInfo) (*terraform.ResourceState, error) {
|
sg *ec2.SecurityGroupInfo) (*terraform.ResourceState, error) {
|
||||||
|
|
||||||
log.Println(sg)
|
|
||||||
|
|
||||||
s.Attributes["description"] = sg.Description
|
s.Attributes["description"] = sg.Description
|
||||||
s.Attributes["name"] = sg.Name
|
s.Attributes["name"] = sg.Name
|
||||||
s.Attributes["vpc_id"] = sg.VpcId
|
s.Attributes["vpc_id"] = sg.VpcId
|
||||||
|
|
|
@ -3,7 +3,6 @@ package aws
|
||||||
import (
|
import (
|
||||||
"github.com/mitchellh/goamz/ec2"
|
"github.com/mitchellh/goamz/ec2"
|
||||||
"github.com/mitchellh/goamz/elb"
|
"github.com/mitchellh/goamz/elb"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Takes the result of flatmap.Expand for an array of listeners and
|
// Takes the result of flatmap.Expand for an array of listeners and
|
||||||
|
@ -38,17 +37,18 @@ func expandIPPerms(configured []interface{}) []ec2.IPPerm {
|
||||||
// an array of goamz/ec2 compatabile objects
|
// an array of goamz/ec2 compatabile objects
|
||||||
for _, perm := range configured {
|
for _, perm := range configured {
|
||||||
newP := perm.(map[string]interface{})
|
newP := perm.(map[string]interface{})
|
||||||
log.Println(newP)
|
|
||||||
|
|
||||||
// Loop over the array of sg ids and built
|
// Loop over the array of sg ids and built
|
||||||
// compatibile goamz objects
|
// compatibile goamz objects
|
||||||
groups := expandStringList(newP["security_groups"].([]interface{}))
|
expandedGroups := []ec2.UserSecurityGroup{}
|
||||||
expandedGroups := make([]ec2.UserSecurityGroup, 0, len(groups))
|
configGroups, ok := newP["security_groups"].([]interface{})
|
||||||
for _, g := range groups {
|
if ok {
|
||||||
newG := ec2.UserSecurityGroup{
|
gs := expandStringList(configGroups)
|
||||||
Id: g,
|
for _, g := range gs {
|
||||||
|
newG := ec2.UserSecurityGroup{
|
||||||
|
Id: g,
|
||||||
|
}
|
||||||
|
expandedGroups = append(expandedGroups, newG)
|
||||||
}
|
}
|
||||||
expandedGroups = append(expandedGroups, newG)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the permission objet
|
// Create the permission objet
|
||||||
|
|
Loading…
Reference in New Issue