Jenkins pipeline to run Terraform + Packer integration with AWS
If you do not have one yet, I recommend you go here and create one first, before you proceeding the following steps.
2. Install Jenkins
Follow the Get Started guide, and configure your jenkins server.
prerequisite installation for jenkins: Java
check that Java has successfully installed by command: java -version
3. install Docker
verify by docker -v
- AWS credentials (we mark this as "aws-credential" in the following doc). go to your Jenkins --> Credentials, create a new AWS credentials with your IAM key and secret. ** hint: If you do not have IAM yet, plz check this link, and create one.
- Git credentials (we mark this as "git-credential" in the following doc). create a new git credential with your git username/password, or access-token
- Login your jenkins platform, create a new folder for the deployment by
New Item --> Folder
. You can provide any name for the folder as your own preference. - Navigate into the folder, create two pipelines items named:
Packer
,Terraform
(This has to be the same as the folder names we use in this repo)
- We are going to your local machine file system, or vm machine if this is what you working on, find the workspace of the Pipelines you just created. Usually it's under
~/.jenkins/workspace/<Your Folder Name>
(or you can find it in the "Home Directory" of<Jenkins_url>/configure
). If there is nothing there, just create one with the same name (Jenkins will also automatically generate the folder when needed) - Then under
~/.jenkins/workspace/<Your Folder Name>
, create a config file namedenvironments.config
, where you can find most values above:
environments.config
// The AWS configs
env.AWS_CREDENTIALS="<aws-credential>"
env.SOURCE_AMI_ID="<>"
// The Git configs
env.GIT_LINK="<The git url where you have your project, if don't have one yet you can use mine: "[email protected]:hotyhuang/testMyApp.git">"
env.GIT_CREDENTIALS="<git-credential>"
// Project related envs
env.PROJECT_NAME="<Any Name without Space!!>"
Now it's ready to run the cicd. You just need to run "Packer", it will internally trigger the "Terraform" job.
If you see the error like Scripts not permitted to use staticMethod...
, you will need to:
- Navigate to jenkins > Manage jenkins > In-process Script Approval
- There was a pending command, which I had to approve.