Merge pull request #704 from yahyapo/master

[AWS] Adding default network ACL ID and default security group ID to VPC reference attributes
This commit is contained in:
Armon Dadgar 2015-01-06 10:29:16 -08:00
commit 0ffc11c885
2 changed files with 49 additions and 0 deletions

View File

@ -47,6 +47,17 @@ func resourceAwsVpc() *schema.Resource {
Computed: true,
},
"default_network_acl_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"default_security_group_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"tags": tagsSchema(),
},
}
@ -139,6 +150,9 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
d.Set("main_route_table_id", v[0].RouteTableId)
}
resourceAwsVpcSetDefaultNetworkAcl(ec2conn, d)
resourceAwsVpcSetDefaultSecurityGroup(ec2conn, d)
return nil
}
@ -228,3 +242,36 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
return vpc, vpc.State, nil
}
}
func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) error {
filter := ec2.NewFilter()
filter.Add("default", "true")
filter.Add("vpc-id", d.Id())
networkAclResp, err := conn.NetworkAcls(nil, filter)
if err != nil {
return err
}
if v := networkAclResp.NetworkAcls; len(v) > 0 {
d.Set("default_network_acl_id", v[0].NetworkAclId)
}
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
}

View File

@ -54,3 +54,5 @@ The following attributes are exported:
* `enable_dns_hostnames` - Whether or not the VPC has DNS hostname support
* `main_route_table_id` - The ID of the main route table associated with
this VPC.
* `default_network_acl_id` - The ID of the network ACL created by default on VPC creation
* `default_security_group_id` - The ID of the security group created by default on VPC creation