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

Issue creating security group (Handle Sets) #87

Closed
ddollar opened this issue Jul 29, 2014 · 11 comments
Closed

Issue creating security group (Handle Sets) #87

ddollar opened this issue Jul 29, 2014 · 11 comments
Labels
bug provider/aws waiting-response An issue/pull request is waiting for a response from the community

Comments

@ddollar
Copy link

ddollar commented Jul 29, 2014

After I created this security group

resource "aws_security_group" "cluster-member" {
  vpc_id = "${aws_vpc.deis.id}"
  name = "cluster-member"
  description = "cluster-member"
  ingress {
    cidr_blocks = ["0.0.0.0/0"]
    protocol = "tcp"
    from_port = 22
    to_port = 22
  }
  ingress {
    security_groups = ["${aws_security_group.cluster-balancer.id}"]
    protocol = "tcp"
    from_port = 80
    to_port = 80
  }
  ingress {
    security_groups = ["${aws_security_group.cluster-balancer.id}"]
    protocol = "tcp"
    from_port = 2222
    to_port = 2222
  }
}

I see this output from terraform plan:

~ aws_security_group.cluster-member
    ingress.1.cidr_blocks.#: "0" => ""
    ingress.2.cidr_blocks.#: "0" => ""

And terraform apply fails with this message:

* Resource type 'aws_security_group' doesn't support update
@pearkes
Copy link
Contributor

pearkes commented Jul 29, 2014

Thanks! Keep them coming. :)

@ddollar
Copy link
Author

ddollar commented Jul 29, 2014

I'm still seeing this behavior on master, both before and after a terraform refresh

@pearkes
Copy link
Contributor

pearkes commented Jul 29, 2014

Just wanted to give you an update here.

Although we were able to fix a bit of a bug related to this issue, there's still and underlying problem with how Terraform handles sets of objects, i.e in your example:

  ingress {
    cidr_blocks = ["0.0.0.0/0"]
    protocol = "tcp"
    from_port = 22
    to_port = 22
  }
  ingress {
    security_groups = ["${aws_security_group.cluster-balancer.id}"]
    protocol = "tcp"
    from_port = 80
    to_port = 80
  }
  ingress {
    security_groups = ["${aws_security_group.cluster-balancer.id}"]
    protocol = "tcp"
    from_port = 2222
    to_port = 2222
  }

We store this as an array of ingress rules. To us, that ends up looking more or less like this:

  ingress.# = 3
  ingress.0.cidr_blocks.# = 1
  ingress.0.cidr_blocks.0 = 10.0.0.0/8
  ingress.0.from_port = 800
  ingress.0.protocol = tcp
  ingress.0.to_port = 800
  ingress.1.cidr_blocks.# = 1
  ingress.1.cidr_blocks.0 = 10.0.0.0/8
  ingress.1.from_port = 22
  ingress.1.protocol = tcp
  ingress.1.to_port = 22
  ingress.2.from_port = 80
  ingress.2.protocol = tcp
  ingress.2.security_groups.# = 1
  ingress.2.security_groups.0 = sg-74529647
  ingress.2.to_port = 8000

Amazon IP permissions don't have a unique identifier, so we have to rely on the order while diffing. However, if Amazon changes their order remotely for some reason, Terraform thinks that things have changed.

This is too naive and we need a better way to handle this. I'm assuming that's the issue you're now running in to, but either way what I just went over is still a related problem. I'm going to add to the issue name to reflect this.

Let me know if that's not accurate!

@pearkes pearkes changed the title Issue creating security group Issue creating security group (Handle Sets) Jul 29, 2014
@MrJoy
Copy link

MrJoy commented Jul 29, 2014

May I suggest producing a canonical order by sorting by [protocol, from_port, to_port, cidr_blocks (string-sorted) || security_groups (string-sorted)], and then just essentially doing a tree-diff to determine what changes need to be made to bring things in line with reality?

@pearkes pearkes added the bug label Jul 30, 2014
@mattsoftware
Copy link

I'm seeing this too, essentially setting a security group for port 80 and 443 (you can guess why :)

Group gets created successfully, however when I do a plan it wants to do an update...

~ aws_security_group.loadbalancer
ingress.0.from_port: "443" => "80"
ingress.0.to_port: "443" => "80"
ingress.1.from_port: "80" => "443"
ingress.1.to_port: "80" => "443"

Doing a sort before a comparison would be a great idea if the order cannot be guaranteed from the aws api call.

On a slightly different note, I also get this error when I do an apply...

...
aws_security_group.loadbalancer: Modifying...
ingress.0.from_port: "443" => "80"
ingress.0.to_port: "443" => "80"
ingress.1.from_port: "80" => "443"
ingress.1.to_port: "80" => "443"
...
aws_security_group.loadbalancer: Error: Resource type 'aws_security_group' doesn't support update
...

That probably requires a different bug report, let me know if thats the case and I'll file one.

@deoxxa
Copy link
Contributor

deoxxa commented Aug 10, 2014

+1 for producing a canonical representation of the rules. That'd at least solve the "nothing has changed but terraform thinks it has" problem.

@mitchellh
Copy link
Contributor

Fixed. We've added a TypeSet as a type in the new provider schemas we're using, so multiple resources can start taking advantage of this basically for free.

Hurray!

@tisba
Copy link

tisba commented Aug 26, 2015

I'm still seeing this effect using Terraform 0.6.3. Is your suggested fix not released yet, @mitchellh? Or is there anything I need to do to get this fixed? Thanks!

@catsby
Copy link
Contributor

catsby commented Aug 26, 2015

@tisba can you share a configuration that reproduces this? The fix in question was released in August of last year, and should be in place. If you have something that reproduces this (minus any secrets), I can dig in.

Thanks!

@catsby catsby added waiting-response An issue/pull request is waiting for a response from the community provider/aws labels Aug 26, 2015
@tisba
Copy link

tisba commented Aug 26, 2015

@catsby I'll try to cut out a minimal configuration that will trigger this issue and ping you when I'm done.

@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.
Labels
bug provider/aws waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

No branches or pull requests

8 participants