-
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: Add support for FWaaS routerinsertion extension #12589
provider/openstack: Add support for FWaaS routerinsertion extension #12589
Conversation
@jtopjian I thought it would be easier to create a PR, and can then use the review process :) |
Yeh, RouterIDs is returned as part of the response.
I did try it in types.go, but it didn’t work… I’ll give it another go though :)
… On 10 Mar 2017, at 20:42, Joe Topjian ***@***.***> wrote:
@jtopjian commented on this pull request.
In builtin/providers/openstack/resource_openstack_fw_firewall_v1.go <#12589 (comment)>:
> @@ -60,6 +68,18 @@ func resourceFWFirewallV1() *schema.Resource {
}
}
+// Firewall is an OpenStack firewall.
+type Firewall struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ Description string `json:"description"`
+ AdminStateUp bool `json:"admin_state_up"`
+ Status string `json:"status"`
+ PolicyID string `json:"firewall_policy_id"`
+ TenantID string `json:"tenant_id"`
+ RouterIDs []string `json:"router_ids"`
Ah, does the result of GET now have router_ids? I wasn't aware of that or else I would have dealt with it in the original gophercloud PR.
This should be fine for now, but can you move it to types.go?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#12589 (review)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ACIbIhQLWePbcg0hUY0hYXz1R67IvnrZks5rkbWpgaJpZM4MZmaJ>.
|
@fatmcgav I forgot to hit the "start review" button, so I ended up cancelling it. Glad you got that one comment, though. I was playing around with this and I think I found a cleaner way of going about it. Take a look here: jtopjian@346eb05 I think it works for Create, but haven't finished up the Update yet. There seems to be an issue in my test environment where firewalls are not being created, so I'll have to rebuild it. Feel free to simply copy the code if you want to work with it further. I should have some time tomorrow to keep looking at this, too. |
Ah, Yeh, that looks cleaner... That's how I thought it should work, but couldn't find the right combination... Will give it a test later and confirm... |
Yeah, I tried a number of different combinations, too, until I landed on this one :) One other thing I think I noticed is that if this extension is enabled, then Neutron will pass a router ID anyway. This is probably where the |
@jtopjian Yeh, I spotted the same... If I don't provide a value for So yeh, think will need a |
Ah, so the next challenge is that 'router_ids' is stripped out by Gophercloud if it's empty :( So guess either need to update Gophercloud, or overload the method in Terraform... |
Can you confirm that |
Yeh, passing |
Sounds good. I'll also add support for the |
Cool, cheers.
…On 11 Mar 2017 16:17, "Joe Topjian" ***@***.***> wrote:
Sounds good. I'll also add support for the RouterID in the results, too.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12589 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACIbIvKa82PRdBZgL3R-dzuuB1IvXoZcks5rkskegaJpZM4MZmaJ>
.
|
Pending merge of gophercloud/gophercloud#292 |
cec412c
to
b994923
Compare
@jtopjian So this one is ready for another review... :) Since gophercloud/gophercloud#292 was merged, I've updated to use the latest changes and added some additional acceptance tests, which all pass for me :)
Unfortunately all the commits have been rebased, as I had to fix a merge conflict as a result of #12863 - Once happy with the changes, I'll get it all squashed down into a couple of commits... |
Hmm, so travis is failing the build with:
However when I run a @jtopjian / @stack72 Any ideas on how to fix the above error? Edit: Actually, looking closer at the error, it appears the failure is in gophercloud rather than terraform... I'll take a look there... :) |
So I've got a 'fix' for the |
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.
@fatmcgav Really nice work here!
I've left a few comments, all very minor.
In addition, I had no idea the Firewall tests were the way they currently are. They don't match the other test setups at all. If they were similar to the others, you would have probably been able to write easier tests. Let's leave everything as-is and I'll try to make some time to clean them up later.
Let me know if you have any questions.
if OS_IMAGE_ID == "" || OS_IMAGE_NAME == "" { | ||
t.Fatal("OS_IMAGE_ID and OS_IMAGE_NAME must be set for acceptance tests") | ||
if OS_IMAGE_ID == "" && OS_IMAGE_NAME == "" { | ||
t.Fatal("OS_IMAGE_ID or OS_IMAGE_NAME must be set for acceptance tests") |
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.
While this is probably true, this is out of scope for this PR since it's not related to the router insertion feature.
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.
Agreed, I'll get it raised in a different PR...
}, | ||
associatedRoutersRaw := d.Get("associated_routers").(*schema.Set).List() | ||
if len(associatedRoutersRaw) > 0 { | ||
log.Printf("[DEBUG] Need to associate Firewall with router(s): %+v", associatedRoutersRaw) |
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.
How about: "Will attempt to associate firewall with router(s):..." ?
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.
Done
@@ -106,6 +146,7 @@ func resourceFWFirewallV1Create(d *schema.ResourceData, meta interface{}) error | |||
} | |||
|
|||
_, err = stateConf.WaitForState() | |||
log.Println("[DEBUG] Firewall is active.") |
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.
How about: "Firewall (ID) is active." ?
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.
Done
result := firewalls.Get(networkingClient, d.Id()) | ||
|
||
var firewall Firewall | ||
err = result.ExtractInto(&firewall) |
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.
Just a heads up that this might change in the future. What you have is the current working solution -- just something to be mindful of down the road.
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.
Ah, ok... Well atleast the tests should show us any breakage...
I guess I could collapse this into a single line, tagging the ExtractInto
onto the end of the firewalls.Get
... Thoughts?
@@ -57,6 +58,18 @@ func resourceFWFirewallV1() *schema.Resource { | |||
ForceNew: true, | |||
Computed: true, | |||
}, | |||
"associated_routers": &schema.Schema{ | |||
Type: schema.TypeSet, |
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.
Does the API return the associated routers as an array in the same order as what the user gave? If so, this can be a TypeList
. But if the API takes it upon itself to re-order (for example, alphabetical), then TypeSet
is the way to go.
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.
I'm not sure tbh... I'll give it a test with TypeList
and see what it does...
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.
So it looks like the API doesn't guarantee the ordering, as I switched to using TypeList
and got a failure:
--- FAIL: TestAccFWFirewallV1_router_update (33.48s)
testing.go:280: Step 1 error: After applying this step, the plan was not empty:
DIFF:
UPDATE: openstack_fw_firewall_v1.fw_1
associated_routers.0: "5eda6df1-0271-4468-a2eb-3e1e1a24596e" => "9ee2774f-a1af-494c-955e-bf37109c6bae"
associated_routers.1: "9ee2774f-a1af-494c-955e-bf37109c6bae" => "5eda6df1-0271-4468-a2eb-3e1e1a24596e"
So looks like got to stick to using TypeSet
.
// FirewallCreateOpts represents the attributes used when creating a new firewall. | ||
type FirewallCreateOpts struct { | ||
firewalls.CreateOpts | ||
firewalls.CreateOptsBuilder |
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.
👍
I recently ran into this with a different type in another PR.
In addition to this, I wonder if this field should be explicitly labeled CreateOptsBuilder
so this type of format can work? I haven't tried to modify the custom types here to support the field name. Just a thought.
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.
Yeh, the go vet
failure had me confused for a bit... So used that format here: https://github.com/hashicorp/terraform/pull/12589/files#diff-08dbfa227aa19c57ae3521114151c1c8R111
builtin/providers/openstack/types.go
Outdated
return nil, err | ||
} | ||
|
||
if base["value_specs"] != nil { |
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.
Just spotted another optimisation I can make, by extracting this out into its own function in util.go
so that's it more reusable...
@@ -57,6 +58,18 @@ func resourceFWFirewallV1() *schema.Resource { | |||
ForceNew: true, | |||
Computed: true, | |||
}, | |||
"associated_routers": &schema.Schema{ | |||
Type: schema.TypeSet, |
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.
So it looks like the API doesn't guarantee the ordering, as I switched to using TypeList
and got a failure:
--- FAIL: TestAccFWFirewallV1_router_update (33.48s)
testing.go:280: Step 1 error: After applying this step, the plan was not empty:
DIFF:
UPDATE: openstack_fw_firewall_v1.fw_1
associated_routers.0: "5eda6df1-0271-4468-a2eb-3e1e1a24596e" => "9ee2774f-a1af-494c-955e-bf37109c6bae"
associated_routers.1: "9ee2774f-a1af-494c-955e-bf37109c6bae" => "5eda6df1-0271-4468-a2eb-3e1e1a24596e"
So looks like got to stick to using TypeSet
.
From a commit squash POV, I'm thinking the following:
|
Yep, that looks good to me :)
Sure, that sounds good. Really, as long as the vendor commit is separate, anything else is fine. I'll done one final sweep and test with a squashed set. |
gophercloud/firewall to support router insertion
`openstack_fw_firewall_v1` resources with router(s). Added `associated_routers` and `no_routers` arguments.
…rguments on `openstack_fw_firewall_v1` resource.
afc163f
to
5f5c5ec
Compare
@jtopjian Right, all squashed down into a healthier number of commits... :) |
This looks good to me! Really nice work on this, @fatmcgav -- thank you :)
|
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. |
Add support for the Openstack FWaaS
routerinsertion
extension, as added to Gophercloud here: gophercloud/gophercloud#220Fixes #12488
Todo: