-
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 openstack_networking_network_v2 datasource #12304
Conversation
@yanndegat Thanks for making this :) This looks good, but it's limited to only using the You can see the list of list options for networks here. You don't need to add all of the possible options. For example, if all you need is is to search by "name", then just do: listOpts := networks.ListOpts{
Name: d.Get("name").(string),
} This method is the same of what you have now, but at least by doing it this way, someone else can easily add Then in order to handle multiple returned networks, maybe add a This is the pattern that most of the OpenStack resources will take for data sources. The various Thoughts? Also, if you use the image data source to base the network data source off of, you'll see that the image is iterating through EachPage. This was due to a bug in Gophercloud at the time. Networks should be more simple: allPages, err := networks.List(client, listOpts).AllPages()
if err != nil {
return err
}
allNetworks, err := networks.ExtractNetworks(allPages)
if err != nil {
return err
} Then you should be able to pick up again starting here. Let me know if you have any questions or comments! Thanks again for putting this together :) |
@jtopjian hi joe thanks a lot. One thing though : there's no way to sort a list of networks based on a pertinent criteria. There's only 2 cases where there could be more than one result:
so if the list search returns more than one network, then there's obsviously missing criterias. what do you think? |
"shared": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, |
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.
Can you move admin_state_up
and shared
to the bottom of the list like here?
@yanndegat I agree with everything :) I left one comment on schema placement, but it's absolutely minor. I'll run some acceptance tests on this later today :) |
@yanndegat I ran into an error with the acceptance test. The "network" one works, but it's failing on the subnet test. I'll look at it in more detail tomorrow. I can send you a patch once it's working. |
yup, i saw whats wrong. resubmitting |
@yanndegat Ah, I found the problem :) By default, this data source will query all networks, even those created by an admin and marked as "shared". Normal users can see these networks, but it looks like they cannot perform a GET on some subnets. So when the data source is iterating through all networks and looking for a matching subnet, I was seeing an error about "subnet not found". In reality, it was simply querying a subnet the test user did not have access to. I made a patch here that fixes the problem: https://gist.github.com/jtopjian/37accf201276cf18fb18c575f7094243 Let me know if this makes sense :) |
thanks a lot, |
That's a great idea, but it's better to use https://github.com/hashicorp/terraform/blob/master/builtin/providers/openstack/provider.go#L37 |
done |
@yanndegat Awesome. This looks good to me! Thank you for making this and for your patience with the changes. :) @stack72 do you want to do a quick review? |
This LGTM :) Thanks for all the work here @yanndegat |
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 @jtopjian
i'm pushing this new datasource for the openstack provider.
sadly, i cannot run the acceptance tests because my openstack provider doesn't allow network creation through the neutron api.
hoping the tests pass
anyhow, i've used this datasource against a pre existing network and this works.