Advertisement
Guest User

Untitled

a guest
Mar 8th, 2017
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. provider "aws" {
  2. region = "${var.aws_region}"
  3. }
  4.  
  5. resource "aws_instance" "ec2_instance" {
  6. count = "${var.block_device["type"] == "none" ? var.number_of_instances : 0}"
  7.  
  8. ami = "${var.ami_id}"
  9. subnet_id = "${var.subnet_id}"
  10. instance_type = "${var.instance_type}"
  11. availability_zone = "${var.availability_zone}"
  12. key_name = "${var.key_name}"
  13. associate_public_ip_address = "${var.public_ip}"
  14. security_groups = ["${var.security_group_ids}"]
  15.  
  16. tags = "${merge(map(
  17. "Name", format("%s-%d.%s.%s", var.role, count.index, var.vpc, var.env),
  18. "created_by", "terraform",
  19. "Orchestration", var.orchestration,
  20. "Role", var.role,
  21. "Index", count.index,
  22. "Env", var.env,
  23. "VPC", var.vpc), var.tags)}"
  24. }
  25.  
  26. resource "aws_instance" "ec2_instance_ebs" {
  27. count = "${var.block_device["type"] == "ebs" ? var.number_of_instances : 0}"
  28.  
  29. ami = "${var.ami_id}"
  30. subnet_id = "${var.subnet_id}"
  31. instance_type = "${var.instance_type}"
  32. availability_zone = "${var.availability_zone}"
  33. key_name = "${var.key_name}"
  34. associate_public_ip_address = "${var.public_ip}"
  35. security_groups = ["${var.security_group_ids}"]
  36.  
  37. ebs_block_device {
  38. device_name = "${lookup(var.block_device, "device_name", "/dev/xda")}"
  39. volume_type = "${lookup(var.block_device, "volume_type", "gp2")}"
  40. volume_size = "${lookup(var.block_device, "volume_size", 25)}"
  41. delete_on_termination = "${lookup(var.block_device, "delete_on_termination", true)}"
  42. }
  43.  
  44. tags = "${merge(map(
  45. "Name", format("%s-%d.%s.%s", var.role, count.index, var.vpc, var.env),
  46. "created_by", "terraform",
  47. "Orchestration", var.orchestration,
  48. "Role", var.role,
  49. "Index", count.index,
  50. "Env", var.env,
  51. "VPC", var.vpc), var.tags)}"
  52. }
  53.  
  54. resource "aws_instance" "ec2_instance_ephemeral" {
  55. count = "${var.block_device["type"] == "ephemeral" ? var.number_of_instances : 0}"
  56.  
  57. ami = "${var.ami_id}"
  58. subnet_id = "${var.subnet_id}"
  59. instance_type = "${var.instance_type}"
  60. availability_zone = "${var.availability_zone}"
  61. key_name = "${var.key_name}"
  62. associate_public_ip_address = "${var.public_ip}"
  63. security_groups = ["${var.security_group_ids}"]
  64.  
  65. ephemeral_block_device {
  66. device_name = "${lookup(var.block_device, "device_name", "/dev/xda")}"
  67. virtual_name = "${lookup(var.block_device, "virtual_name", "ephemeral0")}"
  68. }
  69.  
  70. tags = "${merge(map(
  71. "Name", format("%s-%d.%s.%s", var.role, count.index, var.vpc, var.env),
  72. "created_by", "terraform",
  73. "Orchestration", var.orchestration,
  74. "Role", var.role,
  75. "Index", count.index,
  76. "Env", var.env,
  77. "VPC", var.vpc), var.tags)}"
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement