Adding default security group id attribute reference on creation of VPC. Fixes issue #466.

This commit is contained in:
Yahya Poonawala 2014-12-23 11:43:33 +05:30
parent 634984532d
commit 7860dc1ef6
1 changed files with 23 additions and 0 deletions

View File

@ -52,6 +52,12 @@ func resourceAwsVpc() *schema.Resource {
Computed: true,
},
"default_security_group_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"tags": tagsSchema(),
},
}
@ -145,6 +151,7 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
}
resourceAwsVpcSetDefaultNetworkAcl(ec2conn, d)
resourceAwsVpcSetDefaultSecurityGroup(ec2conn, d)
return nil
}
@ -252,3 +259,19 @@ func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) e
return nil
}
func resourceAwsVpcSetDefaultSecurityGroup(conn *ec2.EC2, d *schema.ResourceData) error {
filter := ec2.NewFilter()
filter.Add("group-name", "default")
filter.Add("vpc-id", d.Id())
securityGroupResp, err := conn.SecurityGroups(nil, filter)
if err != nil {
return err
}
if v := securityGroupResp.Groups; len(v) > 0 {
d.Set("default_security_group_id", v[0].Id)
}
return nil
}