Advertisement
PandaAcademy

ec2.tf

Jul 27th, 2022
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. data "aws_ami" "latest_ubuntu" {
  2. owners = ["099720109477"]
  3. most_recent = true
  4.  
  5. filter {
  6. name = "name"
  7. values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
  8. }
  9. }
  10.  
  11. resource "aws_instance" "panda" {
  12. depends_on = [null_resource.download_ssh_key]
  13. count = length(var.availability_zones)
  14. ami = data.aws_ami.latest_ubuntu.image_id
  15. instance_type = "t2.micro"
  16. availability_zone = var.availability_zones[count.index]
  17. key_name = var.aws_key_name
  18. vpc_security_group_ids = [aws_security_group.sg_pub.id]
  19. subnet_id = aws_default_subnet.default_az[count.index].id
  20. }
  21.  
  22. resource "aws_security_group" "sg_pub" {
  23. ingress {
  24. from_port = 5000
  25. to_port = 5001
  26. protocol = "tcp"
  27. cidr_blocks = ["0.0.0.0/0"]
  28. }
  29.  
  30. ingress {
  31. from_port = 22
  32. to_port = 22
  33. protocol = "tcp"
  34. cidr_blocks = ["0.0.0.0/0"]
  35. }
  36.  
  37. egress {
  38. from_port = 0
  39. to_port = 65535
  40. protocol = "tcp"
  41. cidr_blocks = ["0.0.0.0/0"]
  42. }
  43. }
  44.  
  45. # output
  46.  
  47. output "alb_dns_name" {
  48. value = aws_lb.alb.dns_name
  49. }
  50.  
  51. output "ami_id" {
  52. value = data.aws_ami.latest_ubuntu.image_id
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement