Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Support multiple subnets in Network ACL #1931

Merged
merged 5 commits into from
May 15, 2015

Conversation

catsby
Copy link
Contributor

@catsby catsby commented May 12, 2015

Ref #1717

The AWS API allows Network ACLs to be applied to multiple subnets, but Terraform is currently limited to 1-to-1. With this PR we introduce subnet_ids and deprecate subnet_id, so you can a single ACL to multiple subnets.

Subnets in a VPC must be assigned an ACL, so, if we remove a subnet from this ACL, that subnet gets associated to the Default ACL. This needs to be documented because it could have weird behavior.

Usage:

provider "aws" {
  region = "us-west-2"
}

resource "aws_vpc" "foo" {
    cidr_block = "10.1.0.0/16"
    tags {
        Name = "acl-subnets-test"
    }
}
resource "aws_subnet" "one" {
    cidr_block = "10.1.111.0/24"
    vpc_id = "${aws_vpc.foo.id}"
}
resource "aws_subnet" "two" {
    cidr_block = "10.1.1.0/24"
    vpc_id = "${aws_vpc.foo.id}"
}
resource "aws_subnet" "three" {
    cidr_block = "10.1.2.0/24"
    vpc_id = "${aws_vpc.foo.id}"
}
resource "aws_network_acl" "bar" {
    vpc_id = "${aws_vpc.foo.id}"
    subnet_ids = [
    "${aws_subnet.one.id}",
    "${aws_subnet.two.id}",
    "${aws_subnet.three.id}",
  ]
}

State generated: (things omitted)

aws_network_acl.bar:
  id = acl-f6bd3393
  egress.# = 0
  ingress.# = 0
  subnet_ids.# = 3
  subnet_ids.0 = subnet-123456
  subnet_ids.1 = subnet-789123
  subnet_ids.2 = subnet-456789
  tags.# = 0
  vpc_id = vpc-25c64440

Needs:

  • docs
  • ~~plan keeps wanting to change the sorting. I'm calling sort.Strings here, but the sorting is still not correct. This may be because I didn't sort them in the config(?). Not sure what to do about that.. ~~ fixed by making it a TypeSet from TypeList

@mzupan
Copy link
Contributor

mzupan commented May 12, 2015

just tested this out and it works well 👍

},
})

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another step to this test to exercise the update functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can, but the test doesn't pass ATM b/c plan isn't empty (sorting issue mentioned above)

@phinze
Copy link
Contributor

phinze commented May 12, 2015

Two nits - LGTM generally!

@catsby
Copy link
Contributor Author

catsby commented May 13, 2015

@phinze applied feedback, thanks!
I need help with the sorting stuff. Do I need to covert subnet_ids to TypeSet?

@phinze
Copy link
Contributor

phinze commented May 14, 2015

I need help with the sorting stuff. Do I need to covert subnet_ids to TypeSet?

Ah yes - this is a great candidate for TypeSet:

"subnet_ids": schema.Schema{
  Type: TypeSet,
  Elem: TypeString,
  Set: func(v interface{}) int {
    return hashcode.String(v.(string))
  }
}

@catsby
Copy link
Contributor Author

catsby commented May 15, 2015

@phinze updated tests, take a look when you can

@phinze
Copy link
Contributor

phinze commented May 15, 2015

Solid solid - LGTM!

@catsby catsby merged commit bf65f7c into master May 15, 2015
@mitchellh mitchellh deleted the f-aws-network-subnet-ids branch June 26, 2015 22:49
@ghost
Copy link

ghost commented May 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants