-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Problems when setting OpenStack security groups for an instance by ID #2009
Comments
It looks like there are a few issues with the current security group implementation:
|
Thanks for the pointer to #1848 - there are gratuitous changes even when using security group names, and it looks like that PR would fix that problem. I'll merge it into my local copy and see how it works. However, it is just one of the issues, and fairly orthogonal. As for (re)using an existing security group with the same name, I'm conflicted - the same arguments pro and con would apply to nearly every other OpenStack resource type; I'm dubious that it would make sense to change just security groups. On the third point, right now if you specify by name, it does what you want unless there are duplicates, in which case you get an error during apply. If the ID were looked up during planning and recorded, we could fail on ambiguity earlier, which is definitely an improvement (it's annoying when a "valid" plan fails during apply). |
I agree re Point 2. The reason I brought it up is because someone mentioned this ability back when this provider was being developed. I didn't want to introduce personal bias... perhaps this ability is best left aside for now. Once #1848 and #2008 are merged, I'll look at creating the ability to specify a security group by ID. It should be fairly simple: pull back all security groups, create a map of |
I'm observing the following behavior -- am I correct in thinking it's relevant to this issue? Apologies if I'm creating noise; just making sure this is accounted for. I'm also hoping my documentation helps others in assessing their own problems. My issue... Why are the names & IDs being scrambled when changing a resource? Steps to reproduce:
|
Regarding the ability to specify or refer to a security group by ID, I don't think this is possible. OpenStack Nova will always want the security group name and never the ID. Upon specifying an ID, you get the following error (as of Kilo): {"badRequest": {"message": "Security group 3697 not found for project 7ab5f9f65b4b417d24d774a23fcdf45b.", "code": 400}} I modified the compute resource to make it look up the name of the group when it comes across an string of all digits (assuming it's an ID). Even then, Nova will always report back the name, and Terraform will always want to change it back to the ID. Given the add/remove order has been taken care of, was there anything else that needed to be noted with this issue? If not, I'll go ahead and close it. |
I'm going to close this issue, but please re-open or open a new issue if there is still work to be done. |
As far as I'm aware - there is still a problem referencing security groups by ID instead of name, and names can conflict (Openstack allows multiple security groups with the same name). So I'm not sure why this issue was closed. Using IDs, a plan afterwards shows they are being treated as names:
|
@dannytrigo When using the compute API, you must specify the name of the security group, not the ID. When using the Networking API, you must reference the ID. It looks like you are doing the reverse in the above example you gave. If you are still having problems, I recommend opening a new issue at https://github.com/terraform-providers/terraform-provider-openstack and we can discuss further :) |
Ok, thanks for the feedback - so its a peculiarity of the Openstack API :( |
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. |
My OpenStack Terraform configuration file contains lines like these:
As noted in the comment, I use the
id
attribute of theopenstack_compute_secgroup_v2
objects because it is guaranteed to be unique and won't fail to be created because of some left-over secgroup object with the same name.However, when I run
terraform plan
a second time, I get the following output:And running `terraform apply a second time will remove the http_server secgroup from the instance (a third apply will bring it back):
The problem is that the Terraform OpenStack provider is attempting to match the names to the ids, and doesn't have code to do that. But this would be cosmetic and only a minor annoyance, if it were not for the fact that the provider implements secgroup changes as "add then remove." In this case, the
https_server
group is added (by id), which is a no-op as it is already present with the specified id. However, the remove step is not a no-op, since it removes the secgroup named "https_server." Repeated application continues to remove and re-add the secgroup.A better approach would be at a minimum to do "remove before create" since the removal by name would be very quickly undone by the (re-)addition of the secgroup by id.
If the provider could detect that an id matched a name and not mark it as changed, that would be even better, and would remove the several second "gap" when the secgroup is removed but before it is re-added.
I've submitted a PR ( #2008) for the "remove before create" change that works for me.
The text was updated successfully, but these errors were encountered: