How to use AWS IAM Role for Packer build command inside Jenkins Pipeline using Kubernetes / Docker Slave

4/19/2019

I'm using Jenkins Pipeline and Packer to create AMI inside an AWS Account.

  • The Jenkins uses Kubernetes cluster as slave (using a cloud plugin that allows me to parameter docker pods template),

  • I have a pipeline that pull git project with the packer template in it and run packer validate command which is a success. Than, it runs packer build and i get the following error:

[1;31mBuild 'Amazon Linux 2 Classic' errored: No valid credential sources found for AWS Builder. Please see https://www.packer.io/docs/builders/amazon.html#specifying-amazon-credentials for more information on providing credentials for the AWS Builder.[0m

I also use Kube2iam to provide roles on my slave containers.

In my packer template, i don't define any aws credentials since I don't want to use it but role. Do you know if I have something to do inside the packer template to indicate the role to use ?

Best Regards,

Tony.

-- Tony Lecointre
amazon-iam
amazon-web-services
jenkins-pipeline
kubernetes
packer

1 Answer

4/19/2019

From what I understand, you are running Jenkins inside a Kubernetes cluster running on AWS EC2 instances? If so, the Jenkins agents running the build should be able to read available roles from the metadata of the instance they're running on.

In this case, the process would be to assign the desire IAM role to instances and Kubernetes should be able to handle that.

-- Andrei Dascalu
Source: StackOverflow