Automating AWS Infrastructure Deployment Using Jenkins and Terraform: A Step-by-Step Guide
Jagan Rajagopal AWS Certified Solution Associate ,Aws Coach Jagan ,Azure ,Terraform
AWS Certified Solution Architect | 6K Followers | Aws Coach Jagan Certified AWS Solutions Architect | Freelance on Cloud | DevOps Expert | Azure Solution Architect | Terraform | Gitlab | Devops | Kubernetes | IAC
Prerequisites
Steps
Step 1: Configure AWS Credentials in Jenkins
Step 2: Create Terraform Code
Create a simple Terraform configuration for deploying an EC2 instance. For example, create a file named main.tf in your repository with the following content:
main.tf
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
output "ip" {
value = aws_instance.example.public_ip
}
Step 3: Create a Jenkins Pipeline
In the pipeline configuration:
pipeline {
agent any
environment {
领英推荐
AWS_ACCESS_KEY_ID = credentials('aws-terraform')
AWS_SECRET_ACCESS_KEY = credentials('aws-terraform')
}
stages {
stage('Checkout Code') {
steps {
}
}
stage('Init Terraform') {
steps {
sh 'terraform init'
}
}
stage('Apply Terraform') {
steps {
sh 'terraform apply -auto-approve'
}
}
}
}
Step 4: Run Your Pipeline
Please follow me : https://www.dhirubhai.net/in/jagan-rajagopal/
Free Newsletter Devops Best practise:https://www.dhirubhai.net/newsletters/devops-real-world-practise-7183495093687918592/
Offical page: www.dhirubhai.net/company/awstrainingwithjagan
Website : https://awstrainingwithjagan.com/
Instagram personal page:https://www.instagram.com/awscoachjagan/
Twitter personal page:https://twitter.com/jagan_rajagopal