How to run terraform from Jenkins ? | Jenkins pipeline and Terraform integration | terraform CI/CD

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this lecture we're gonna see how to run terraform from jenkins declarative pipeline okay let's get started i already have jenkins machine with me and it's installed on easy to instance i do have a sample ise project written in terraform and for this we want to set up jenkins declarative pipeline let's go and install a terraform jenkins plugin it's successfully installed and let's go back to home page manage jenkins global tool configurations let's check for terraform add terraform name so we do have options to install automatically so which will install our terraform automatically on our jenkins mission but i want to uncheck that provide the installation directory but our terraform is not yet installed on jenkins box let's go to terraform dot io download cli so for linux we want to install it on linux 64-bit copy link address let's use wget download the chip let's unzip that so we got this a binary which is an executable next we want to add this binary to the path i want to move our terraform binary to user bin right we got this terraform into a path and yes i am able to use that command and check the version let's use this so it just requires installation directory don't include terraform command in this path save it our next step is to create jenkins job pipeline let's go to pipeline i want to add our terraform tools information into our pipeline script open pipeline syntax generator so declarative directive generator tools terraform generated see in our case terraform is in the path so i don't think this is required but still sometimes you might have your terraform command kept somewhere on your local jenkins mission which is not in the path in such cases this will be helpful again if terraform script is there in the path this is redundant if terraform script is not in the path right then this helps okay so this brings our terraform a binary into the path so that we can execute that command in this job so go back to snippet generator so i want to execute terraform in it so but before i execute this i need to have the source code so let's grab this link repository url the branch the credentials so if you want to add credentials of your github i choose username and password provide those details username password id description and add i already have that with me i choose it okay so we have couple of stages stage one is to get checkout stage two is terraform init and likewise stage 3 i want to run terraform apply so i use auto approve because without this switch it prompts us for yes no by default i want to say yes go and apply without prompting me save it let's execute it got failed there is duplicate stage name fine let's fix that save it and build it we might get some other problem right it's able to check out the code and it's also kind of doing init which is downloading our provider details provider plugins then when it comes to apply it and it's unable to locate credentials this could be done in couple of ways i can install jenkins credential plugin i can store access keys and secret keys and wrap it and i mean wrap it around this command so it works otherwise because jenkins is installed inside ec2 instance i can create im role and attach that role to ec instance let's go to im go to roles create role i want this role to be used by ec2 i want to select administrator access tags i want to leave that let me name it terraform jenkins role create role all right come back to ec2 dashboard select ec2 instance that's jenkins instant settings attach the roll terraform jenkins role and apply so come back to our jenkins job build it so it executed successfully it added one resource the code i have here is to create vpc let's go over to our aws management console click vpc your vpcs we should find vpc with name demo vpc let me refresh it taking time for displaying it yeah we have a demo vpc now let's slightly do changes code changes commit changes and go back to jenkins job hit bill now it ran successfully so go to vpc dashboard do a refresh and find the changes are reflecting so guys that's how we integrate jenkins and terraform thanks for watching
Info
Channel: Java Home Cloud
Views: 26,913
Rating: 4.9089026 out of 5
Keywords: java home, java home cloud, devops tutorial, devops by javahome, devops by java home cloud, aws tutorial, aws by javahome, running terrafrom from jenkins, running terraform from jenkins pipeline job, integrating jenkins and terraform, terraform ci cd tutorial, jenkins pipeline demo with terraform, how to run terraform from jenkins, jenkins pipeline tutorial for beginners, terraform jenkins pipeline example, terraform jenkins pipeline script, terraform jenkins pipeline aws
Id: 5jwYGCAr_pw
Channel Id: undefined
Length: 12min 15sec (735 seconds)
Published: Thu Aug 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.