Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

pravargauba

🏠
Working from home
View GitHub Profile
View ec2_main.tf
resource "aws_instance" "ec2" {
ami = "${data.aws_ami.ami.id}"
instance_type = "${var.instance_type}"
key_name = "${var.key_pair}"
vpc_security_group_ids = ["${aws_security_group.ec2-sg.id}"]
subnet_id = "${element(random_shuffle.subnet.result,0)}"
user_data = "${data.template_file.user_data.rendered}"
iam_instance_profile = "${aws_iam_instance_profile.ec2-profile.id}"
user_data = "${data.template_file.user_data.rendered}"
associate_public_ip_address = "${var.associate_public_ip_address}"
View Plan
stage('Plan') {
steps {
sh 'terraform init [ -f terraform.tfstate ] && rm terraform.tfstate '
sh 'terraform plan –out=tfplan.txt '
}
}
View Apply
stage('Apply') {
steps {
sh ‘terraform apply -auto-approve tfplan.txt '
sh ‘echo "`terraform output`" | mail -s "${Env^} EC2 created by ${BUILD_USER} for ${Team} Team in ${region} region" -r email@company-domain.com email@company-domain.com’
}
}
View spotinst
curl -X POST \
'https://api.spotinst.io/aws/ec2/statefulMigrationGroup?accountId={act-1234xyz}’ \
-H 'Authorization: Bearer <authorization_token>’ \
-H 'Content-Type: application/json' \
-H 'Postman-Token: <postman_token>' \
-H 'cache-control: no-cache' \
-d '{
"statefulMigrationGroup": {
"shouldKeepPrivateIp": true,
"originalInstanceId": "'"$instance_id"'",
View Checkout
stage('Checkout') {
steps {
checkout scm
sh ' cd devops/terraform/modules/ec2/'
sh """ sed -i '/instance_type=.*/c instance_type='\""${instance_type}"\"'' terraform.tfvars
sed -i '/key_pair=.*/c key_pair='\""${key_pair}"\"'' terraform.tfvars
sed -i '/ami_name=.*/c ami_name='\""${ami_name}"\"'' terraform.tfvars
sed -i '/subnet=.*/c subnet='\""${subnet}"\"'' terraform.tfvars
sed -i '/root_vol_size=.*/c root_vol_size='\""${root_vol_size}"\"'' terraform.tfvars
sed -i '/root_vol_delete_on_termination=.*/c root_vol_delete_on_termination='\""${root_vol_delete_on_termination}"\"'' terraform.tfvars
View Approval
stage('Approval') {
steps {
script {
def userInput = input(id: 'confirm', message: 'Apply Terraform?', parameters: [ [$class: 'BooleanParameterDefinition', defaultValue: false, description: 'Apply terraform', name: 'confirm'] ])
}
}
}
You can’t perform that action at this time.