{"action":"created","issue":{"url":"https://api.github.com/repos/terraform-providers/terraform-provider-vcd/issues/48","repository_url":"https://api.github.com/repos/terraform-providers/terraform-provider-vcd","labels_url":"https://api.github.com/repos/terraform-providers/terraform-provider-vcd/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/terraform-providers/terraform-provider-vcd/issues/48/comments","events_url":"https://api.github.com/repos/terraform-providers/terraform-provider-vcd/issues/48/events","html_url":"https://github.com/terraform-providers/terraform-provider-vcd/issues/48","id":251626034,"number":48,"title":"Guest customization load order is not configurable to postcustomization","user":{"login":"opsforge","id":22707841,"avatar_url":"https://avatars3.githubusercontent.com/u/22707841?v=4","gravatar_id":"","url":"https://api.github.com/users/opsforge","html_url":"https://github.com/opsforge","followers_url":"https://api.github.com/users/opsforge/followers","following_url":"https://api.github.com/users/opsforge/following{/other_user}","gists_url":"https://api.github.com/users/opsforge/gists{/gist_id}","starred_url":"https://api.github.com/users/opsforge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opsforge/subscriptions","organizations_url":"https://api.github.com/users/opsforge/orgs","repos_url":"https://api.github.com/users/opsforge/repos","events_url":"https://api.github.com/users/opsforge/events{/privacy}","received_events_url":"https://api.github.com/users/opsforge/received_events","type":"User","site_admin":false},"labels":[{"id":640744315,"url":"https://api.github.com/repos/terraform-providers/terraform-provider-vcd/labels/waiting-response","name":"waiting-response","color":"5319e7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-08-21T11:09:10Z","updated_at":"2017-08-24T09:56:32Z","closed_at":null,"body":"Hi there,\r\n\r\nI want to run a guest customization script for a vcd_vm_app resource on launch. I wanted to make the script run post tools customization (e.g setting host name and IP address).\r\n\r\nThere seems to be support for this from VMware, although documentation is sparse on it:\r\nhttps://pubs.vmware.com/vcd-51/index.jsp#com.vmware.vcloud.users.doc_51/GUID-724EB7B5-5C97-4A2F-897F-B27F1D4226C7.html\r\nhttps://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1026614\r\n\r\nIn a nutshell, there needs to be a wrapper around the script you are executing, defining which tasks are pre and post. I would want to execute my actions post (possible using this method).\r\n\r\nHowever it seems, that the VCD provider picks up my actions by default as pre. This makes it impossible to use the network and the host name as they have not been set at that point yet. Here's some logs to show the behaviour:\r\n\r\n```\r\nDEBUG: Exit Code: 0\r\nDEBUG: Command: 'hostname -f 2>/dev/null'\r\nDEBUG: Result: localhost\r\n\r\nDEBUG: Exit Code: 0\r\nDEBUG: opening file /etc/sysconfig/network.\r\nDEBUG: Match found   : Line = HOSTNAME=localhost.localdomain\r\n\r\nDEBUG: Actual String : localhost.localdomain\r\nINFO: OLD HOST NAME = localhost.localdomain\r\nINFO: Handling pre-customization ...\r\nINFO: RunCustomScript invoked in '/tmp/.vmware-imgcust-d52grc3/' for 'precustomization'\r\nDEBUG: Command: '/bin/cat /tmp/.vmware-imgcust-d52grc3//script4204918823332955454.bat | /usr/bin/tr -d '^M' > /tmp/.vmware-imgcust-d52grc3//script4204918823332955454.bat.tmp'\r\nDEBUG: Result:\r\nDEBUG: Exit Code: 0\r\nDEBUG: Command: '/bin/mv -f /tmp/.vmware-imgcust-d52grc3//script4204918823332955454.bat.tmp /tmp/.vmware-imgcust-d52grc3//script4204918823332955454.bat'\r\nDEBUG: Result:\r\nDEBUG: Exit Code: 0\r\nDEBUG: Command: '/bin/chmod u+x /tmp/.vmware-imgcust-d52grc3//script4204918823332955454.bat'\r\nDEBUG: Result:\r\nDEBUG: Exit Code: 0\r\nINFO: Executing pre-customization script...\r\nINFO: precustomization\r\nDEBUG: Command: '/bin/sh /tmp/.vmware-imgcust-d52grc3//script4204918823332955454.bat \"precustomization\"'\r\n```\r\n\r\nYou can see in the above snippet, that it defaults to 'precustomization' even though that's not specified anywhere in my script.\r\n\r\nThe configuration is like this:\r\n\r\n```\r\nresource \"vcd_vapp_vm\" \"repo\" {\r\n  depends_on    = [\"vcd_vapp_vm.jump\"]\r\n  provider      = \"vcd.xap\"\r\n  vapp_name     = \"${vcd_vapp.xap_core.name}\"\r\n  name          = \"repo01\"\r\n  catalog_name  = \"${var.catalog_lin}\"\r\n  template_name = \"${var.template_lin}\"\r\n  memory        = 4096\r\n  cpus          = 4\r\n  network_name  = \"${vcd_network.mgmt_net.name}\"\r\n  ip            = \"${cidrhost(var.mgmt_network_ip_pool, 22)}\"\r\n  initscript    = \"service network restart; cp -r /tmp/vm* /root/\"\r\n}\r\n```\r\n\r\nI have tested the script and it works if executed locally on post as root. I've also seen from the VMware logs that it does attempt to do actions defined in it, it just can't succeed due to no network.\r\n\r\nI'm aware of the connection + remote-exec method, however I want to use clean API calls for this provisioning and according to documentation and manual test with the UI, this should be possible.\r\n\r\nCan you please advise on how the initscript interacts with the API and if it's possible to override the `precustomization` argument to `postcustomization` ?\r\n\r\nCheers"},"comment":{"url":"https://api.github.com/repos/terraform-providers/terraform-provider-vcd/issues/comments/324590385","html_url":"https://github.com/terraform-providers/terraform-provider-vcd/issues/48#issuecomment-324590385","issue_url":"https://api.github.com/repos/terraform-providers/terraform-provider-vcd/issues/48","id":324590385,"user":{"login":"bobbydeveaux","id":5550105,"avatar_url":"https://avatars2.githubusercontent.com/u/5550105?v=4","gravatar_id":"","url":"https://api.github.com/users/bobbydeveaux","html_url":"https://github.com/bobbydeveaux","followers_url":"https://api.github.com/users/bobbydeveaux/followers","following_url":"https://api.github.com/users/bobbydeveaux/following{/other_user}","gists_url":"https://api.github.com/users/bobbydeveaux/gists{/gist_id}","starred_url":"https://api.github.com/users/bobbydeveaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bobbydeveaux/subscriptions","organizations_url":"https://api.github.com/users/bobbydeveaux/orgs","repos_url":"https://api.github.com/users/bobbydeveaux/repos","events_url":"https://api.github.com/users/bobbydeveaux/events{/privacy}","received_events_url":"https://api.github.com/users/bobbydeveaux/received_events","type":"User","site_admin":false},"created_at":"2017-08-24T09:56:32Z","updated_at":"2017-08-24T09:56:32Z","body":"Awesome - thanks for that. Shall tag this issue as a documentation update. Cheers! :)"}}
{"actor":{"display_login":"bobbydeveaux"}}