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

New resource: vsphere_tag_category #164

Merged
merged 9 commits into from
Sep 19, 2017
Merged

New resource: vsphere_tag_category #164

merged 9 commits into from
Sep 19, 2017

Conversation

vancluever
Copy link
Contributor

This adds a new resource, vsphere_tag_category, which is the start of
the effort to get tag support into the provider. This allows one to
create and manage tag categories in the provider, which can then be
passed along to tag resources.

As part of this work, other work has been done to prime the provider for
the ability to manage multiple API connections at once, as the provider
now needs to connect to two to do its job. Furthermore, tags are not
supported on all versions of vSphere and not on ESXi, so extra
precautions needed to be undertaken to ensure these cases were properly
blocked.

@vancluever vancluever changed the title New resource, vsphere_tag_category New resource": vsphere_tag_category Sep 19, 2017
@vancluever vancluever changed the title New resource": vsphere_tag_category New resource: vsphere_tag_category Sep 19, 2017
Copy link

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments but otherwise LGTM

@@ -11,8 +17,8 @@
{
"checksumSHA1": "+2yCNqbcf7VcavAptooQReTGiHY=",
"path": "github.com/apparentlymart/go-rundeck-api",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is Rundeck needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

govendor add strikes again 😛

I'm going to try this again against my fork using govendor fetch, and see if I get the same deps pulled in.

"description": {
Type: schema.TypeString,
Description: "The description of the category.",
Optional: true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be Computed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config should be the source of truth, even if there's no description defined, so this should not be computed so that it can be reverted to a blank description if set out-of-band.

Elem: &schema.Schema{Type: schema.TypeString},
Required: true,
},
"used_by": {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is named incorrectly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I almost feel like removing this field altogether. I will do a bit more research on it. API entry where it's referenced.

if len(cats) > 1 {
// This should not happen but guarding just in case it does.
return nil, fmt.Errorf("category name %q returned multiple results, more specific name required", name)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not combine these to be:

if len(cats) == 1) {
  d.SetId(cats[0].ID)
 return []*schema.ResourceData{d}, nil 
}

return nil, fmt.Errorf("Expected a single category, got '%d'", len(cats))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's 2 specific cases here - the first one is when an incorrect category is given and the one that will be the one most users will encounter (len(cats) < 1). Technically, it seems impossible for len(cats) > 1 to happen at the moment, as category names need to be unique (adding a category with a different name but different associable types in TF or the UI will result in a name collision error). Yet GetCategoriesByName returns multiple, even though its own logic searches for an exact match. So the second case is just for brevity to match the SDK and I don't expect it to really happen. Regardless, given these two cases are so distinct I'd prefer to have this level of verbosity over a more general len != 1 style error message, which I think is more confusing...

Also as I'm typing this I think the second error is a little misleading too - might end up re-wording this as well, but we still need to distinguish between "not found" (something a user may stumble on if they just mis-typed the name of the category) versus len > 1 (which is more of a change of the expected API and something we will need to fix).

return func(s *terraform.State) error {
_, err := testGetTagCategory(s, "terraform-test-category")
if err != nil {
if strings.Contains(err.Error(), "Status code: 404") && !expected {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there no way of getting a concrete object back and checking the status code on that instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. The library does not wrap an error type to pull it from (reference).

[ext-tags-general]: https://docs.vmware.com/en/VMware-vSphere/6.5/com.vmware.vsphere.vcenterhost.doc/GUID-E8E854DD-AA97-4E0C-8419-CE84F93C4058.html
[ext-tag-categories]: https://docs.vmware.com/en/VMware-vSphere/6.5/com.vmware.vsphere.vcenterhost.doc/GUID-BA3D1794-28F2-43F3-BCE9-3964CB207FB6.html

~> **NOTE:** Tagging support is unsupported on direct ESXi connections and

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably also warrants a section on the main vSphere page for "Required vSphere Versions" IMO (although, checking the page perhaps it wants a separate page for that?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly that index page needs a massive overhaul anyway so I'm not surprised. For now I think I'm fine with it being out of date, but close to v1.0.0 (or during some downtime) I will work on updating it so that not only does it have this information, but the dev info is removed, and other steps are taken to make sure that it focuses on a summary of what the provider does and that's it, saving extra detail for each individual resource.


* `name` - (String, required) The name of the tag.
* `description` - (String, optional) A description for the tag.
* `cardinality` - (String, required, forces new resource) The number of tags

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor in order providers we suffix the description with "Changing this forces a new resource to be created" rather than doing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm still saving this work for a documentation overhaul. Keeping consistent with the style that I have on other docs for now, as that will allow me to easier fix this later. I haven't forgotten!

[here](#associable-object-types).

~> **NOTE:** You can add associable types to a category, but you cannot remove
them. Attempting to do so will result in an error.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like this should be ForceNew?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding types is a legitimate operation, removing them is not - so we can't be ForceNew here as that would block the case where someone wants to add a type to a category.

Created a new type, VSphereClient, to hold the multiple client
connections we are going to need here now that we are working on using a
different SDK for tags.
This adds a new resource, vsphere_tag_category, which is the start of
the effort to get tag support into the provider. This allows one to
create and manage tag categories in the provider, which can then be
passed along to tag resources.

As part of this work, other work has been done to prime the provider for
the ability to manage multiple API connections at once, as the provider
now needs to connect to two to do its job. Furthermore, tags are not
supported on all versions of vSphere and not on ESXi, so extra
precautions needed to be undertaken to ensure these cases were properly
blocked.
Note that this is temporary until vmware/vic#6381 is merged, at which
point we will vendor off of the upstream commit.
Looks like govendor fetch added this a lot more cleanly than govendor
add.
I can't find any sort of useful data on how this is used, the docs don't
mention it, the API is murky on its purpose and the UI does not expose
it. Adding a tag to an object with the category doesn't add anything to
it either. Since we can't figure out what it's used for, I'm just
dropping it - if it's missed by any user, we can just add it back later.
For the "multiple category returned" case. By all observations this is a
case that can't happen, but VIC's tag package seems to think it can, so
we are indicating that the user needs to put in an issue if they indeed
somehow managed to add multiple tag categories with the same name.
Apparently need to add the full package path as the origin :P
@vancluever
Copy link
Contributor Author

Merging now - thanks for the review @tombuildsstuff!

@vancluever vancluever merged commit 8f28860 into master Sep 19, 2017
@vancluever vancluever deleted the f-tag-categories branch September 20, 2017 20:03
@ghost ghost locked and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants