Code Monkey home page Code Monkey logo

task-1's Introduction

provider "aws" { profile = "tfgopal" region = "ap-south-1" }

resource "tls_private_key" "my-key"{ algorithm = "RSA" rsa_bits = "4096" } resource "aws_key_pair" "generate_key" { key_name = "mytfkey1" public_key = "${tls_private_key.my-key.public_key_openssh}"

depends_on = [ tls_private_key.my-key ] }

resource "local_file" "key-file" { content = "${tls_private_key.my-key.private_key_pem}" filename = "mytfkey1.pem"

depends_on = [ tls_private_key.my-key ] }

resource "aws_security_group" "sec_group" { name = "sec_group" description = "allow ssh and HTTPD"

ingress { description = "SSH Port" from_port =22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress {

       description = "HTTPD"
       from_port = 80
       to_port = 80
       protocol = "tcp"
       cidr_blocks = ["0.0.0.0/0"]
      } 

egress {

       from_port = 0
       to_port = 0
       protocol = "-1"
       cidr_blocks = ["0.0.0.0/0"]
   } 

tags = { Name = "sec_group" } }

resource "aws_instance" "web" { ami = "ami-0447a12f28fddb066" instance_type = "t2.micro" key_name = aws_key_pair.generate_key.key_name security_groups = [ "sec_group"]

provisioner "remote-exec" { connection { type = "ssh" user = "ec2-user" private_key = "${tls_private_key.my-key.private_key_pem}" host = "${aws_instance.web.public_ip}" }

inline = [ "sudo yum install httpd git -y", "sudo systemctl restart httpd" , "sudo systemctl enable httpd" , ] } tags = { Name = "Gopal_OS" } }

resource "aws_ebs_volume" "ebs11" { availability_zone = aws_instance.web.availability_zone size = 1 tags = { Name = "vol_web" } }

resource "aws_volume_attachment" "ebs_attach"{ device_name = "/dev/sdh" volume_id = aws_ebs_volume.ebs11.id instance_id = aws_instance.web.id force_detach = true }

output "myip" { value = aws_instance.web.public_ip

}

resource "null_resource" "nullip" { provisioner "local-exec" { command = "echo ${aws_instance.web.public_ip} > publicip.txt " } }

resource "null_resource" "nullmount" { depends_on = [ aws_volume_attachment.ebs_attach, ]

connection { type = "ssh" user = "ec2-user" private_key = "${tls_private_key.my-key.private_key_pem}" host = "${aws_instance.web.public_ip}" }

provisioner "remote-exec" { inline = [ "sudo mkfs.ext4 /dev/xvdh" , "sudo mount /dev/xvdh /var/www/html", "sudo rm -rf /var/www/html/*", "sudo git clone https://github.com/Gopal-786/Gopal-Jaiswal.git" ] } }

/* resource "aws_s3_bucket" "terra-bucket1" { bucket = "Gopalsbucket" acl = "public-read"

versioning { enabled = true }

tags = { Name = "my-terra-bucket1" Environment = "Dev" } }

resource "aws_cloudfront_distribution" "terra-cloudfront1" origin { domain_name = "Gopalsbucket.s3.amazonaws.com" origin_id = "S3-Gopalsbucket"

      custom_origin_config {
       http_port = 80
       origin_protocol_policy = "match-viewer"
       origin_ssl_protocols = ["TLSv1", "TLSv1.1", "TLSv1.2"]
     }

}

enabled = true

default_cache_behavior { allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "PUT"] cached-methods = ["GET" , "HEAD" ] target_origin-id = "S3-Gopalsbucket"

forwarded_values { query_string = false

        cookies {
              forward = "none"
         }

}

viewer_protocol_policy = "allow-all" min_ttl = 0 default_ttl = 3600 max_ttl = 86400

}

restrictions { geo_restriction { restriction_type = "none" } }

viewer_certificate { cloudfront_default_certification = true }

resource "null_resource" "nullremote" { depends_on = [ null_resource.nullmount ]

} */

task-1's People

Contributors

gopal-786 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.