X EC2 (or 1 ASG X:X); X external volumes; X network interfaces; KMS key for volumes; Key pair
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.9KB

  1. ####
  2. # Defaults
  3. ####
  4. locals {
  5. should_fetch_default_subnet = local.use_default_subnets
  6. should_fetch_default_security_group = var.vpc_security_group_ids == null
  7. should_fetch_default_vpc = local.should_fetch_default_subnet || local.should_fetch_default_security_group
  8. should_fetch_default_ami = var.ami == null
  9. }
  10. data "aws_availability_zones" "default" {
  11. count = local.should_fetch_default_subnet ? 1 : 0
  12. state = "available"
  13. }
  14. data "aws_vpc" "default" {
  15. count = local.should_fetch_default_vpc ? 1 : 0
  16. default = true
  17. }
  18. data "aws_subnet_ids" "default" {
  19. count = local.should_fetch_default_subnet ? length(data.aws_availability_zones.default.*.names[0]) : 0
  20. vpc_id = data.aws_vpc.default.*.id[0]
  21. filter {
  22. name = "availability-zone"
  23. values = [element(data.aws_availability_zones.default.*.names[0], count.index)]
  24. }
  25. }
  26. data "aws_security_group" "default" {
  27. count = local.should_fetch_default_security_group ? 1 : 0
  28. vpc_id = data.aws_vpc.default.*.id[0]
  29. name = "default"
  30. }
  31. ####
  32. # Subnets
  33. ####
  34. data "aws_subnet" "current" {
  35. count = length(local.subnet_ids)
  36. id = local.subnet_ids[count.index]
  37. }
  38. ####
  39. # EBS
  40. ####
  41. data "null_data_source" "ebs_block_device" {
  42. count = var.extra_volume_count
  43. inputs = {
  44. device_name = element(var.extra_volume_device_names, count.index)
  45. type = element(var.extra_volume_types, count.index)
  46. size = element(var.extra_volume_sizes, count.index)
  47. }
  48. }
  49. ####
  50. # IAM Instance Profile
  51. ####
  52. data "aws_iam_policy_document" "sts_instance" {
  53. count = local.should_create_instance_profile ? 1 : 0
  54. statement {
  55. actions = ["sts:AssumeRole"]
  56. principals {
  57. type = "Service"
  58. identifiers = [
  59. "ec2.amazonaws.com"
  60. ]
  61. }
  62. }
  63. }
  64. ####
  65. # SSM Parameter
  66. ####
  67. data "aws_ssm_parameter" "default_ami" {
  68. count = local.should_fetch_default_ami ? 1 : 0
  69. name = "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
  70. }