{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/packer/issues/6297","repository_url":"https://api.github.com/repos/hashicorp/packer","labels_url":"https://api.github.com/repos/hashicorp/packer/issues/6297/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/packer/issues/6297/comments","events_url":"https://api.github.com/repos/hashicorp/packer/issues/6297/events","html_url":"https://github.com/hashicorp/packer/issues/6297","id":325871361,"node_id":"MDU6SXNzdWUzMjU4NzEzNjE=","number":6297,"title":"[1.2.3] Fails to retrieve Windows Administrator Password from a Packer amazon-ebs successful build","user":{"login":"lmayorga1980","id":3172378,"node_id":"MDQ6VXNlcjMxNzIzNzg=","avatar_url":"https://avatars0.githubusercontent.com/u/3172378?v=4","gravatar_id":"","url":"https://api.github.com/users/lmayorga1980","html_url":"https://github.com/lmayorga1980","followers_url":"https://api.github.com/users/lmayorga1980/followers","following_url":"https://api.github.com/users/lmayorga1980/following{/other_user}","gists_url":"https://api.github.com/users/lmayorga1980/gists{/gist_id}","starred_url":"https://api.github.com/users/lmayorga1980/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmayorga1980/subscriptions","organizations_url":"https://api.github.com/users/lmayorga1980/orgs","repos_url":"https://api.github.com/users/lmayorga1980/repos","events_url":"https://api.github.com/users/lmayorga1980/events{/privacy}","received_events_url":"https://api.github.com/users/lmayorga1980/received_events","type":"User","site_admin":false},"labels":[{"id":126745464,"node_id":"MDU6TGFiZWwxMjY3NDU0NjQ=","url":"https://api.github.com/repos/hashicorp/packer/labels/builder/amazon","name":"builder/amazon","color":"d4c5f9","default":false},{"id":95839186,"node_id":"MDU6TGFiZWw5NTgzOTE4Ng==","url":"https://api.github.com/repos/hashicorp/packer/labels/windows-guest","name":"windows-guest","color":"207de5","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-05-23T20:59:54Z","updated_at":"2018-08-14T22:37:14Z","closed_at":"2018-08-01T17:15:51Z","author_association":"CONTRIBUTOR","body":"I have a successful Packer amazon-ebs windows ami but when I try to create an ec2 instance based on the ami I am not able to retrieve the Administrator credentials using the certificate I used to build the instance.\r\n\r\nI know that Packer during the build process creates a temporal key pair and is able to retrieve the AMI Administrator Password but after the build is complete the key pair is destroyed. \r\n\r\n![screenshot from 2018-05-23 16-56-46](https://user-images.githubusercontent.com/3172378/40450660-5135ce08-5eaa-11e8-85e4-4d1c2dac0e9b.png)\r\n\r\n\r\n```json\r\n{\r\n    \"variables\": {\r\n      \"admin_user\": \"Administrator\"\r\n    },\r\n    \"builders\": [ {\r\n      \"type\": \"amazon-ebs\",\r\n      \"ami_name\": \"Windows_2016_Full_Base\",\r\n      \"instance_type\": \"t2.medium\",\r\n      \"region\": \"\",\r\n      \"secret_key\": \"\",\r\n      \"access_key\": \"\",\r\n      \"profile\": \"saml\",\r\n      \"ami_description\": \"Base AMI\",\r\n      \"ami_block_device_mappings\": [\r\n        {\"delete_on_termination\": true,\r\n          \"device_name\": \"/dev/sda1\",\r\n          \"volume_size\": 60,\r\n          \"volume_type\": \"gp2\"\r\n        }\r\n       ],\r\n      \"source_ami_filter\": {\r\n        \"filters\": {\r\n          \"virtualization-type\": \"hvm\",\r\n          \"name\": \"Windows_Server-2016-English-Full-Base-????.??.??\",\r\n          \"root-device-type\": \"ebs\"\r\n        },\r\n       \"owners\": [\"801119661308\"],\r\n       \"most_recent\": true\r\n      },\r\n      \"communicator\": \"winrm\",\r\n      \"user_data_file\": \"scripts/win/ec2-userdata.ps1\",\r\n      \"windows_password_timeout\": \"30m\",\r\n      \"winrm_use_ssl\": true,\r\n      \"winrm_insecure\": true,\r\n      \"winrm_username\": \"{{user `admin_user`}}\",\r\n      \"winrm_timeout\": \"6h\"\r\n    }\r\n    ],\r\n    \"provisioners\": [\r\n    {\r\n      \"type\": \"windows-shell\",\r\n      \"scripts\": [\r\n        \"scripts/win/uac-enable.bat\",\r\n        \"scripts/win/enable-rdp.bat\"\r\n      ]\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\n**ec2-user-data**\r\n\r\n```json\r\n<powershell>\r\n\r\nwrite-output \"Running User Data Script\"\r\nwrite-host \"(host) Running User Data Script\"\r\n\r\nSet-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore\r\n\r\n# Don't set this before Set-ExecutionPolicy as it throws an error\r\n$ErrorActionPreference = \"stop\"\r\n\r\n# Remove HTTP listener\r\nRemove-Item -Path WSMan:\\Localhost\\listener\\listener* -Recurse\r\n\r\n$Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\\LocalMachine\\My -DnsName \"packer\"\r\nNew-Item -Path WSMan:\\LocalHost\\Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert.Thumbprint -Force\r\n\r\n# WinRM\r\nwrite-output \"Setting up WinRM\"\r\nwrite-host \"(host) setting up WinRM\"\r\n\r\ncmd.exe /c winrm quickconfig -q\r\ncmd.exe /c winrm set \"winrm/config\" '@{MaxTimeoutms=\"1800000\"}'\r\ncmd.exe /c winrm set \"winrm/config/winrs\" '@{MaxMemoryPerShellMB=\"1024\"}'\r\ncmd.exe /c winrm set \"winrm/config/service\" '@{AllowUnencrypted=\"true\"}'\r\ncmd.exe /c winrm set \"winrm/config/client\" '@{AllowUnencrypted=\"true\"}'\r\ncmd.exe /c winrm set \"winrm/config/service/auth\" '@{Basic=\"true\"}'\r\ncmd.exe /c winrm set \"winrm/config/client/auth\" '@{Basic=\"true\"}'\r\ncmd.exe /c winrm set \"winrm/config/service/auth\" '@{CredSSP=\"true\"}'\r\ncmd.exe /c winrm set \"winrm/config/listener?Address=*+Transport=HTTPS\" \"@{Port=`\"5986`\";Hostname=`\"packer`\";CertificateThumbprint=`\"$($Cert.Thumbprint)`\"}\"\r\ncmd.exe /c netsh advfirewall firewall set rule group=\"remote administration\" new enable=yes\r\ncmd.exe /c netsh firewall add portopening TCP 5986 \"Port 5986\"\r\ncmd.exe /c net stop winrm\r\ncmd.exe /c sc config winrm start= auto\r\ncmd.exe /c net start winrm\r\n\r\n</powershell>\r\n```"},"comment":{"url":"https://api.github.com/repos/hashicorp/packer/issues/comments/413038247","html_url":"https://github.com/hashicorp/packer/issues/6297#issuecomment-413038247","issue_url":"https://api.github.com/repos/hashicorp/packer/issues/6297","id":413038247,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzAzODI0Nw==","user":{"login":"shadycuz","id":17090999,"node_id":"MDQ6VXNlcjE3MDkwOTk5","avatar_url":"https://avatars1.githubusercontent.com/u/17090999?v=4","gravatar_id":"","url":"https://api.github.com/users/shadycuz","html_url":"https://github.com/shadycuz","followers_url":"https://api.github.com/users/shadycuz/followers","following_url":"https://api.github.com/users/shadycuz/following{/other_user}","gists_url":"https://api.github.com/users/shadycuz/gists{/gist_id}","starred_url":"https://api.github.com/users/shadycuz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shadycuz/subscriptions","organizations_url":"https://api.github.com/users/shadycuz/orgs","repos_url":"https://api.github.com/users/shadycuz/repos","events_url":"https://api.github.com/users/shadycuz/events{/privacy}","received_events_url":"https://api.github.com/users/shadycuz/received_events","type":"User","site_admin":false},"created_at":"2018-08-14T22:37:14Z","updated_at":"2018-08-14T22:37:14Z","author_association":"CONTRIBUTOR","body":"How would you deal with this on a 2012r2? @lmayorga1980 @SNikalaichyk \r\n"}}
{"actor":{"display_login":"shadycuz"}}