How to Automate Infrastructure setup using Terraform & Jenkins | Terraform Remote State Store in S3
Vložit
- čas přidán 29. 08. 2024
- www.coachdevop...
We will be learning how to provision resources in AWS cloud using Terraform and Jenkins. We will also learn how to store terraform state info remotely in AWS S3 bucket.
We will create S3 bucket for storing terraform state info and DynamoDB table for locking capability.
We will try to create an EC2 instance and S3 Bucket using Terraform and Jenkins in AWS cloud. Look at the diagram that describes the whole flow.
Pre-requistes:
Create S3 bucket for storing TF state
Create dynamo DB table for providing lock capability
Jenkins is up and running
Terraform is installed in Jenkins
Terraform files already created in your SCM
Make sure you have necessary IAM role created with right policy and attached to Jenkins EC2 instance.
Step 1 - Create S3 bucket and DynamoDB table in AWS
Step 2 - Create IAM role with three policies mentioned and attach to Jenkins EC2
Step 3 - Create Jenkins pipeline with parameters
Step 4- Execute pipeline
Hi, Can you please list down some common error we face while working with Terraform and Jenkins in real time.
We can’t generalize that. Terraform State file need to be kept in a remote place. You may have terraform state file locked error when some errors happen during terraform apply
Great video sir. What is the use of dynamoDB here? If you could briefly explain?
DynamoDB is used for exclusive locking to prevent concurrent executions from modifying the same state simultaneously.
Hii , i am getting error in Plan stage , (Error acquiring the state lock) , Solutions for this? , Wts wrong?
is it neccessary to have linux installed in our system to run this? because in my windows built in node , the sh is not recognising terraform init command
you can do it by installing Git or Cygwin.. check the below link
stackoverflow.com/questions/30374998/run-a-command-shell-in-jenkins
Where did you do the authentication for AWS and Jenkins as in access and secret keys?
You can use IAM role that’s is more preferred as I have installed on Jenkins running on aws itself
while checking out, I am getting error. Failed to connect to repository : Error performing git command: git ls-remote -h . Any resolution on this? my inbound and outbound traffic is set to everywhere while trying to resolve it.
Did you fork my repo?
@@DevOpsCoach I did but turned out it was some issue with the plugin. post reinstallation it worked fine.
@@DevOpsCoach thank you
@@DevOpsCoach but for some reason my tf file wouldnt get update to s3 bucket, and created a lock file issue. for now, ignored it to complete the infra, but working on it to find the fix
@@S0912S have u fixed the lock issue
kindly use mic . very very less audible
perfectly audible to me! Keep up the great work @DevOpsCoach
repo link ?
github.com/akannan1087/myInfra2021Repo