provider/aws: Convert AWS Network ACL to aws-sdk-go
This commit is contained in:
parent
70a989a23e
commit
bd591877fe
|
@ -2,11 +2,14 @@ package aws
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
)
|
||||
|
||||
func expandNetworkAclEntries(configured []interface{}, entryType string) ([]ec2.NetworkAclEntry, error) {
|
||||
entries := make([]ec2.NetworkAclEntry, 0, len(configured))
|
||||
func expandNetworkAclEntries(configured []interface{}, entryType string) ([]ec2.NetworkACLEntry, error) {
|
||||
entries := make([]ec2.NetworkACLEntry, 0, len(configured))
|
||||
for _, eRaw := range configured {
|
||||
data := eRaw.(map[string]interface{})
|
||||
protocol := data["protocol"].(string)
|
||||
|
@ -15,16 +18,16 @@ func expandNetworkAclEntries(configured []interface{}, entryType string) ([]ec2.
|
|||
return nil, fmt.Errorf("Invalid Protocol %s for rule %#v", protocol, data)
|
||||
}
|
||||
p := extractProtocolInteger(data["protocol"].(string))
|
||||
e := ec2.NetworkAclEntry{
|
||||
Protocol: p,
|
||||
PortRange: ec2.PortRange{
|
||||
From: data["from_port"].(int),
|
||||
To: data["to_port"].(int),
|
||||
e := ec2.NetworkACLEntry{
|
||||
Protocol: aws.String(strconv.Itoa(p)),
|
||||
PortRange: &ec2.PortRange{
|
||||
From: aws.Integer(data["from_port"].(int)),
|
||||
To: aws.Integer(data["to_port"].(int)),
|
||||
},
|
||||
Egress: (entryType == "egress"),
|
||||
RuleAction: data["action"].(string),
|
||||
RuleNumber: data["rule_no"].(int),
|
||||
CidrBlock: data["cidr_block"].(string),
|
||||
Egress: aws.Boolean((entryType == "egress")),
|
||||
RuleAction: aws.String(data["action"].(string)),
|
||||
RuleNumber: aws.Integer(data["rule_no"].(int)),
|
||||
CIDRBlock: aws.String(data["cidr_block"].(string)),
|
||||
}
|
||||
entries = append(entries, e)
|
||||
}
|
||||
|
@ -33,17 +36,17 @@ func expandNetworkAclEntries(configured []interface{}, entryType string) ([]ec2.
|
|||
|
||||
}
|
||||
|
||||
func flattenNetworkAclEntries(list []ec2.NetworkAclEntry) []map[string]interface{} {
|
||||
func flattenNetworkAclEntries(list []ec2.NetworkACLEntry) []map[string]interface{} {
|
||||
entries := make([]map[string]interface{}, 0, len(list))
|
||||
|
||||
for _, entry := range list {
|
||||
entries = append(entries, map[string]interface{}{
|
||||
"from_port": entry.PortRange.From,
|
||||
"to_port": entry.PortRange.To,
|
||||
"action": entry.RuleAction,
|
||||
"rule_no": entry.RuleNumber,
|
||||
"protocol": extractProtocolString(entry.Protocol),
|
||||
"cidr_block": entry.CidrBlock,
|
||||
"from_port": *entry.PortRange.From,
|
||||
"to_port": *entry.PortRange.To,
|
||||
"action": *entry.RuleAction,
|
||||
"rule_no": *entry.RuleNumber,
|
||||
"protocol": *entry.Protocol,
|
||||
"cidr_block": *entry.CIDRBlock,
|
||||
})
|
||||
}
|
||||
return entries
|
||||
|
|
|
@ -4,10 +4,11 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
)
|
||||
|
||||
func Test_expandNetworkAclEntry(t *testing.T) {
|
||||
func Test_expandNetworkACLEntry(t *testing.T) {
|
||||
input := []interface{}{
|
||||
map[string]interface{}{
|
||||
"protocol": "tcp",
|
||||
|
@ -28,30 +29,36 @@ func Test_expandNetworkAclEntry(t *testing.T) {
|
|||
}
|
||||
expanded, _ := expandNetworkAclEntries(input, "egress")
|
||||
|
||||
expected := []ec2.NetworkAclEntry{
|
||||
ec2.NetworkAclEntry{
|
||||
Protocol: 6,
|
||||
PortRange: ec2.PortRange{
|
||||
From: 22,
|
||||
To: 22,
|
||||
expected := []ec2.NetworkACLEntry{
|
||||
ec2.NetworkACLEntry{
|
||||
Protocol: aws.String("tcp"),
|
||||
PortRange: &ec2.PortRange{
|
||||
From: aws.Integer(22),
|
||||
To: aws.Integer(22),
|
||||
},
|
||||
RuleAction: aws.String("deny"),
|
||||
RuleNumber: aws.Integer(1),
|
||||
CIDRBlock: aws.String("0.0.0.0/0"),
|
||||
Egress: aws.Boolean(true),
|
||||
ICMPTypeCode: &ec2.ICMPTypeCode{
|
||||
Code: aws.Integer(0),
|
||||
Type: aws.Integer(0),
|
||||
},
|
||||
RuleAction: "deny",
|
||||
RuleNumber: 1,
|
||||
CidrBlock: "0.0.0.0/0",
|
||||
Egress: true,
|
||||
IcmpCode: ec2.IcmpCode{Code: 0, Type: 0},
|
||||
},
|
||||
ec2.NetworkAclEntry{
|
||||
Protocol: 6,
|
||||
PortRange: ec2.PortRange{
|
||||
From: 443,
|
||||
To: 443,
|
||||
ec2.NetworkACLEntry{
|
||||
Protocol: aws.String("tcp"),
|
||||
PortRange: &ec2.PortRange{
|
||||
From: aws.Integer(443),
|
||||
To: aws.Integer(443),
|
||||
},
|
||||
RuleAction: aws.String("deny"),
|
||||
RuleNumber: aws.Integer(2),
|
||||
CIDRBlock: aws.String("0.0.0.0/0"),
|
||||
Egress: aws.Boolean(true),
|
||||
ICMPTypeCode: &ec2.ICMPTypeCode{
|
||||
Code: aws.Integer(0),
|
||||
Type: aws.Integer(0),
|
||||
},
|
||||
RuleAction: "deny",
|
||||
RuleNumber: 2,
|
||||
CidrBlock: "0.0.0.0/0",
|
||||
Egress: true,
|
||||
IcmpCode: ec2.IcmpCode{Code: 0, Type: 0},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -64,28 +71,28 @@ func Test_expandNetworkAclEntry(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func Test_flattenNetworkAclEntry(t *testing.T) {
|
||||
func Test_flattenNetworkACLEntry(t *testing.T) {
|
||||
|
||||
apiInput := []ec2.NetworkAclEntry{
|
||||
ec2.NetworkAclEntry{
|
||||
Protocol: 6,
|
||||
PortRange: ec2.PortRange{
|
||||
From: 22,
|
||||
To: 22,
|
||||
apiInput := []ec2.NetworkACLEntry{
|
||||
ec2.NetworkACLEntry{
|
||||
Protocol: aws.String("tcp"),
|
||||
PortRange: &ec2.PortRange{
|
||||
From: aws.Integer(22),
|
||||
To: aws.Integer(22),
|
||||
},
|
||||
RuleAction: "deny",
|
||||
RuleNumber: 1,
|
||||
CidrBlock: "0.0.0.0/0",
|
||||
RuleAction: aws.String("deny"),
|
||||
RuleNumber: aws.Integer(1),
|
||||
CIDRBlock: aws.String("0.0.0.0/0"),
|
||||
},
|
||||
ec2.NetworkAclEntry{
|
||||
Protocol: 6,
|
||||
PortRange: ec2.PortRange{
|
||||
From: 443,
|
||||
To: 443,
|
||||
ec2.NetworkACLEntry{
|
||||
Protocol: aws.String("tcp"),
|
||||
PortRange: &ec2.PortRange{
|
||||
From: aws.Integer(443),
|
||||
To: aws.Integer(443),
|
||||
},
|
||||
RuleAction: "deny",
|
||||
RuleNumber: 2,
|
||||
CidrBlock: "0.0.0.0/0",
|
||||
RuleAction: aws.String("deny"),
|
||||
RuleNumber: aws.Integer(2),
|
||||
CIDRBlock: aws.String("0.0.0.0/0"),
|
||||
},
|
||||
}
|
||||
flattened := flattenNetworkAclEntries(apiInput)
|
||||
|
|
|
@ -6,10 +6,11 @@ import (
|
|||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
)
|
||||
|
||||
func resourceAwsNetworkAcl() *schema.Resource {
|
||||
|
@ -108,32 +109,34 @@ func resourceAwsNetworkAcl() *schema.Resource {
|
|||
|
||||
func resourceAwsNetworkAclCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
||||
|
||||
// Create the Network Acl
|
||||
createOpts := &ec2.CreateNetworkAcl{
|
||||
VpcId: d.Get("vpc_id").(string),
|
||||
createOpts := &ec2.CreateNetworkACLRequest{
|
||||
VPCID: aws.String(d.Get("vpc_id").(string)),
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Network Acl create config: %#v", createOpts)
|
||||
resp, err := ec2conn.CreateNetworkAcl(createOpts)
|
||||
resp, err := ec2conn.CreateNetworkACL(createOpts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating network acl: %s", err)
|
||||
}
|
||||
|
||||
// Get the ID and store it
|
||||
networkAcl := &resp.NetworkAcl
|
||||
d.SetId(networkAcl.NetworkAclId)
|
||||
log.Printf("[INFO] Network Acl ID: %s", networkAcl.NetworkAclId)
|
||||
networkAcl := resp.NetworkACL
|
||||
d.SetId(*networkAcl.NetworkACLID)
|
||||
log.Printf("[INFO] Network Acl ID: %s", *networkAcl.NetworkACLID)
|
||||
|
||||
// Update rules and subnet association once acl is created
|
||||
return resourceAwsNetworkAclUpdate(d, meta)
|
||||
}
|
||||
|
||||
func resourceAwsNetworkAclRead(d *schema.ResourceData, meta interface{}) error {
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
||||
|
||||
resp, err := ec2conn.NetworkAcls([]string{d.Id()}, ec2.NewFilter())
|
||||
resp, err := ec2conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{d.Id()},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -142,29 +145,29 @@ func resourceAwsNetworkAclRead(d *schema.ResourceData, meta interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
networkAcl := &resp.NetworkAcls[0]
|
||||
var ingressEntries []ec2.NetworkAclEntry
|
||||
var egressEntries []ec2.NetworkAclEntry
|
||||
networkAcl := &resp.NetworkACLs[0]
|
||||
var ingressEntries []ec2.NetworkACLEntry
|
||||
var egressEntries []ec2.NetworkACLEntry
|
||||
|
||||
// separate the ingress and egress rules
|
||||
for _, e := range networkAcl.EntrySet {
|
||||
if e.Egress == true {
|
||||
for _, e := range networkAcl.Entries {
|
||||
if *e.Egress == true {
|
||||
egressEntries = append(egressEntries, e)
|
||||
} else {
|
||||
ingressEntries = append(ingressEntries, e)
|
||||
}
|
||||
}
|
||||
|
||||
d.Set("vpc_id", networkAcl.VpcId)
|
||||
d.Set("vpc_id", networkAcl.VPCID)
|
||||
d.Set("ingress", ingressEntries)
|
||||
d.Set("egress", egressEntries)
|
||||
d.Set("tags", tagsToMap(networkAcl.Tags))
|
||||
d.Set("tags", tagsToMapSDK(networkAcl.Tags))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
||||
d.Partial(true)
|
||||
|
||||
if d.HasChange("ingress") {
|
||||
|
@ -190,13 +193,16 @@ func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error
|
|||
if err != nil {
|
||||
return fmt.Errorf("Failed to update acl %s with subnet %s: %s", d.Id(), newSubnet, err)
|
||||
}
|
||||
_, err = ec2conn.ReplaceNetworkAclAssociation(association.NetworkAclAssociationId, d.Id())
|
||||
_, err = ec2conn.ReplaceNetworkACLAssociation(&ec2.ReplaceNetworkACLAssociationRequest{
|
||||
AssociationID: association.NetworkACLAssociationID,
|
||||
NetworkACLID: aws.String(d.Id()),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := setTags(ec2conn, d); err != nil {
|
||||
if err := setTagsSDK(ec2conn, d); err != nil {
|
||||
return err
|
||||
} else {
|
||||
d.SetPartial("tags")
|
||||
|
@ -226,7 +232,11 @@ func updateNetworkAclEntries(d *schema.ResourceData, entryType string, ec2conn *
|
|||
}
|
||||
for _, remove := range toBeDeleted {
|
||||
// Delete old Acl
|
||||
_, err := ec2conn.DeleteNetworkAclEntry(d.Id(), remove.RuleNumber, remove.Egress)
|
||||
err := ec2conn.DeleteNetworkACLEntry(&ec2.DeleteNetworkACLEntryRequest{
|
||||
NetworkACLID: aws.String(d.Id()),
|
||||
RuleNumber: remove.RuleNumber,
|
||||
Egress: remove.Egress,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting %s entry: %s", entryType, err)
|
||||
}
|
||||
|
@ -238,7 +248,15 @@ func updateNetworkAclEntries(d *schema.ResourceData, entryType string, ec2conn *
|
|||
}
|
||||
for _, add := range toBeCreated {
|
||||
// Add new Acl entry
|
||||
_, err := ec2conn.CreateNetworkAclEntry(d.Id(), &add)
|
||||
err := ec2conn.CreateNetworkACLEntry(&ec2.CreateNetworkACLEntryRequest{
|
||||
NetworkACLID: aws.String(d.Id()),
|
||||
CIDRBlock: add.CIDRBlock,
|
||||
Egress: add.Egress,
|
||||
PortRange: add.PortRange,
|
||||
Protocol: add.Protocol,
|
||||
RuleAction: add.RuleAction,
|
||||
RuleNumber: add.RuleNumber,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating %s entry: %s", entryType, err)
|
||||
}
|
||||
|
@ -247,12 +265,15 @@ func updateNetworkAclEntries(d *schema.ResourceData, entryType string, ec2conn *
|
|||
}
|
||||
|
||||
func resourceAwsNetworkAclDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
ec2conn := meta.(*AWSClient).ec2conn
|
||||
ec2conn := meta.(*AWSClient).awsEC2conn
|
||||
|
||||
log.Printf("[INFO] Deleting Network Acl: %s", d.Id())
|
||||
return resource.Retry(5*time.Minute, func() error {
|
||||
if _, err := ec2conn.DeleteNetworkAcl(d.Id()); err != nil {
|
||||
ec2err := err.(*ec2.Error)
|
||||
err := ec2conn.DeleteNetworkACL(&ec2.DeleteNetworkACLRequest{
|
||||
NetworkACLID: aws.String(d.Id()),
|
||||
})
|
||||
if err != nil {
|
||||
ec2err := err.(aws.APIError)
|
||||
switch ec2err.Code {
|
||||
case "InvalidNetworkAclID.NotFound":
|
||||
return nil
|
||||
|
@ -267,7 +288,10 @@ func resourceAwsNetworkAclDelete(d *schema.ResourceData, meta interface{}) error
|
|||
if err != nil {
|
||||
return fmt.Errorf("Dependency violation: Cannot delete acl %s: %s", d.Id(), err)
|
||||
}
|
||||
_, err = ec2conn.ReplaceNetworkAclAssociation(association.NetworkAclAssociationId, defaultAcl.NetworkAclId)
|
||||
_, err = ec2conn.ReplaceNetworkACLAssociation(&ec2.ReplaceNetworkACLAssociationRequest{
|
||||
AssociationID: association.NetworkACLAssociationID,
|
||||
NetworkACLID: defaultAcl.NetworkACLID,
|
||||
})
|
||||
return resource.RetryError{Err: err}
|
||||
default:
|
||||
// Any other error, we want to quit the retry loop immediately
|
||||
|
@ -296,30 +320,43 @@ func resourceAwsNetworkAclEntryHash(v interface{}) int {
|
|||
return hashcode.String(buf.String())
|
||||
}
|
||||
|
||||
func getDefaultNetworkAcl(vpc_id string, ec2conn *ec2.EC2) (defaultAcl *ec2.NetworkAcl, err error) {
|
||||
filter := ec2.NewFilter()
|
||||
filter.Add("default", "true")
|
||||
filter.Add("vpc-id", vpc_id)
|
||||
|
||||
resp, err := ec2conn.NetworkAcls([]string{}, filter)
|
||||
func getDefaultNetworkAcl(vpc_id string, ec2conn *ec2.EC2) (defaultAcl *ec2.NetworkACL, err error) {
|
||||
resp, err := ec2conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{},
|
||||
Filters: []ec2.Filter{
|
||||
ec2.Filter{
|
||||
Name: aws.String("default"),
|
||||
Values: []string{"true"},
|
||||
},
|
||||
ec2.Filter{
|
||||
Name: aws.String("vpc-id"),
|
||||
Values: []string{vpc_id},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp.NetworkAcls[0], nil
|
||||
return &resp.NetworkACLs[0], nil
|
||||
}
|
||||
|
||||
func findNetworkAclAssociation(subnetId string, ec2conn *ec2.EC2) (networkAclAssociation *ec2.NetworkAclAssociation, err error) {
|
||||
filter := ec2.NewFilter()
|
||||
filter.Add("association.subnet-id", subnetId)
|
||||
|
||||
resp, err := ec2conn.NetworkAcls([]string{}, filter)
|
||||
func findNetworkAclAssociation(subnetId string, ec2conn *ec2.EC2) (networkAclAssociation *ec2.NetworkACLAssociation, err error) {
|
||||
resp, err := ec2conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{},
|
||||
Filters: []ec2.Filter{
|
||||
ec2.Filter{
|
||||
Name: aws.String("association.subnet-id"),
|
||||
Values: []string{subnetId},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, association := range resp.NetworkAcls[0].AssociationSet {
|
||||
if association.SubnetId == subnetId {
|
||||
for _, association := range resp.NetworkACLs[0].Associations {
|
||||
if *association.SubnetID == subnetId {
|
||||
return &association, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,16 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
// "github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
// "github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func TestAccAWSNetworkAclsWithEgressAndIngressRules(t *testing.T) {
|
||||
var networkAcl ec2.NetworkAcl
|
||||
var networkAcl ec2.NetworkACL
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -54,7 +55,7 @@ func TestAccAWSNetworkAclsWithEgressAndIngressRules(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccAWSNetworkAclsOnlyIngressRules(t *testing.T) {
|
||||
var networkAcl ec2.NetworkAcl
|
||||
var networkAcl ec2.NetworkACL
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -85,7 +86,7 @@ func TestAccAWSNetworkAclsOnlyIngressRules(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccAWSNetworkAclsOnlyIngressRulesChange(t *testing.T) {
|
||||
var networkAcl ec2.NetworkAcl
|
||||
var networkAcl ec2.NetworkACL
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -139,7 +140,7 @@ func TestAccAWSNetworkAclsOnlyIngressRulesChange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccAWSNetworkAclsOnlyEgressRules(t *testing.T) {
|
||||
var networkAcl ec2.NetworkAcl
|
||||
var networkAcl ec2.NetworkACL
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -150,7 +151,7 @@ func TestAccAWSNetworkAclsOnlyEgressRules(t *testing.T) {
|
|||
Config: testAccAWSNetworkAclEgressConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSNetworkAclExists("aws_network_acl.bond", &networkAcl),
|
||||
testAccCheckTags(&networkAcl.Tags, "foo", "bar"),
|
||||
testAccCheckTagsSDK(&networkAcl.Tags, "foo", "bar"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -184,7 +185,7 @@ func TestAccAWSNetworkAcl_SubnetChange(t *testing.T) {
|
|||
|
||||
func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error {
|
||||
// log.Printf("\n@@@\nEnter Destroy func\n@@@\n")
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_network" {
|
||||
|
@ -192,9 +193,11 @@ func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error {
|
|||
}
|
||||
|
||||
// Retrieve the network acl
|
||||
resp, err := conn.NetworkAcls([]string{rs.Primary.ID}, ec2.NewFilter())
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{rs.Primary.ID},
|
||||
})
|
||||
if err == nil {
|
||||
if len(resp.NetworkAcls) > 0 && resp.NetworkAcls[0].NetworkAclId == rs.Primary.ID {
|
||||
if len(resp.NetworkACLs) > 0 && *resp.NetworkACLs[0].NetworkACLID == rs.Primary.ID {
|
||||
// log.Printf("\n@@@\nDestroy func err: still exists\n@@@\n")
|
||||
return fmt.Errorf("Network Acl (%s) still exists.", rs.Primary.ID)
|
||||
}
|
||||
|
@ -203,7 +206,7 @@ func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
ec2err, ok := err.(*ec2.Error)
|
||||
ec2err, ok := err.(aws.APIError)
|
||||
if !ok {
|
||||
// log.Printf("\n@@@\nDestroy func err: aws err:%#v\n@@@\n", err)
|
||||
return err
|
||||
|
@ -219,7 +222,7 @@ func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkAcl) resource.TestCheckFunc {
|
||||
func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkACL) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
if !ok {
|
||||
|
@ -229,15 +232,17 @@ func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkAcl) resou
|
|||
if rs.Primary.ID == "" {
|
||||
return fmt.Errorf("No Security Group is set")
|
||||
}
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
||||
|
||||
resp, err := conn.NetworkAcls([]string{rs.Primary.ID}, nil)
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{rs.Primary.ID},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(resp.NetworkAcls) > 0 && resp.NetworkAcls[0].NetworkAclId == rs.Primary.ID {
|
||||
*networkAcl = resp.NetworkAcls[0]
|
||||
if len(resp.NetworkACLs) > 0 && *resp.NetworkACLs[0].NetworkACLID == rs.Primary.ID {
|
||||
*networkAcl = resp.NetworkACLs[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -245,11 +250,11 @@ func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkAcl) resou
|
|||
}
|
||||
}
|
||||
|
||||
func testIngressRuleLength(networkAcl *ec2.NetworkAcl, length int) resource.TestCheckFunc {
|
||||
func testIngressRuleLength(networkAcl *ec2.NetworkACL, length int) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
var ingressEntries []ec2.NetworkAclEntry
|
||||
for _, e := range networkAcl.EntrySet {
|
||||
if e.Egress == false {
|
||||
var ingressEntries []ec2.NetworkACLEntry
|
||||
for _, e := range networkAcl.Entries {
|
||||
if *e.Egress == false {
|
||||
ingressEntries = append(ingressEntries, e)
|
||||
}
|
||||
}
|
||||
|
@ -267,21 +272,26 @@ func testAccCheckSubnetIsAssociatedWithAcl(acl string, sub string) resource.Test
|
|||
networkAcl := s.RootModule().Resources[acl]
|
||||
subnet := s.RootModule().Resources[sub]
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
filter := ec2.NewFilter()
|
||||
filter.Add("association.subnet-id", subnet.Primary.ID)
|
||||
resp, err := conn.NetworkAcls([]string{networkAcl.Primary.ID}, filter)
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{networkAcl.Primary.ID},
|
||||
Filters: []ec2.Filter{
|
||||
ec2.Filter{
|
||||
Name: aws.String("association.subnet-id"),
|
||||
Values: []string{subnet.Primary.ID},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(resp.NetworkAcls) > 0 {
|
||||
if len(resp.NetworkACLs) > 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
r, _ := conn.NetworkAcls([]string{}, ec2.NewFilter())
|
||||
fmt.Printf("\n\nall acls\n %#v\n\n", r.NetworkAcls)
|
||||
conn.NetworkAcls([]string{}, filter)
|
||||
// r, _ := conn.NetworkACLs([]string{}, ec2.NewFilter())
|
||||
// fmt.Printf("\n\nall acls\n %#v\n\n", r.NetworkAcls)
|
||||
// conn.NetworkAcls([]string{}, filter)
|
||||
|
||||
return fmt.Errorf("Network Acl %s is not associated with subnet %s", acl, sub)
|
||||
}
|
||||
|
@ -292,15 +302,21 @@ func testAccCheckSubnetIsNotAssociatedWithAcl(acl string, subnet string) resourc
|
|||
networkAcl := s.RootModule().Resources[acl]
|
||||
subnet := s.RootModule().Resources[subnet]
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
filter := ec2.NewFilter()
|
||||
filter.Add("association.subnet-id", subnet.Primary.ID)
|
||||
resp, err := conn.NetworkAcls([]string{networkAcl.Primary.ID}, filter)
|
||||
conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
||||
resp, err := conn.DescribeNetworkACLs(&ec2.DescribeNetworkACLsRequest{
|
||||
NetworkACLIDs: []string{networkAcl.Primary.ID},
|
||||
Filters: []ec2.Filter{
|
||||
ec2.Filter{
|
||||
Name: aws.String("association.subnet-id"),
|
||||
Values: []string{subnet.Primary.ID},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(resp.NetworkAcls) > 0 {
|
||||
if len(resp.NetworkACLs) > 0 {
|
||||
return fmt.Errorf("Network Acl %s is still associated with subnet %s", acl, subnet)
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue