-
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
provider/openstack: static routing entries for routers #6207
Conversation
@drebes This is really cool - thank you 😄 A couple questions / thoughts:
func testAccCheckNetworkingV2RouterTableDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil {
return fmt.Errorf("(testAccCheckNetworkingV2RouterTableDestroy) Error creating OpenStack networking client: %s", err)
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "openstack_networking_router_table_v2" {
continue
}
router, err := routers.Get(networkingClient, rs.Primary.Attributes["router_id"]).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
if httpError.Actual == 404 {
// The router doesn't exist,
// therefore the routing table is inherently destroyed
return nil
}
}
if router.ID != rs.Primary.Attributes["router_id"] {
return fmt.Errorf("Router for table not found")
}
if len(router.Routes) != 0 {
return fmt.Errorf("Invalid number of route entries: %d", len(router.Routes))
}
}
return nil
}
With that in mind, what are the use-cases of having multiple tables pointing to the same router? Is it safe to say that there should never be?
Thoughts? |
Thanks for the feedback.
3 &4) This actually makes sense, and would solve the problem with point 2 above. I'll take a look on how to do it that way. Thanks |
Hi, regarding creating separate |
Good catch. I recently implemented the following in the a Cobbler resource. It causes all resources of the same type to be processed one at a time rather than in parallel: Off the top of my head, this should also work here. |
I did the refactoring to split the route entries in their own resources: now multiple route resources shouldn't be a problem on the same router. I also fixed the acceptance tests to better test adding/deleting just the route entries. Let me know if it looks good this way and I'll update the documentation.
|
915f422
to
0de1ed2
Compare
@@ -1,10 +1,14 @@ | |||
package openstack | |||
|
|||
import ( | |||
"github.com/hashicorp/terraform/helper/mutexkv" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
This looks really cool! I left a few comments for some small changes. Those + docs and this is good to go! |
@drebes Looks like the inline comments got clobbered.
I think this only applies to Delete. If you'd like to play it safe, I'm totally fine leaving all |
3909b09
to
2347489
Compare
I've removed the SetId("")s from delete, kept them in the other cases, and added the resource documentation. Should now be good to go. |
Looks good! Can you do one more thing and squash the commits into a single commit? This would prevent the original resource and refactor from being in the git history. |
@drebes I forgot to leave a comment when I merged. Thank you very much for this -- it's a great addition! |
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. |
Hi,
This is an attempt at adding support to static routes for OpenStack router resources. The trick here is that the static route entries are not first class citizens in OpenStack, but instead are created as an update to the routers once they are already attached to the subnets with the next hops.
I worked around that by creating a
openstack_networking_router_table_v2
resource with arouter_id
argument, which specifies which router to apply the rules to. Here's the example I'm using for the acceptance tests:That seems to work, except for the case in which two
openstack_networking_router_table_v2
resources try to configure the same router (through the samerouter_id
). I'd assume that setting resource IDs consistently related to the router would allow the detection of conflicting resources (as they would have the same ID), but it doesn't seem to be the case.The problem I'm having with the acceptance tasks is that the CheckDestroy function is called only once the whole configuration is destroyed, which includes the router to which the route entries are attached, which is more than what I want to check the deletion for. Is there a way I can limit that the CheckDestroy function is called after the destroy of the
openstack_networking_router_table_v2
resource, but still before the destruction of the other resources?I'm also open to implement it in a different way, but I'm not sure how to do it, due to the way the lifecycle of the routes need to be managed. For that reason, I still haven't written any documentation, but plan to do so.