Skip to content

Instantly share code, notes, and snippets.

View iamtheindian's full-sized avatar

RAHUL BAIRWA iamtheindian

  • JODHPUR ,RAJASTHAN
View GitHub Profile
#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
#login to console
provider "aws" {
region = "ap-south-1"
profile= "rbterra"
}
#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"
#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"
}
}
#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"
#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 {
#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"
<html>
<head>
<title> MY FIRST WEBPAGE </title>
</head>
<style>
body {
background-color: #E6E6FA;
}
</style>
<body>
#generate private key
resource "tls_private_key" "tkey" {
algorithm = "RSA"
}
#assigne public openssh to the aws key pair
resource "aws_key_pair" "deployer" {
key_name = "deployer-key"
public_key = tls_private_key.tkey.public_key_openssh
depends_on=[tls_private_key.tkey]
}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: http-volume
labels:
type: local
spec:
storageClassName: manual
capacity: