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/openstack: Ignore order of security_groups in instance #3651

Merged
merged 2 commits into from
Oct 30, 2015

Conversation

Sheile
Copy link
Contributor

@Sheile Sheile commented Oct 27, 2015

Problems

When execute terraform plan after terraform apply with same template by provider/openstack, sometimes output some changes of securitygroups.
This problem is occurred when created securitygroups have mismatched between order of ID and order of security_groups attribute in template like below.

resource "openstack_compute_instance_v2" "server" {
  name = "terraform-server"
  security_groups = ["${openstack_compute_secgroup_v2.sg1.name}", "${openstack_compute_secgroup_v2.sg2.name}"]
}
# nova secgroup-list
+--------------------------------------+---------+---------------------------+
| Id                                   | Name    | Description               |
+--------------------------------------+---------+---------------------------+
| 483d055e-54f3-43f5-b24f-2e33610c4ad6 | default | default                   |
| ab3ac38f-c185-4232-a4bd-cac3b1455aa2 | sg1     | terraform_security_group1 |
| 71834dc8-e73e-41f5-a191-66f8007b92ae | sg2     | terraform_security_group2 |
+--------------------------------------+---------+---------------------------+

If assigned ID of sg1 larger than ID of sg2, terraform plan will output following changes.

$ terraform plan

~ openstack_compute_instance_v2.ap_server
    security_groups.0: "sg2" => "sg1"
    security_groups.1: "sg1" => "sg2"


Plan: 0 to add, 1 to change, 0 to destroy.

I think this problem is relevant to openstack API response to get server information.
Following request return security_groups that is sorted by ascending order on ID. In addition, these response hasn't ID attribute.

curl -H "X-Auth-Token: *****************" http://localhost:8774/v2/*************/servers/***************** | jq .server.security_groups
[
  {
    "name": "sg2"
  },
  {
    "name": "sg1"
  }
]

Fix

Order of SecurityGroups can be ignored. I changed security group from TypeList to TypeSet.

@jtopjian
Copy link
Contributor

@phinze This is the same solution that was suggested in #2284. Unfortunately it was rolled back due to concerns about schema migrations. I left a question in #2284 about whether a schema migration is really needed as I was unable to break anything by launching resources, switching to the patched version, then resuming work. Thoughts?

@phinze
Copy link
Contributor

phinze commented Oct 30, 2015

@jtopjian Ah yes, the reason nothing broke is because - as the state representation is currently implemented - a TypeSet can be successfully parsed out of the state for an attribute that was stored in the TypeList format. It's a bit of a cheat semantically speaking, but I think we should be able to use it successfully.

@phinze
Copy link
Contributor

phinze commented Oct 30, 2015

To be clear: after the first run with the newer version of Terraform - the state version will be stored in the standard TypeSet format. You saw this in your testing as well as the monotonically increasing integers switched to hashcodes.

@jtopjian
Copy link
Contributor

@phinze So this should be OK to merge without a schema migration? With the understanding that this was, more or less, a lucky break?

@phinze
Copy link
Contributor

phinze commented Oct 30, 2015

Yep - sounds about right. Merge away! ( See #3696 (comment) for my merge+changelog crash course. 👌 )

@jtopjian
Copy link
Contributor

okie dokie. acceptance tests pass.

jtopjian added a commit that referenced this pull request Oct 30, 2015
provider/openstack: Ignore order of security_groups in instance
@jtopjian jtopjian merged commit beab561 into hashicorp:master Oct 30, 2015
@Sheile Sheile deleted the ignore-sg-order branch November 4, 2015 01:56
@ghost
Copy link

ghost commented Apr 30, 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 Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants