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

Code 404 when attempting to attach tags - #805

Closed
rui-su-bnet opened this issue Jul 8, 2019 · 2 comments
Closed

Code 404 when attempting to attach tags - #805

rui-su-bnet opened this issue Jul 8, 2019 · 2 comments

Comments

@rui-su-bnet
Copy link

rui-su-bnet commented Jul 8, 2019

Terraform Version

Terraform v0.12.3

Provider Version

provider.vsphere v1.12.0

Affected Resource(s)

  • vsphere_tag
  • vsphere_tag_category

If this issue appears to affect multiple resources, it may be an issue with
Terraform's core, so please mention this.

Terraform Configuration Files

data "vsphere_datacenter" "dc" {
  name = "removed"
 }

data "vsphere_datastore" "datastore" {
  name          = "removed"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
 }

data "vsphere_compute_cluster" "cluster" {
  name          = "removed"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
 }

data "vsphere_network" "network" {
  name          = "removed"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
 }

data "vsphere_virtual_machine" "template" {
  name = "template_ubuntu18"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
 }

data "vsphere_tag_category" "group" {
  name = "Group"
}

data "vsphere_tag" "tag_group" {
  name        = "team1"
  category_id = "${data.vsphere_tag_category.group.id}"
}

data "vsphere_tag_category" "bu" {
  name = "Business Unit"
}

data "vsphere_tag" "tag_bu" {
  name        = "bu1"
  category_id = "${data.vsphere_tag_category.bu.id}"
}

resource "vsphere_virtual_machine" "vm" {
  name = "${upper(format("ubunutu_rsu-%s", format("%02d", count.index + 1)))}"
  resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"
  count    = 2
  num_cpus = 2
  memory   = 2048
  guest_id = "ubuntu64Guest"
  tags     = [
              "${data.vsphere_tag_category.bu.id}",
              "${data.vsphere_tag_category.group.id}"
  ]
  
  network_interface {
    network_id = "${data.vsphere_network.network.id}"
  }

  disk {
    label       = "disk0"
    size        = 32
    thin_provisioned = true
    unit_number = 0
  }
  
  disk {
    label       = "disk1"
    size        = 32
    thin_provisioned = true
    unit_number = 1
  }
  
  clone {
    template_uuid = "${data.vsphere_virtual_machine.template.id}"
  }

}

Debug Output

Error: error attaching tags to object ID "vm-11574": Get unexpected status code: 404: call failed: Error response from vCloud Suite API: {"type":"com.vmware.vapi.std.errors.not_found","value":{"messages":[{"args":["urn:vmomi:InventoryServiceCategory:29f72ecf-efd0-4276-9f16-11fbe85c3d45:GLOBAL"],"default_message":"Tagging object urn:vmomi:InventoryServiceCategory:29f72ecf-efd0-4276-9f16-11fbe85c3d45:GLOBAL not found","id":"cis.tagging.objectNotFound.error"}]}}

on main.tf line 43, in resource "vsphere_virtual_machine" "vm":
43: resource "vsphere_virtual_machine" "vm" {

Expected Behavior

What should have happened? Terraform should have saw the assigned tag categories and applied the tag the virtual machine post spin up.

Actual Behavior

What actually happened? The VM was created however the tag was not applied

Steps to Reproduce

  1. terraform plan
  2. terraform apply

References

#380 (not sure if this is the same issue)

@bill-rich
Copy link
Contributor

Hey @rui-su-bnet! The reason you're getting a 404 error when you apply your configuration is that the you've got tag categories listed in vsphere_virtual_machine.tags rather than the tags themselves. The categories are an attribute of the tags for determining how they are grouped an what they can be applied to, but you need to apply specific tags to a resource. For example, the following should work given your config:

tags     = [ 
    "${data.vsphere_tag.tag_bu.id}",
    "${data.vsphere_tag.tag_group.id}"
 ]

@rui-su-bnet
Copy link
Author

Thank you Bill! That fixed it

@ghost ghost locked and limited conversation to collaborators Apr 18, 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

No branches or pull requests

2 participants