Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

provider "aws" { region = "eu-central-1" shared_credentials_files = ["/Users/rahulwagh/.aws/credentials"] }

resource "aws_instance" "ec2_example" {

ami = "ami-0767046d1677be5a0"  
instance_type = "t2.micro" 
key_name= "aws_key"
vpc_security_group_ids = [aws_security_group.main.id]

provisioner "file" { source = "/home/rahul/Jhooq/keys/aws/test-file.txt" destination = "/home/ubuntu/test-file.txt" } connection { type = "ssh" host = self.public_ip user = "ubuntu" private_key = file("/home/rahul/Jhooq/keys/aws/aws_key") timeout = "4m" } }

resource "aws_security_group" "main" { egress = [ { cidr_blocks = [ "0.0.0.0/0", ] description = "" from_port = 0 ipv6_cidr_blocks = [] prefix_list_ids = [] protocol = "-1" security_groups = [] self = false to_port = 0 } ] ingress = [ { cidr_blocks = [ "0.0.0.0/0", ] description = "" from_port = 22 ipv6_cidr_blocks = [] prefix_list_ids = [] protocol = "tcp" security_groups = [] self = false to_port = 22 }, { cidr_blocks = [ "0.0.0.0/0", ] description = "" from_port = 443 ipv6_cidr_blocks = [] prefix_list_ids = [] protocol = "tcp" security_groups = [] self = false to_port = 443 } ]

}

resource "aws_key_pair" "deployer" { key_name = "aws_key" public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDbvRN/gvQBhFe+dE8p3Q865T/xTKgjqTjj56p1IIKbq8SDyOybE8ia0rMPcBLAKds+wjePIYpTtRxT9UsUbZJTgF+SGSG2dC6+ohCQpi6F3xM7ryL9fy3BNCT5aPrwbR862jcOIfv7R1xVfH8OS0WZa8DpVy5kTeutsuH5FMAmEgba4KhYLTzIdhM7UKJvNoUMRBaxAqIAThqH9Vt/iR1WpXgazoPw6dyPssa7ye6tUPRipmPTZukfpxcPlsqytXWlXm7R89xAY9OXkdPPVsrQA0XFQnY8aFb9XaZP8cm7EOVRdxMsA1DyWMVZOTjhBwCHfEIGoePAS3jFMqQjGWQd rahul@rahul-HP-ZBook-15-G2" }

---- dynamic block

provider "aws" { region = "eu-central-1" shared_credentials_files = ["/Users/rahulwagh/.aws/credentials"] }

locals { ingress_rules = [{ port = 443 description = "Ingress rules for port 443" }, { port = 80 description = "Ingree rules for port 80" }] }

resource "aws_instance" "ec2_example" {

ami = "ami-0767046d1677be5a0"  
instance_type = "t2.micro" 

}

resource "aws_security_group" "main" { egress = [ { cidr_blocks = [ "0.0.0.0/0", ] description = "" from_port = 0 ipv6_cidr_blocks = [] prefix_list_ids = [] protocol = "-1" security_groups = [] self = false to_port = 0 } ]

dynamic "ingress" { for_each = local.ingress_rules

  content {
     description = ingress.value.description
     from_port   = ingress.value.port
     to_port     = ingress.value.port
     protocol    = "tcp"
     cidr_blocks = ["0.0.0.0/0"]
  }

} }