Packer build issues on credentials, validate passes

161 views
Skip to first unread message

MDR

unread,
May 24, 2021, 2:43:08 PM5/24/21
to Packer
Hello Packer Community -

New to Packer and following a course in Packer. Using Packer 1.7.2 on Ubun 20.10 VM.

Trying to deploy to AWS and I am running under an user I created in AWS which is part of group Administrator and has all privileges. I am running in a vagrant box as it allows me to keep to latest toolsets. This is shown below.
----------
My packer validate passes but packer build fails:
Error: Datasource.Execute failed: no valid credential sources for  found.
Please see 
for more information about providing credentials.
Error: NoCreentialProviders: no valid providers in chain. Deprecated.
For verbose messaging see aws.Config.CredentialsChainVerboseErrors
  on template.json.pkr.hcl line 21:
  (source code shown below)
----------
I am using AWS CLI 2 and credentials file + config file are ok.
In fact sts get caller-identitity returns fine.

vagrant@vbUBUNiINFRA1:~$ aws.sts.get-caller-identity
3304XXXX arn:aws:iam::3304XXXX:user/mono-acc.admin XXXXXXXXXXXXX
vagrant@vbUBUNiINFRA1:~$ aws.version
aws-cli/2.2.5 Python/3.8.8 Linux/5.8.0-53-generic exe/x86_64.ubuntu.20 prompt/off
----------
The file I am trying to validate is as follows:
The ssh-username  (below) is the only thing I change from the example (in book) to the default user in my credentials file based on which sts caller identity runs.

Not sure is ssh-username is the issue and what the ssh-username should be?
line 21 - where error shown occurs - is bolded-italicized

I use the same credentials and config file to run Terraform fine.
Thus I am not understanding as to why a similarly configured Packer templ will not work?
----------
variable "aws_profile" {
  type    = string
  default = "AWS PROFILE"
}

variable "region" {
  type    = string
  default = "AWS REGION"
}

variable "instance_type" {
  type    = string
  default = "EC2 INSTANCE TYPE"
}

variable "source_ami" {
  type    = string
  default = "AMAZON LINUX AMI ID"
}

data "amazon-ami" "autogenerated_1" {
  filters = {
    name                = "Amazon Linux AMI-*"
    root-device-type    = "ebs"
    virtualization-type = "hvm"
  }
  most_recent = true
  owners      = ["amazon"]
  profile     = "${var.aws_profile}"
  region      = "${var.region}"
}

source "amazon-ebs" "autogenerated_1" {
  ami_description = "Amazon Linux Image with Jenkins Server"
  ami_name        = "jenkins-master-2.204.1"
  instance_type   = "${var.instance_type}"
  profile         = "${var.aws_profile}"
  region          = "${var.region}"
  source_ami      = "${data.amazon-ami.autogenerated_1.id}"
  ssh_username    = "mono-acc.admin"
}

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

  provisioner "shell" {
    execute_command = "sudo -E -S sh '{{ .Path }}'"
    script          = "./setup.sh"
  }
}
----------
Thanks for your help and insight.

Mono
Reply all
Reply to author
Forward
0 new messages