upgrade to use typeset for subnet_ids
This commit is contained in:
parent
898fa91595
commit
468de49265
|
@ -31,17 +31,19 @@ func resourceAwsNetworkAcl() *schema.Resource {
|
||||||
Computed: false,
|
Computed: false,
|
||||||
},
|
},
|
||||||
"subnet_id": &schema.Schema{
|
"subnet_id": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
Computed: false,
|
Computed: false,
|
||||||
Deprecated: "Attribute subnet_id is deprecated on network_acl resources. Use subnet_ids instead",
|
ConflictsWith: []string{"subnet_ids"},
|
||||||
|
Deprecated: "Attribute subnet_id is deprecated on network_acl resources. Use subnet_ids instead",
|
||||||
},
|
},
|
||||||
"subnet_ids": &schema.Schema{
|
"subnet_ids": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
// Computed: true,
|
ConflictsWith: []string{"subnet_id"},
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
Set: schema.HashString,
|
||||||
},
|
},
|
||||||
"ingress": &schema.Schema{
|
"ingress": &schema.Schema{
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeSet,
|
||||||
|
@ -232,19 +234,18 @@ func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
|
|
||||||
if d.HasChange("subnet_ids") {
|
if d.HasChange("subnet_ids") {
|
||||||
o, n := d.GetChange("subnet_ids")
|
o, n := d.GetChange("subnet_ids")
|
||||||
|
if o == nil {
|
||||||
var pre []string
|
o = new(schema.Set)
|
||||||
for _, x := range o.([]interface{}) {
|
}
|
||||||
pre = append(pre, x.(string))
|
if n == nil {
|
||||||
|
n = new(schema.Set)
|
||||||
}
|
}
|
||||||
|
|
||||||
var post []string
|
os := o.(*schema.Set)
|
||||||
for _, x := range n.([]interface{}) {
|
ns := n.(*schema.Set)
|
||||||
post = append(post, x.(string))
|
|
||||||
}
|
|
||||||
|
|
||||||
remove := diffSubnets(pre, post)
|
remove := os.Difference(ns).List()
|
||||||
add := diffSubnets(post, pre)
|
add := ns.Difference(os).List()
|
||||||
|
|
||||||
if len(remove) > 0 {
|
if len(remove) > 0 {
|
||||||
// A Network ACL is required for each subnet. In order to disassociate a
|
// A Network ACL is required for each subnet. In order to disassociate a
|
||||||
|
@ -254,7 +255,7 @@ func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
return fmt.Errorf("Failed to find Default ACL for VPC %s", d.Get("vpc_id").(string))
|
return fmt.Errorf("Failed to find Default ACL for VPC %s", d.Get("vpc_id").(string))
|
||||||
}
|
}
|
||||||
for _, r := range remove {
|
for _, r := range remove {
|
||||||
association, err := findNetworkAclAssociation(r, conn)
|
association, err := findNetworkAclAssociation(r.(string), conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to find acl association: acl %s with subnet %s: %s", d.Id(), r, err)
|
return fmt.Errorf("Failed to find acl association: acl %s with subnet %s: %s", d.Id(), r, err)
|
||||||
}
|
}
|
||||||
|
@ -270,7 +271,7 @@ func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
|
|
||||||
if len(add) > 0 {
|
if len(add) > 0 {
|
||||||
for _, a := range add {
|
for _, a := range add {
|
||||||
association, err := findNetworkAclAssociation(a, conn)
|
association, err := findNetworkAclAssociation(a.(string), conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to find acl association: acl %s with subnet %s: %s", d.Id(), a, err)
|
return fmt.Errorf("Failed to find acl association: acl %s with subnet %s: %s", d.Id(), a, err)
|
||||||
}
|
}
|
||||||
|
@ -409,7 +410,7 @@ func resourceAwsNetworkAclDelete(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("subnet_ids"); ok {
|
if v, ok := d.GetOk("subnet_ids"); ok {
|
||||||
ids := v.([]interface{})
|
ids := v.(*schema.Set).List()
|
||||||
for _, i := range ids {
|
for _, i := range ids {
|
||||||
a, err := findNetworkAclAssociation(i.(string), conn)
|
a, err := findNetworkAclAssociation(i.(string), conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -542,22 +543,3 @@ func networkAclEntriesToMapList(networkAcls []*ec2.NetworkACLEntry) []map[string
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func diffSubnets(o, n []string) []string {
|
|
||||||
m := make(map[string]int)
|
|
||||||
|
|
||||||
for _, y := range n {
|
|
||||||
m[y]++
|
|
||||||
}
|
|
||||||
|
|
||||||
var ret []string
|
|
||||||
for _, x := range o {
|
|
||||||
if m[x] > 0 {
|
|
||||||
m[x]--
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
ret = append(ret, x)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,72 +10,6 @@ import (
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDiffSubnets(t *testing.T) {
|
|
||||||
removal := []struct {
|
|
||||||
First []string
|
|
||||||
Second []string
|
|
||||||
Output []string
|
|
||||||
}{
|
|
||||||
{[]string{"old"}, []string{"new"}, []string{"old"}},
|
|
||||||
{[]string{"new"}, []string{"old"}, []string{"new"}},
|
|
||||||
{[]string{"one", "two"}, []string{"two"}, []string{"one"}},
|
|
||||||
{
|
|
||||||
[]string{"subnet-1234", "subnet-5667", "subnet-897"},
|
|
||||||
[]string{"subnet-1234", "subnet-897"},
|
|
||||||
[]string{"subnet-5667"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{"subnet-1234", "subnet-897"},
|
|
||||||
[]string{"subnet-1234", "subnet-5667", "subnet-897"},
|
|
||||||
[]string{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tc := range removal {
|
|
||||||
actual := diffSubnets(tc.First, tc.Second)
|
|
||||||
if len(actual) != len(tc.Output) {
|
|
||||||
t.Fatalf("\n\texpected: %#v \n\tactual: %#v\n", tc.Output, actual)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, x := range tc.Output {
|
|
||||||
if x != actual[i] {
|
|
||||||
t.Fatalf("Network ACL diff does not match, expected %#v, got %#v", x, actual[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
addition := []struct {
|
|
||||||
First []string
|
|
||||||
Second []string
|
|
||||||
Output []string
|
|
||||||
}{
|
|
||||||
{[]string{"old"}, []string{"new"}, []string{"new"}},
|
|
||||||
{[]string{"new"}, []string{"old"}, []string{"old"}},
|
|
||||||
{[]string{"one", "two"}, []string{"two"}, []string{}},
|
|
||||||
{
|
|
||||||
[]string{"subnet-1234", "subnet-5667", "subnet-897"},
|
|
||||||
[]string{"subnet-1234", "subnet-897"},
|
|
||||||
[]string{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{"subnet-1234", "subnet-897"},
|
|
||||||
[]string{"subnet-1234", "subnet-5667", "subnet-897"},
|
|
||||||
[]string{"subnet-5667"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tc := range addition {
|
|
||||||
actual := diffSubnets(tc.Second, tc.First)
|
|
||||||
if len(actual) != len(tc.Output) {
|
|
||||||
t.Fatalf("\n\texpected: %#v \n\tactual: %#v\n", tc.Output, actual)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, x := range tc.Output {
|
|
||||||
if x != actual[i] {
|
|
||||||
t.Fatalf("Network ACL diff does not match, expected %#v, got %#v", x, actual[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAccAWSNetworkAcl_EgressAndIngressRules(t *testing.T) {
|
func TestAccAWSNetworkAcl_EgressAndIngressRules(t *testing.T) {
|
||||||
var networkAcl ec2.NetworkACL
|
var networkAcl ec2.NetworkACL
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue