Closed kholisrag closed 2 years ago
You need to wait until the Packer image is built. There is no console output while this happens. I don't think it's possible to log the current progress to the console via Terraform.
If the build fails, you get the log output of Packer. Please let me know if this answers your question.
@simaotwx waiting for 1 hour before, but still stuck...
When using packer directly only wait for 20 minutes
Is there a reason you specified ignore_environment = true
?
Also which OS and Terraform version are you using?
@simaotwx, I experienced the same issue earlier today. Terraform will normally log status updates every 10 seconds but suddenly it stopped. Had to force kill the process. A provider shouldn't be able to build a resource for longer than an hour unless explicitly configured since the default timeout (provided by Terraform core) is 20 minutes, so there must be some kind of issue going on here. Otherwise Terraform would have exited with status code 1.
That's really weird. Nothing changed here so there must be something that changed outside of our control.
@simaotwx, I ran it again in debug mode and it seems like this might be related to #12. Unfortunately, there were no detailed error messages but it did say "Failed to run packer build:", which should confirm it, considering that this all works locally but not in TF Cloud (where packer init
is never executed).
It's weird that that's the only thing returned. The error is here: https://github.com/toowoxx/terraform-provider-packer/blob/main/provider/resource_packer_image.go#L191 and it should contain more than just "Failed to run packer build:". I will have to look deeper into this. Also in TF Cloud, if you use this provider, packer init
is run here: https://github.com/toowoxx/terraform-provider-packer/blob/main/provider/resource_packer_image.go#L191
Is there a reason you specified
ignore_environment = true
? Also which OS and Terraform version are you using?
@simaotwx no reason, trying both ignore_environment = true
or ignore_environment = false
, not working,
OS : Ubuntu 20.04
Packer : Linuxbrew, brew install hashicorp/tap/packer
Terraform : Linuxbrew,
❯ which terraform
/home/linuxbrew/.linuxbrew/bin/terraform
❯ terraform version
Terraform v1.1.8
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v4.16.0
+ provider registry.terraform.io/hashicorp/external v2.2.2
+ provider registry.terraform.io/hashicorp/local v2.2.3
+ provider registry.terraform.io/toowoxx/packer v0.12.0
tried using files / directory, its still stuck
pkr.hcl
packer {
required_version = ">= 1.8.0"
}
variable "aws_region" {
type = string
description = "AWS Region"
default = "us-west-2"
}
variable "ami_regions" {
type = string
description = "A comma separated string value of regions to copy the AMI to"
default = "us-east-1,eu-central-1,ap-southeast-1"
}
variable "vpc_id" {
type = string
description = "VPC ID, Where Packer Builder will be executed"
}
variable "subnet_id" {
type = string
description = "Subnet ID of VPC ID, Where Packer Builder will be executed"
}
variable "ubuntu_codename" {
type = string
description = "Ubuntu Codename, how to get : `lsb_release -cs`"
default = "focal"
}
variable "ubuntu_version" {
type = string
description = "Ubuntu Version"
default = "20.04"
}
variable "docker_version" {
type = string
description = "Docker CE Package, full version string"
default = "5:20.10.16~3-0~ubuntu-focal"
}
variable "containerd_version" {
type = string
description = "ContainerD Package, full version string"
default = "1.6.4-1"
}
variable "nomad_version" {
type = string
description = "Nomad binary version (https://releases.hashicorp.com/nomad)"
}
variable "consul_version" {
type = string
description = "Consul binary version (https://releases.hashicorp.com/consul)"
}
variable "consul_template_version" {
type = string
description = "Consul Template binary version (https://releases.hashicorp.com/consul-template)"
}
variable "vault_version" {
type = string
description = "Vault binary version (https://releases.hashicorp.com/vault)"
}
variable "cni_plugins_version" {
type = string
description = "CNI Plugins version (https://github.com/containernetworking/plugins/releases/)"
}
variable "ami_name_prefix" {
type = string
description = "Name Prefix for the generated AMI"
}
variable "ami_tags" {
type = string
description = "Key Value Pair Tags with comma separated, to pass to Packer Builded's AMI"
}
variable "ami_users" {
type = string
description = "AWS Account ID with comma separated, that can use this AMI"
}
variable "ami_org_arns" {
type = string
description = "AWS Organization ARN with comma separated, that can use this AMI"
}
locals {
time_now = timestamp()
packer_ami_tag_list = flatten([
for pair in split(",", var.ami_tags) : convert(pair, string)
])
packer_ami_tag_pair = zipmap(
flatten([for key in local.packer_ami_tag_list : replace(regex(".*=", key), "=", "")]),
flatten([for key in local.packer_ami_tag_list : replace(regex("=.*", key), "=", "")])
)
packer_ami_regions = var.ami_regions != "" ? split(",", var.ami_regions) : null
packer_ami_users = var.ami_users != "" ? split(",", var.ami_users) : null
packer_ami_org_arns = var.ami_org_arns != "" ? split(",", var.ami_org_arns) : null
skip_region_validation = var.ami_regions == "" ? true : false
}
source "amazon-ebs" "nomad_ami_amd64" {
#- Change this to true, when you're debugging / adding a feature
#- ref: https://www.packer.io/plugins/builders/amazon/ebs#skip_create_ami
skip_create_ami = false
ami_name = format("%s-%s-ami-ubuntu-%s-amd64-%s", var.ami_name_prefix, var.nomad_version, var.ubuntu_version, formatdate("YYYYMMDDhhmmss", local.time_now))
ami_description = format("Ubuntu %s AMI with Nomad, Consul, Vault and Docker installed", var.ubuntu_version)
ami_regions = local.packer_ami_regions
ami_users = local.packer_ami_users
ami_org_arns = local.packer_ami_org_arns
skip_region_validation = local.skip_region_validation
region = var.aws_region
vpc_id = var.vpc_id
subnet_id = var.subnet_id
instance_type = "t3a.small"
source_ami_filter {
filters = {
name = format("ubuntu/images/hvm-ssd/ubuntu-%s-%s-amd64-server-*", var.ubuntu_codename, var.ubuntu_version)
root-device-type = "ebs"
virtualization-type = "hvm"
architecture = "x86_64"
}
owners = ["099720109477"]
most_recent = true
}
temporary_iam_instance_profile_policy_document {
Statement {
Effect = "Allow"
Resource = [
"arn:aws:s3:::test-tools/*",
"arn:aws:s3:::test-tools"
]
Action = [
"s3:GetObject",
"s3:ListBucket"
]
}
Statement {
Effect = "Allow"
Resource = ["*"]
Action = [
"ssm:DescribeAssociation",
"ssm:GetDeployablePatchSnapshotForInstance",
"ssm:GetDocument",
"ssm:DescribeDocument",
"ssm:GetManifest",
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:ListAssociations",
"ssm:ListInstanceAssociations",
"ssm:PutInventory",
"ssm:PutComplianceItems",
"ssm:PutConfigurePackageResult",
"ssm:UpdateAssociationStatus",
"ssm:UpdateInstanceAssociationStatus",
"ssm:UpdateInstanceInformation",
]
}
Statement {
Effect = "Allow"
Resource = ["*"]
Action = [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel",
]
}
Statement {
Effect = "Allow"
Resource = ["*"]
Action = [
"ec2messages:AcknowledgeMessage",
"ec2messages:DeleteMessage",
"ec2messages:FailMessage",
"ec2messages:GetEndpoint",
"ec2messages:GetMessages",
"ec2messages:SendReply",
]
}
Version = "2012-10-17"
}
communicator = "ssh"
ssh_interface = "session_manager"
ssh_username = "ubuntu"
ssh_timeout = "5m"
pause_before_ssm = "10s"
dynamic "tag" {
for_each = local.packer_ami_tag_pair
content {
key = tag.key
value = tag.value
}
}
}
source "amazon-ebs" "nomad_ami_arm64" {
#- Change this to true, when you're debugging / adding a feature
#- ref: https://www.packer.io/plugins/builders/amazon/ebs#skip_create_ami
skip_create_ami = false
ami_name = format("%s-%s-ami-ubuntu-%s-arm64-%s", var.ami_name_prefix, var.nomad_version, var.ubuntu_version, formatdate("YYYYMMDDhhmmss", local.time_now))
ami_description = format("Ubuntu %s AMI with Nomad, Consul, Vault and Docker installed", var.ubuntu_version)
ami_regions = local.packer_ami_regions
ami_users = local.packer_ami_users
ami_org_arns = local.packer_ami_org_arns
skip_region_validation = local.skip_region_validation
region = var.aws_region
vpc_id = var.vpc_id
subnet_id = var.subnet_id
instance_type = "t4g.small"
source_ami_filter {
filters = {
name = format("ubuntu/images/hvm-ssd/ubuntu-%s-%s-arm64-server-*", var.ubuntu_codename, var.ubuntu_version)
root-device-type = "ebs"
virtualization-type = "hvm"
architecture = "arm64"
}
owners = ["099720109477"]
most_recent = true
}
temporary_iam_instance_profile_policy_document {
Statement {
Effect = "Allow"
Resource = [
"arn:aws:s3:::test-tools/*",
"arn:aws:s3:::test-tools"
]
Action = [
"s3:GetObject",
"s3:ListBucket"
]
}
Statement {
Effect = "Allow"
Resource = ["*"]
Action = [
"ssm:DescribeAssociation",
"ssm:GetDeployablePatchSnapshotForInstance",
"ssm:GetDocument",
"ssm:DescribeDocument",
"ssm:GetManifest",
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:ListAssociations",
"ssm:ListInstanceAssociations",
"ssm:PutInventory",
"ssm:PutComplianceItems",
"ssm:PutConfigurePackageResult",
"ssm:UpdateAssociationStatus",
"ssm:UpdateInstanceAssociationStatus",
"ssm:UpdateInstanceInformation",
]
}
Statement {
Effect = "Allow"
Resource = ["*"]
Action = [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel",
]
}
Statement {
Effect = "Allow"
Resource = ["*"]
Action = [
"ec2messages:AcknowledgeMessage",
"ec2messages:DeleteMessage",
"ec2messages:FailMessage",
"ec2messages:GetEndpoint",
"ec2messages:GetMessages",
"ec2messages:SendReply",
]
}
Version = "2012-10-17"
}
communicator = "ssh"
ssh_interface = "session_manager"
ssh_username = "ubuntu"
ssh_timeout = "5m"
pause_before_ssm = "10s"
dynamic "tag" {
for_each = local.packer_ami_tag_pair
content {
key = tag.key
value = tag.value
}
}
}
build {
sources = [
"source.amazon-ebs.nomad_ami_amd64",
"source.amazon-ebs.nomad_ami_arm64"
]
provisioner "file" {
source = format("%s/packer", path.root)
destination = "/tmp/"
}
provisioner "shell" {
inline = [
"chmod -R +x /tmp/packer",
"/tmp/packer/setup-ubuntu.sh"
]
environment_vars = [
format("DOCKER_VERSION=%s", var.docker_version),
format("CONTAINERD_VERSION=%s", var.containerd_version),
format("NOMAD_VERSION=%s", var.nomad_version),
format("CONSUL_VERSION=%s", var.consul_version),
format("VAULT_VERSION=%s", var.vault_version),
format("CONSUL_TEMPLATE_VERSION=%s", var.consul_template_version),
format("CNI_PLUGINS_VERSION=%s", var.cni_plugins_version),
"DEBIAN_FRONTEND=noninteractive"
]
pause_before = "1s"
}
post-processors {
post-processor "manifest" {
output = format("%s/%s-%s-ami-ubuntu-%s.json", path.root, var.ami_name_prefix, var.nomad_version, var.ubuntu_version)
strip_path = true
}
}
}
sorry if not completed, deleted some confidential information
This is difficult to reproduce and I haven't been able to do that so far. Would it be possible for you to provide a minmal example that has the issue? If you can't provide a minimal example, it would be great to know what exactly causes the issue to happen. This can be done in numerous ways, one of which being removing/changing parts of your Terraform/Packer files until it works and then reporting what caused the issue.
Any news on this topic?
There's been no activity for this issue for over a month so I will close this issue. Feel free to reopen if the issue persists and you have more information for us.
Got terraform apply stuck with :
main.tf
logs :
but when building directly with packer its work