hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.11k stars 3.33k forks source link

amazon-ebs: The flag "-debug" is (partially) ignored (HCL2) #9223

Closed jcttrll closed 4 years ago

jcttrll commented 4 years ago

Overview of the Issue

When I do packer build -debug packer.pkr.hcl, I would expect the SSH private key to be written to a PEM file to the local directory. However, it is not. Also, the build stops at fewer "breakpoints" along the way, compared with a JSON build.

Reproduction Steps

  1. Fill in the vpc_id and subnet_id in the provided templates with ones for your account.
  2. Run the build with:
    packer build -debug packer.pkr.hcl
  3. Compare behavior with:
    packer build -debug packer.json

Packer version

Packer v1.5.6

Simplified Packer Buildfile

Both build files are presented below.

packer.pkr.hcl:
source "amazon-ebs" "bug" {
  subnet_id = "subnet-XXXXXXXX"
  vpc_id = "vpc-XXXXXXXX"
  source_ami = "ami-068663a3c619dd892"
  instance_type = "t2.small"
  ssh_username = "ubuntu"
  ami_name = "packer-{{timestamp}}"
}

build {
  sources = [
    "source.amazon-ebs.bug"
  ]

  provisioner "shell" {
    inline = [
      "echo hello"
    ]
  }
}
packer.json:
{
    "builders": [
        {
            "type": "amazon-ebs",
            "subnet_id": "subnet-XXXXXXXX",
            "vpc_id": "vpc-XXXXXXXX",
            "source_ami": "ami-068663a3c619dd892",
            "instance_type": "t2.small",
            "ssh_username": "ubuntu",
            "ami_name": "packer-{{timestamp}}"
        }
    ],
    "provisioners": [
        {
            "type": "shell",
            "inline": [
                "echo hello"
            ]
        }
    ]
}

Operating system and Environment details

openSUSE Leap 15.1, Linux kernel 4.12.14

Log Fragments and crash.log files

Here is the complete output of the two builds.

From packer build -debug packer.pkr.hcl:
Debug mode enabled. Builds will not be parallelized.
amazon-ebs: output will be in this color.

==> amazon-ebs: Prevalidating any provided VPC information
==> amazon-ebs: Prevalidating AMI Name: packer-1589413384
    amazon-ebs: Found Image ID: ami-068663a3c619dd892
==> amazon-ebs: Creating temporary keypair: packer_5ebc8608-5129-d07a-88d6-126555169aba
==> amazon-ebs: Creating temporary security group for this instance: packer_5ebc860b-f968-9811-7e1a-d4d219b4b4c5
==> amazon-ebs: Authorizing access to port 22 from [0.0.0.0/0] in the temporary security groups...
==> amazon-ebs: Launching a source AWS instance...
==> amazon-ebs: Adding tags to source instance
    amazon-ebs: Adding tag: "Name": "Packer Builder"
    amazon-ebs: Instance ID: i-000173187983c864d
==> amazon-ebs: Waiting for instance (i-000173187983c864d) to become ready...
==> amazon-ebs: Using ssh communicator to connect: 10.42.76.26
==> amazon-ebs: Waiting for SSH to become available...
==> amazon-ebs: Connected to SSH!
==> amazon-ebs: Pausing before the next provisioner . Press enter to continue. 
==> amazon-ebs: Provisioning with shell script: /tmp/packer-shell969628716
    amazon-ebs: hello
==> amazon-ebs: Stopping the source instance...
    amazon-ebs: Stopping instance
==> amazon-ebs: Waiting for the instance to stop...
==> amazon-ebs: Creating AMI packer-1589413384 from instance i-000173187983c864d
    amazon-ebs: AMI: ami-0e65841e823c054e2
==> amazon-ebs: Waiting for AMI to become ready...
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Deleting temporary security group...
==> amazon-ebs: Deleting temporary keypair...
Build 'amazon-ebs' finished.

==> Builds finished. The artifacts of successful builds are:
--> amazon-ebs: AMIs were created:
us-east-1: ami-0e65841e823c054e2
From packer build -debug packer.json:
Debug mode enabled. Builds will not be parallelized.
amazon-ebs: output will be in this color.

==> amazon-ebs: Prevalidating any provided VPC information
==> amazon-ebs: Prevalidating AMI Name: packer-1589413726
==> amazon-ebs: Pausing after run of step 'StepPreValidate'. Press enter to continue. 
    amazon-ebs: Found Image ID: ami-068663a3c619dd892
==> amazon-ebs: Pausing after run of step 'StepSourceAMIInfo'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepNetworkInfo'. Press enter to continue. 
==> amazon-ebs: Creating temporary keypair: packer_5ebc875e-3d27-9f54-03fc-b5b771c4f1a7
    amazon-ebs: Saving key for debug purposes: ec2_amazon-ebs.pem
==> amazon-ebs: Pausing after run of step 'StepKeyPair'. Press enter to continue. 
==> amazon-ebs: Creating temporary security group for this instance: packer_5ebc8778-f03a-37bc-415f-30abc9b76a76
==> amazon-ebs: Authorizing access to port 22 from [0.0.0.0/0] in the temporary security groups...
==> amazon-ebs: Pausing after run of step 'StepSecurityGroup'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepIamInstanceProfile'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepCleanupVolumes'. Press enter to continue. 
==> amazon-ebs: Launching a source AWS instance...
==> amazon-ebs: Adding tags to source instance
    amazon-ebs: Adding tag: "Name": "Packer Builder"
    amazon-ebs: Instance ID: i-0e3b2f064222d2964
==> amazon-ebs: Waiting for instance (i-0e3b2f064222d2964) to become ready...
    amazon-ebs: Private IP: 10.42.76.252
==> amazon-ebs: Pausing after run of step 'StepRunSourceInstance'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepGetPassword'. Press enter to continue. 
==> amazon-ebs: Using ssh communicator to connect: 10.42.76.252
==> amazon-ebs: Waiting for SSH to become available...
==> amazon-ebs: Connected to SSH!
==> amazon-ebs: Pausing after run of step 'StepConnect'. Press enter to continue. 
==> amazon-ebs: Pausing before the next provisioner . Press enter to continue. 
==> amazon-ebs: Provisioning with shell script: /tmp/packer-shell796280718
    amazon-ebs: hello
==> amazon-ebs: Pausing after run of step 'StepProvision'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepCleanupTempKeys'. Press enter to continue. 
==> amazon-ebs: Stopping the source instance...
    amazon-ebs: Stopping instance
==> amazon-ebs: Waiting for the instance to stop...
==> amazon-ebs: Pausing after run of step 'StepStopEBSBackedInstance'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepModifyEBSBackedInstance'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepDeregisterAMI'. Press enter to continue. 
==> amazon-ebs: Creating AMI packer-1589413726 from instance i-0e3b2f064222d2964
    amazon-ebs: AMI: ami-0670428230c02160b
==> amazon-ebs: Waiting for AMI to become ready...
==> amazon-ebs: Pausing after run of step 'stepCreateAMI'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepAMIRegionCopy'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepModifyAMIAttributes'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepCreateTags'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepCreateTags'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepModifyAMIAttributes'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepAMIRegionCopy'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'stepCreateAMI'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepDeregisterAMI'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepModifyEBSBackedInstance'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepStopEBSBackedInstance'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepCleanupTempKeys'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepProvision'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepConnect'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepGetPassword'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepRunSourceInstance'. Press enter to continue. 
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Pausing before cleanup of step 'StepCleanupVolumes'. Press enter to continue. 
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Pausing before cleanup of step 'StepIamInstanceProfile'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepSecurityGroup'. Press enter to continue. 
==> amazon-ebs: Deleting temporary security group...
==> amazon-ebs: Pausing before cleanup of step 'StepKeyPair'. Press enter to continue. 
==> amazon-ebs: Deleting temporary keypair...
==> amazon-ebs: Pausing before cleanup of step 'StepNetworkInfo'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepSourceAMIInfo'. Press enter to continue. 
==> amazon-ebs: Pausing before cleanup of step 'StepPreValidate'. Press enter to continue. 
Build 'amazon-ebs' finished.

==> Builds finished. The artifacts of successful builds are:
--> amazon-ebs: AMIs were created:
us-east-1: ami-0670428230c02160b
ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.