chrisluiz16

EIP condition

May 9th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.04 KB | None | 0 0
  1. variable "eip" {
  2.   type    = bool
  3.   default = false
  4. }
  5.  
  6. resource "aws_eip" "ip" {
  7.   count    = var.eip == true ? 1 : 0
  8.   instance = aws_instance.frontend.id
  9.   vpc      = true
  10. }
  11.  
  12.  
  13. resource "aws_route53_record" "eip_enable" {
  14.   count      = var.eip == true ? 1 : 0
  15.   zone_id    = "Z08029923B8M0XI7YJSP2"
  16.   name       = "blog"
  17.   type       = "A"
  18.   ttl        = 5
  19.   records    = [aws_eip.ip[0].public_ip]
  20.   depends_on = [aws_eip.ip[0]]
  21. }
  22.  
  23. resource "aws_route53_record" "eip_disable" {
  24.   count      = var.eip == false ? 1 : 0
  25.   zone_id    = "Z08029923B8M0XI7YJSP2"
  26.   name       = "blog"
  27.   type       = "A"
  28.   ttl        = 5
  29.   records    = [aws_instance.frontend.public_ip]
  30.   depends_on = [aws_instance.frontend]
  31. }
  32.  
  33.  
  34. resource "aws_instance" "frontend" {
  35.  
  36.   ami                    = "ami-0c768662cc797cd75"
  37.   instance_type          = "t2.micro"
  38.   key_name               = "mumbai-new"
  39.   vpc_security_group_ids = ["sg-09a5a43f8400c81c4"]
  40.   user_data              = file("userdata.sh")
  41.   tags = {
  42.     "Name" = "webserver",
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment