Terraform
Terraform
++++++++++++++++++++++++++++++++++++++++++++
# To Use User Data in Terraform Script
user_data = base64encode(file("userdata.sh"))
++++++++++++++++++++++++++++++++++++++++
Modules:
provider "aws" {
region = "us-east-1"
}
module "ec2_instance" {
source = "./modules/ec2_instance"
ami_value = "ami-053b0d53c279acc90" # replace this
instance_type_value = "t2.micro"
subnet_id_value = "subnet-019ea91ed9b5252e7". # replace this
}
+++++++++++++++++++++++++++++++++++
https://www.youtube.com/watch?v=-4IMy5ihiiU&list=PLdpzxOOAlwvI0O4PeKVV1-
yJoX2AqIWuf&index=9&ab_channel=Abhishek.Veeramalla
Terraform Import
1. export the configuration --> Create the state file of the instance->
1 provider "aws" {
2 region = "us-east-1"
3 }
4
5 import {
6 id="i-0573763ef5312afd6"
7
8 to= aws_instance.example
9 }
2. Paste the output, by removing import command and use the output of the
generated_resources.tf to make a terraform main file. This will create the state
file.
36. Give the terraform configuration for creating a single EC2 instance on AWS.
This is the Terraform configuration for creating a single EC2 instance on AWS:
provider “aws” {
region = “”}
resource “aws_instance”
“example” {
ami = ""
instance_type = ""
tags {
Name = "example"}
Configuration Loader :
State Manager:
provider "aws" {
region = "us-east-1"
profile = "terraform-user"
}