使用私钥创建打包程序后,AWS AMI 无法检索密码

AWS AMI cannot retrieve password after packer creation using private key

我正在使用加壳器构建一个 windows 服务器 AMI。它使用硬编码密码可以正常工作,但我正在尝试创建 AMI 以便自动生成密码。我尝试了下面的建议,加壳日志看起来不错,它获得了密码。

How to create windows image in packer using the keypair

然而,当我在 terraform 中从 AMI 创建 EC2 实例时,与 windows 密码的连接丢失并且无法检索。这里缺少什么?

打包机json

{  
  "builders": [
    {
      "profile" : "blah",
      "type": "amazon-ebs",
      "region": "eu-west-1",
      "instance_type": "t2.micro",
      "source_ami_filter": {
        "filters": {
          "virtualization-type": "hvm",
          "name": "*Windows_Server-2012-R2*English-64Bit-Base*",
          "root-device-type": "ebs"
        },
        "most_recent": true,
        "owners": "amazon"
      },
      "ssh_keypair_name" : "shared.key",
      "ssh_private_key_file" : "./common/sharedkey.pem",
      "ssh_agent_auth" : "true",
      "ami_name": "test-{{timestamp}}",
      "user_data_file": "./common/bootstrap_win.txt",
      "communicator": "winrm",
      "winrm_username": "Administrator"      
    }
  ]
}

在最后添加 Ec2Config.exe -sysprep 有效。

{
      "type": "windows-shell",
      "inline": ["C:\progra~1\Amazon\Ec2ConfigService\Ec2Config.exe -sysprep"]
}

不过请注意,我的 IIS 配置似乎在 sysprep 后不起作用。