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

VSphere tags in inventory #88

Merged
merged 6 commits into from Sep 20, 2018
Merged

VSphere tags in inventory #88

merged 6 commits into from Sep 20, 2018

Conversation

Atadilo
Copy link
Contributor

@Atadilo Atadilo commented Mar 27, 2018

I'm using terraform with VSphere provider.

$ terraform version
Terraform v0.11.1
+ provider.vsphere v1.1.1

And I use tags : https://www.terraform.io/docs/providers/vsphere/d/tag.html

In my terraform.tfstate file the tag names are not directly in the resources.

    "vsphere_virtual_machine.twelve": {
        "type": "vsphere_virtual_machine",
        "primary": {
            "id": "422cfa4a-c6bb-3405-0335-2d9b2034405f",
            "attributes": {
                "default_ip_address": "10.20.30.50",
                "tags.#": "1",
                "tags.1357913579": "urn:vmomi:InventoryServiceTag:00000000-0001-4957-81fa-1234567890ab:GLOBAL"
            }
        }
    },
    "data.vsphere_tag.testTag1": {
        "type": "vsphere_tag",
        "primary": {
            "id": "urn:vmomi:InventoryServiceTag:00000000-0001-4957-81fa-1234567890ab:GLOBAL",
            "attributes": {
                "name": "testTag1"
            }
        }
    }

To solve this, I create a map of ID => name of all resources.
And during "inventorize tags", I look for "ID" in the map to replace with tag name.

Copy link
Owner

@adammck adammck left a comment

Choose a reason for hiding this comment

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

This is great, thanks very much for tackling this. This is the first provider I've seen to work in a way other than here's a list tags for each resource. Just a couple of comments.

parser_test.go Outdated
"default_ip_address": "10.20.30.50"
"default_ip_address": "10.20.30.50",
"tags.#": "1",
"tags.1357913579": "urn:vmomi:InventoryServiceTag:00000000-0001-4957-81fa-1234567890ab:GLOBAL"
Copy link
Owner

Choose a reason for hiding this comment

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

Please fix the indentation in this file. It's not caught by gofmt because it's a humungous JSON string.

parser.go Outdated
@@ -52,13 +53,26 @@ func (s *state) outputs() []*Output {
return inst
}

func (s *state) mapidnames() map[string]string {
Copy link
Owner

Choose a reason for hiding this comment

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

Please rename this to something a bit more descriptive, and/or add a docstring. I know this is a private method, but I'm having trouble understanding exactly what it does.

@Atadilo
Copy link
Contributor Author

Atadilo commented May 6, 2018

I modified the files, is that enough?

@uberjew666
Copy link

This functionality is brilliant.
I do hope this gets merged soon.

@adammck
Copy link
Owner

adammck commented Sep 20, 2018

Thanks very much for this patch! I suspect that many other providers do/will work like this, so this will be a useful template in addition to the functionality. Sorry about the very slow review.

@adammck adammck merged commit aecdc48 into adammck:master Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants