toowoxx / terraform-provider-packer

Terraform Provider for HashiCorp Packer
Mozilla Public License 2.0
32 stars 7 forks source link

Terraform Apply Stuck #11

Closed kholisrag closed 2 years ago

kholisrag commented 2 years ago

Got terraform apply stuck with :

main.tf

provider "packer" {}

provider "aws" {
  region = var.aws_region
}

locals {
  name = format("%s-%s-ami-ubuntu-%s", var.ami_name_prefix, var.nomad_version, var.ubuntu_version)

  tags = {
    Name          = local.name
    project       = var.project
    environment   = var.environment
    unique_id     = var.unique_id
    customer_name = var.customer_name
  }

  packer_ami_tags = join(",", [
    for key, value in local.tags : format("%s=%s", key, value)
  ])
  packer_ami_regions = join(",", var.ami_regions)
}

data "packer_version" "version" {}

data "packer_files" "nomad_ami" {
  # count     = var.create_nomad_ami ? 1 : 0
  directory = "manifest"
}

resource "packer_image" "nomad_ami" {
  # count     = var.create_nomad_ami ? 1 : 0
  name               = local.name
  force              = true
  ignore_environment = true
  directory          = data.packer_files.nomad_ami.directory

  variables = {
    ami_architecture                  = var.ami_architecture
    ami_name_prefix                   = var.ami_name_prefix
    ami_regions                       = local.packer_ami_regions
    ami_tags                          = local.packer_ami_tags
    aws_region                        = var.aws_region
    consul_template_version           = var.consul_template_version
    consul_version                    = var.consul_version
    containerd_version                = var.containerd_version
    docker_version                    = var.docker_version
    instance_type                     = var.instance_type
    justice_play_tools_list           = var.justice_play_tools_list
    justice_play_tools_s3_bucket_name = var.justice_play_tools_s3_bucket_name
    nomad_version                     = var.nomad_version
    subnet_id                         = var.subnet_id
    ubuntu_codename                   = var.ubuntu_codename
    ubuntu_version                    = var.ubuntu_version
    vault_version                     = var.vault_version
    vpc_id                            = var.vpc_id
  }

  triggers = {
    packer_version          = data.packer_version.version.version
    files_hash              = data.packer_files.nomad_ami.files_hash
    nomad_version           = var.nomad_version
    consul_version          = var.consul_version
    consul_template_version = var.consul_template_version
    vault_version           = var.vault_version
  }
}

logs :

2022-05-27T16:27:03.653+0700 [TRACE] provider.stdio: waiting for stdio data
2022-05-27T16:27:03.653+0700 [TRACE] provider.stdio: received data: channel=STDOUT len=14
2022-05-27T16:27:03.653+0700 [WARN]  unexpected data: registry.terraform.io/toowoxx/packer:stdout="Packer v1.8.0"
2022-05-27T16:27:03.653+0700 [TRACE] provider.stdio: waiting for stdio data
2022-05-27T16:27:03.653+0700 [TRACE] provider.stdio: received data: channel=STDERR len=100
2022-05-27T16:27:03.653+0700 [WARN]  unexpected data: registry.terraform.io/toowoxx/packer:stderr="[ERR] Checkpoint setup error: No $HOME environment variable found, required to set Config Directory"
2022-05-27T16:27:03.653+0700 [TRACE] provider.stdio: waiting for stdio data
2022-05-27T16:27:03.653+0700 [TRACE] provider.stdio: received data: channel=STDERR len=48
2022-05-27T16:27:03.653+0700 [WARN]  unexpected data: registry.terraform.io/toowoxx/packer:stderr="waiting for all plugin processes to complete..."
2022-05-27T16:27:03.653+0700 [TRACE] provider.stdio: waiting for stdio data
2022-05-27T16:27:03.658+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Called downstream: tf_proto_version=6 tf_provider_addr=packer @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:369 @module=sdk.proto tf_req_id=c1ead27f-af7d-acf4-5014-e0d75390bb6a tf_rpc=ConfigureProvider timestamp=2022-05-27T16:27:03.658+0700
2022-05-27T16:27:03.658+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Served request: @module=sdk.proto tf_rpc=ConfigureProvider tf_proto_version=6 tf_provider_addr=packer tf_req_id=c1ead27f-af7d-acf4-5014-e0d75390bb6a @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:375 timestamp=2022-05-27T16:27:03.658+0700
2022-05-27T16:27:03.658+0700 [TRACE] vertex "provider[\"registry.terraform.io/toowoxx/packer\"]": visit complete
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_files.nomad_ami (expand)": starting visit (*terraform.nodeExpandApplyableResource)
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_files.nomad_ami (expand)": expanding dynamic subgraph
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_version.version (expand)": starting visit (*terraform.nodeExpandApplyableResource)
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_version.version (expand)": expanding dynamic subgraph
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_version.version (expand)": entering dynamic subgraph
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_version.version": starting visit (*terraform.NodeApplyableResource)
2022-05-27T16:27:03.658+0700 [TRACE] vertex "packer_image.nomad_ami (expand)": starting visit (*terraform.nodeExpandApplyableResource)
2022-05-27T16:27:03.658+0700 [TRACE] vertex "packer_image.nomad_ami (expand)": expanding dynamic subgraph
2022-05-27T16:27:03.658+0700 [TRACE] vertex "packer_image.nomad_ami (expand)": entering dynamic subgraph
2022-05-27T16:27:03.658+0700 [TRACE] vertex "packer_image.nomad_ami": starting visit (*terraform.NodeApplyableResource)
2022-05-27T16:27:03.658+0700 [TRACE] vertex "packer_image.nomad_ami": visit complete
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_files.nomad_ami (expand)": entering dynamic subgraph
2022-05-27T16:27:03.658+0700 [TRACE] vertex "packer_image.nomad_ami (expand)": dynamic subgraph completed successfully
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_files.nomad_ami": starting visit (*terraform.NodeApplyableResource)
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_files.nomad_ami": visit complete
2022-05-27T16:27:03.658+0700 [TRACE] vertex "data.packer_files.nomad_ami (expand)": dynamic subgraph completed successfully
2022-05-27T16:27:03.659+0700 [TRACE] vertex "data.packer_files.nomad_ami (expand)": visit complete
2022-05-27T16:27:03.659+0700 [TRACE] vertex "packer_image.nomad_ami (expand)": visit complete
2022-05-27T16:27:03.659+0700 [TRACE] vertex "data.packer_version.version": visit complete
2022-05-27T16:27:03.659+0700 [TRACE] vertex "data.packer_version.version (expand)": dynamic subgraph completed successfully
2022-05-27T16:27:03.659+0700 [TRACE] vertex "data.packer_version.version (expand)": visit complete
2022-05-27T16:27:03.659+0700 [TRACE] vertex "packer_image.nomad_ami": starting visit (*terraform.NodeApplyableResourceInstance)
2022-05-27T16:27:03.659+0700 [TRACE] readDiff: Read Create change from plan for packer_image.nomad_ami
2022-05-27T16:27:03.659+0700 [TRACE] readResourceInstanceState: reading state for packer_image.nomad_ami
2022-05-27T16:27:03.659+0700 [TRACE] readResourceInstanceState: no state present for packer_image.nomad_ami
2022-05-27T16:27:03.659+0700 [TRACE] readDiff: Read Create change from plan for packer_image.nomad_ami
2022-05-27T16:27:03.659+0700 [TRACE] Re-validating config for "packer_image.nomad_ami"
2022-05-27T16:27:03.659+0700 [TRACE] GRPCProvider.v6: ValidateResourceConfig
2022-05-27T16:27:03.659+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Received request: @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:496 @module=sdk.proto tf_provider_addr=packer tf_req_id=922ba0dd-7214-3eb4-9246-d2156b14f789 tf_rpc=ValidateResourceConfig tf_proto_version=6 tf_resource_type=packer_image timestamp=2022-05-27T16:27:03.659+0700
2022-05-27T16:27:03.659+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Calling downstream: @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:503 @module=sdk.proto tf_proto_version=6 tf_provider_addr=packer tf_req_id=922ba0dd-7214-3eb4-9246-d2156b14f789 tf_resource_type=packer_image tf_rpc=ValidateResourceConfig timestamp=2022-05-27T16:27:03.659+0700
2022-05-27T16:27:03.660+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Called downstream: tf_req_id=922ba0dd-7214-3eb4-9246-d2156b14f789 tf_proto_version=6 tf_provider_addr=packer tf_resource_type=packer_image tf_rpc=ValidateResourceConfig @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:509 @module=sdk.proto timestamp=2022-05-27T16:27:03.660+0700
2022-05-27T16:27:03.660+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Served request: tf_rpc=ValidateResourceConfig @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:515 @module=sdk.proto tf_provider_addr=packer tf_resource_type=packer_image tf_proto_version=6 tf_req_id=922ba0dd-7214-3eb4-9246-d2156b14f789 timestamp=2022-05-27T16:27:03.660+0700
2022-05-27T16:27:03.660+0700 [TRACE] GRPCProvider.v6: PlanResourceChange
2022-05-27T16:27:03.660+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Received request: @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:571 tf_proto_version=6 tf_req_id=0d8d2387-12ac-e0d7-9c99-83a85ed4d3f4 @module=sdk.proto tf_provider_addr=packer tf_resource_type=packer_image tf_rpc=PlanResourceChange timestamp=2022-05-27T16:27:03.660+0700
2022-05-27T16:27:03.660+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Calling downstream: @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:578 tf_resource_type=packer_image tf_req_id=0d8d2387-12ac-e0d7-9c99-83a85ed4d3f4 tf_rpc=PlanResourceChange @module=sdk.proto tf_proto_version=6 tf_provider_addr=packer timestamp=2022-05-27T16:27:03.660+0700
2022-05-27T16:27:03.661+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Called downstream: tf_rpc=PlanResourceChange @module=sdk.proto tf_proto_version=6 tf_req_id=0d8d2387-12ac-e0d7-9c99-83a85ed4d3f4 @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:584 tf_provider_addr=packer tf_resource_type=packer_image timestamp=2022-05-27T16:27:03.661+0700
2022-05-27T16:27:03.661+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Served request: @module=sdk.proto tf_resource_type=packer_image tf_rpc=PlanResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:590 tf_provider_addr=packer tf_req_id=0d8d2387-12ac-e0d7-9c99-83a85ed4d3f4 tf_proto_version=6 timestamp=2022-05-27T16:27:03.661+0700
2022-05-27T16:27:03.661+0700 [TRACE] checkPlannedChange: Verifying that actual change (action Create) matches planned change (action Create)
2022-05-27T16:27:03.661+0700 [TRACE] readResourceInstanceState: reading state for packer_image.nomad_ami
2022-05-27T16:27:03.661+0700 [TRACE] readResourceInstanceState: no state present for packer_image.nomad_ami
2022-05-27T16:27:03.661+0700 [INFO]  Starting apply for packer_image.nomad_ami
2022-05-27T16:27:03.662+0700 [DEBUG] packer_image.nomad_ami: applying the planned Create change
2022-05-27T16:27:03.662+0700 [TRACE] GRPCProvider.v6: ApplyResourceChange
2022-05-27T16:27:03.662+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Received request: tf_proto_version=6 tf_provider_addr=packer tf_resource_type=packer_image @module=sdk.proto tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:596 tf_req_id=3fcca3b7-b63c-6ee9-f92f-7e551837b9e2 timestamp=2022-05-27T16:27:03.662+0700
2022-05-27T16:27:03.662+0700 [TRACE] provider.terraform-provider-packer_v0.11.0: Calling downstream: @module=sdk.proto tf_proto_version=6 tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov6/tf6server/server.go:603 tf_provider_addr=packer tf_req_id=3fcca3b7-b63c-6ee9-f92f-7e551837b9e2 tf_resource_type=packer_image timestamp=2022-05-27T16:27:03.662+0700
2022-05-27T16:27:08.483+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:08.484+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:13.484+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:13.485+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:18.486+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:18.486+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:23.487+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:23.487+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:28.488+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:28.488+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:33.490+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:33.490+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:38.491+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:38.491+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:43.492+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:43.492+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:48.494+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:48.494+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:53.496+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:53.496+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:27:58.496+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:27:58.496+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:03.496+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:03.496+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:08.497+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:08.497+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:13.499+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:13.499+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:18.501+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:18.501+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:23.501+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:23.501+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:28.502+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:28.503+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:33.503+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:33.503+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:38.504+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:38.505+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:43.507+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:43.507+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:48.507+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:48.507+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:53.508+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:53.508+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:28:58.511+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:28:58.511+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:03.511+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:03.511+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:08.512+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:08.512+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:13.515+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:13.515+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:18.515+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:18.515+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:23.518+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:23.518+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:28.519+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:28.519+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:33.520+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:33.520+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:38.523+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:38.523+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:43.523+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:43.523+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:48.524+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:48.524+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:53.527+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:29:53.527+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:58.527+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:29:58.527+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:03.528+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:03.528+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:08.529+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:08.529+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:13.531+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:13.531+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:18.531+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:18.531+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:23.532+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:23.532+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:28.534+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:28.534+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:33.535+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:33.535+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:38.536+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:38.536+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:43.539+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:43.539+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:48.539+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:48.539+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:53.540+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:53.540+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:30:58.543+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:30:58.543+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:03.543+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:03.543+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:08.543+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:08.543+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:13.544+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:13.544+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:18.545+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:18.545+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:23.547+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:23.547+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:28.547+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:28.547+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:33.548+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:33.548+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:38.549+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:38.549+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:43.552+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:43.552+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:48.552+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:48.552+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:53.552+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:53.553+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:31:58.555+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:31:58.555+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:03.555+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:03.555+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:08.557+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:08.558+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:13.559+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:13.559+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:18.561+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:18.561+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:23.563+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:23.563+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:28.563+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:28.563+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:33.564+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:33.564+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:38.566+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:38.566+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:43.567+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:43.567+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:48.567+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:48.568+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:53.570+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:53.570+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:32:58.571+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:32:58.571+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:33:03.572+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:33:03.573+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"
2022-05-27T16:33:08.575+0700 [TRACE] dag/walk: vertex "root" is waiting for "provider[\"registry.terraform.io/toowoxx/packer\"] (close)"
2022-05-27T16:33:08.575+0700 [TRACE] dag/walk: vertex "provider[\"registry.terraform.io/toowoxx/packer\"] (close)" is waiting for "packer_image.nomad_ami"

but when building directly with packer its work

simaotwx commented 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.

kholisrag commented 2 years ago

@simaotwx waiting for 1 hour before, but still stuck...

When using packer directly only wait for 20 minutes

simaotwx commented 2 years ago

Is there a reason you specified ignore_environment = true? Also which OS and Terraform version are you using?

karelorigin commented 2 years ago

@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.

simaotwx commented 2 years ago

That's really weird. Nothing changed here so there must be something that changed outside of our control.

karelorigin commented 2 years ago

@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).

simaotwx commented 2 years ago

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

kholisrag commented 2 years ago

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

simaotwx commented 2 years ago

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.

simaotwx commented 2 years ago

Any news on this topic?

simaotwx commented 2 years ago

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.