Terraform day03
resource "aws_instance" "myec2" {
ami = "ami-082b5a644766e0e6f"
instance_type = "t2.micro"
key_name = "kplabs-terraform"
provisioner "remote-exec" {
inline = [
"sudo amazon-linux-extras install -y nginx1.12",
"sudo systemctl start nginx"
]
connection {
type = "ssh"
user = "ec2-user"
private_key = file("./kplabs-terraform.pem")
host = self.public_ip
}
}
}
Remote Exec Provisioners
Integrating Ansible with Terraform
• Steps:
1. Install Ansible on the system.
2. Write a playbook to install and configure the
applications.
3. Copy and paste the pem file which is tagged to the
instance.
4. Write your tf code to build and provision the instance
. Inside the tf code call ansible playbook to run it like
below.
Files:
nginx.yml
ec2.tf
Terraform day03
Terraform day03
Terraform day03
Terraform day03
Terraform day03
terrafrom workspace show
terraform workspace list
terraform workspace select dev
terraform workspace new prod
• Example:
Project File ( ec2_web.tf )
provider "aws" {
region = "us-west-1"
access_key = "YOUR-ACCESS-KEY-HERE"
secret_key = "YOUR-SECRET-KEY-HERE"
}
module "myec2" {
source = "../../modules/ec2"
}
Modules File ( mod_ec2.tf )
resource "aws_instance" "myweb" {
ami = "ami-bf5540df"
instance_type = "${lookup(var.instance_type, terraform.workspace)}"
security_groups = ["default"]
tags {
Name = "web-server"
}
}
/*
default - t2.nano
dev - t2.micro
prd - m4.large
*/
Modules File ( variables.tf )
variable "instance_type" {
type = "map"
default = {
default = "t2.nano"
dev = "t2.micro"
prd = "m4.large"
}
}
Terraform day03
Terraform day03
Terraform day03
Terraform day03
Configuring Remote State File S3
Backend:
Steps:
• Create s3 bucket in AWS.
• Define terraform code for setting remote backend.
Terraform day03
THANK YOU
•Q & A Session

More Related Content

PPTX
Terraform day02
PDF
Terraform Introduction
PDF
Intro to Terraform
PDF
Declarative & workflow based infrastructure with Terraform
PDF
Terraform introduction
PDF
Infrastructure as Code with Terraform
PPTX
Infrastructure as Code: Introduction to Terraform
PDF
Terraform in action
Terraform day02
Terraform Introduction
Intro to Terraform
Declarative & workflow based infrastructure with Terraform
Terraform introduction
Infrastructure as Code with Terraform
Infrastructure as Code: Introduction to Terraform
Terraform in action

What's hot (19)

PDF
Terraform at Scale - All Day DevOps 2017
PPTX
Terraform at Scale
PDF
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
PPTX
Administering and Monitoring SolrCloud Clusters
PDF
Terraform 0.9 + good practices
PPTX
"Continuously delivering infrastructure using Terraform and Packer" training ...
PDF
Introductory Overview to Managing AWS with Terraform
PDF
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
PDF
Terraform in deployment pipeline
PDF
Refactoring terraform
PPTX
An intro to Docker, Terraform, and Amazon ECS
PDF
Everything as Code with Terraform
PPTX
Terraform Modules and Continuous Deployment
PPT
Hadoop on ec2
PPTX
Terraform modules restructured
PDF
Building Distributed System with Celery on Docker Swarm
PPTX
Dive into DevOps | March, Building with Terraform, Volodymyr Tsap
PDF
A Hands-on Introduction on Terraform Best Concepts and Best Practices
PDF
Terraforming the Kubernetes Land
Terraform at Scale - All Day DevOps 2017
Terraform at Scale
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
Administering and Monitoring SolrCloud Clusters
Terraform 0.9 + good practices
"Continuously delivering infrastructure using Terraform and Packer" training ...
Introductory Overview to Managing AWS with Terraform
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
Terraform in deployment pipeline
Refactoring terraform
An intro to Docker, Terraform, and Amazon ECS
Everything as Code with Terraform
Terraform Modules and Continuous Deployment
Hadoop on ec2
Terraform modules restructured
Building Distributed System with Celery on Docker Swarm
Dive into DevOps | March, Building with Terraform, Volodymyr Tsap
A Hands-on Introduction on Terraform Best Concepts and Best Practices
Terraforming the Kubernetes Land
Ad

Similar to Terraform day03 (20)

PPTX
Terraform day 3
PPTX
Configuration Management and Provisioning Are Different
PPTX
Final terraform
PDF
Workshop Infrastructure as Code - Suestra
PDF
Managing Infrastructure as Code
PDF
Automating the Cloud with Terraform, and Ansible
PDF
Terraform for GCP resources deployment demo
PPTX
RIMA-Infrastructure as a code with Terraform.pptx
PDF
Ansible-for-openstack
PDF
AWSをテラフォーミングする会(Terraformハンズオン)
PDF
Building infrastructure as code using Terraform - DevOps Krakow
PPTX
Debasihish da final.ppt
PPTX
Terraform day1
PDF
APIsecure 2023 - How to abuse Terraform to elevate access, Mike McCabe
PDF
Infrastructure As Code With Terraform
PDF
Infrastructure as Code with Terraform
PPTX
Terraform day 1
PPTX
Terraform infraestructura como código
PDF
Using Ansible for Deploying to Cloud Environments
PDF
AWS DevOps - Terraform, Docker, HashiCorp Vault
Terraform day 3
Configuration Management and Provisioning Are Different
Final terraform
Workshop Infrastructure as Code - Suestra
Managing Infrastructure as Code
Automating the Cloud with Terraform, and Ansible
Terraform for GCP resources deployment demo
RIMA-Infrastructure as a code with Terraform.pptx
Ansible-for-openstack
AWSをテラフォーミングする会(Terraformハンズオン)
Building infrastructure as code using Terraform - DevOps Krakow
Debasihish da final.ppt
Terraform day1
APIsecure 2023 - How to abuse Terraform to elevate access, Mike McCabe
Infrastructure As Code With Terraform
Infrastructure as Code with Terraform
Terraform day 1
Terraform infraestructura como código
Using Ansible for Deploying to Cloud Environments
AWS DevOps - Terraform, Docker, HashiCorp Vault
Ad

More from Gourav Varma (20)

PPTX
Jenkins introduction
PPTX
Docker introduction (1)
PPTX
Aws day 4
PPTX
Aws day 3
PPTX
Aws day 2
PPTX
Ansible day 4
PPTX
Ansible day 3
PPTX
Adnible day 2.ppt
PPTX
Ansible day 1.ppt
PPTX
Version control git day03(amarnath dada)
PPTX
Version control git day02
PPTX
Version control git day01
PPTX
Dev ops
PPTX
Shell programming 2
PPTX
Introduction to linux
PPTX
Version control git day03
PPTX
Version control git day02
PPTX
Version control git day01
PPT
Docker swarm
PPTX
Docker advance topic (2)
Jenkins introduction
Docker introduction (1)
Aws day 4
Aws day 3
Aws day 2
Ansible day 4
Ansible day 3
Adnible day 2.ppt
Ansible day 1.ppt
Version control git day03(amarnath dada)
Version control git day02
Version control git day01
Dev ops
Shell programming 2
Introduction to linux
Version control git day03
Version control git day02
Version control git day01
Docker swarm
Docker advance topic (2)

Recently uploaded (20)

PPTX
IOP Unit 1.pptx for btech 1st year students
PDF
Artificial Intelligence_ Basics .Artificial Intelligence_ Basics .
PPTX
Solar energy pdf of gitam songa hemant k
PDF
Engineering Solutions for Ethical Dilemmas in Healthcare (www.kiu.ac.ug)
PDF
Performance, energy consumption and costs: a comparative analysis of automati...
PDF
IAE-V2500 Engine for Airbus Family 319/320
PDF
IAE-V2500 Engine Airbus Family A319/320
DOCX
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
PPTX
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
PDF
Module 1 part 1.pdf engineering notes s7
PPTX
Design ,Art Across Digital Realities and eXtended Reality
PDF
Software defined netwoks is useful to learn NFV and virtual Lans
PDF
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
PPTX
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
PPTX
Research Writing, Mechanical Engineering
PDF
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
PDF
Using Technology to Foster Innovative Teaching Practices (www.kiu.ac.ug)
PDF
V2500 Owner and Operatore Guide for Airbus
PDF
electrical machines course file-anna university
PPTX
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
IOP Unit 1.pptx for btech 1st year students
Artificial Intelligence_ Basics .Artificial Intelligence_ Basics .
Solar energy pdf of gitam songa hemant k
Engineering Solutions for Ethical Dilemmas in Healthcare (www.kiu.ac.ug)
Performance, energy consumption and costs: a comparative analysis of automati...
IAE-V2500 Engine for Airbus Family 319/320
IAE-V2500 Engine Airbus Family A319/320
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
Module 1 part 1.pdf engineering notes s7
Design ,Art Across Digital Realities and eXtended Reality
Software defined netwoks is useful to learn NFV and virtual Lans
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
Research Writing, Mechanical Engineering
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
Using Technology to Foster Innovative Teaching Practices (www.kiu.ac.ug)
V2500 Owner and Operatore Guide for Airbus
electrical machines course file-anna university
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj

Terraform day03

  • 2. resource "aws_instance" "myec2" { ami = "ami-082b5a644766e0e6f" instance_type = "t2.micro" key_name = "kplabs-terraform" provisioner "remote-exec" { inline = [ "sudo amazon-linux-extras install -y nginx1.12", "sudo systemctl start nginx" ] connection { type = "ssh" user = "ec2-user" private_key = file("./kplabs-terraform.pem") host = self.public_ip } } } Remote Exec Provisioners
  • 4. • Steps: 1. Install Ansible on the system. 2. Write a playbook to install and configure the applications. 3. Copy and paste the pem file which is tagged to the instance. 4. Write your tf code to build and provision the instance . Inside the tf code call ansible playbook to run it like below.
  • 12. terrafrom workspace show terraform workspace list terraform workspace select dev terraform workspace new prod
  • 13. • Example: Project File ( ec2_web.tf ) provider "aws" { region = "us-west-1" access_key = "YOUR-ACCESS-KEY-HERE" secret_key = "YOUR-SECRET-KEY-HERE" } module "myec2" { source = "../../modules/ec2" }
  • 14. Modules File ( mod_ec2.tf ) resource "aws_instance" "myweb" { ami = "ami-bf5540df" instance_type = "${lookup(var.instance_type, terraform.workspace)}" security_groups = ["default"] tags { Name = "web-server" } } /* default - t2.nano dev - t2.micro prd - m4.large */
  • 15. Modules File ( variables.tf ) variable "instance_type" { type = "map" default = { default = "t2.nano" dev = "t2.micro" prd = "m4.large" } }
  • 21. Backend: Steps: • Create s3 bucket in AWS. • Define terraform code for setting remote backend.
  • 23. THANK YOU •Q & A Session