This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#combined use of remote and local execution | |
resource "null_resource" "nl1" { | |
depends_on = [ aws_volume_attachment.ebs_att,aws_s3_bucket.b,aws_cloudfront_distribution.s3_distribution ] | |
#sending local data to remote instance using scp | |
provisioner "local-exec" { | |
command = "chmod 400 /root/HybridCloud/Terraform/MyKeyPair.pem && scp -o StrictHostKeyChecking=no -r -i /root/HybridCloud/Terraform/MyKeyPair.pem /root/HybridCloud/Terraform/php ec2-user@${aws_instance.webos.public_dns}:/home/ec2-user" | |
} | |
connection { | |
type = "ssh" | |
user = "ec2-user" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#setting up cloudfron env | |
resource "aws_cloudfront_origin_access_identity" "origin_access_identity" { | |
comment = "myterra-access-generated" | |
} | |
locals { | |
s3_origin_id = "myS3Origin" | |
} | |
resource "aws_cloudfront_distribution" "s3_distribution" { | |
depends_on = [aws_s3_bucket.b] | |
origin { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#variables and data | |
data "local_file" "pathfi" { | |
filename = "/root/HybridCloud/Terraform/img/path.txt" | |
} | |
///////////////////////////////////////////////////// | |
#buckets | |
resource "aws_s3_bucket" "b" { | |
bucket = "aws-terraform-bucket-rahul3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#creation of ebs volume | |
resource "aws_ebs_volume" "myvol" { | |
depends_on =[aws_instance.webos] | |
availability_zone = aws_instance.webos.availability_zone | |
size = 1 | |
tags = { | |
Name = "myvolume" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#creating instance | |
#instance ami id | |
variable "ami_id" { | |
#IMAGE NAME = Amazon Linux 2 AMI (HVM), SSD Volume Type | |
default = "ami-0447a12f28fddb066" | |
} | |
#creating key pair and deleting when destroy command executed | |
resource "null_resource" "exec" { | |
provisioner "local-exec" { | |
command = "aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > /root/HybridCloud/Terraform/MyKeyPair.pem --profile rbterra" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#login to console | |
provider "aws" { | |
region = "ap-south-1" | |
profile= "rbterra" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#creation of security group | |
resource "aws_default_vpc" "main" { | |
tags = { | |
Name = "Default VPC" | |
} | |
} | |
resource "aws_security_group" "allow_tls" { | |
name = "allow_tls" | |
description = "Allow TLS inbound traffic" | |
vpc_id = aws_default_vpc.main.id |
NewerOlder