main.tf 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. module "test_instance" {
  2. source = "terraform-aws-modules/ec2-instance/aws"
  3. version = "~> 2.0"
  4. name = "test_instance"
  5. instance_count = var.create_test_instance ? 1 : 0
  6. disable_api_termination = false # the test instance can always be destroyed
  7. ami = local.ami_map[var.test_instance_ami]
  8. instance_type = "t3a.micro"
  9. key_name = var.test_instance_key_name
  10. vpc_security_group_ids = var.security_group_ids
  11. subnet_id = var.subnet_id
  12. tags = merge(var.standard_tags, var.tags)
  13. ebs_optimized = true
  14. monitoring = false # Do we use this?
  15. user_data_base64 = "${data.template_cloudinit_config.cloud-init.rendered}"
  16. }
  17. data "template_file" "cloud-init" {
  18. # Should these be in a common directory? I suspect they'd be reusable
  19. template = "${file("${path.module}/cloud-init/cloud-init.tpl")}"
  20. vars = {
  21. hostname = "test_instance"
  22. fqdn = "test_instance.${var.dns_info["private"]["zone"]}"
  23. environment = var.environment
  24. saltmaster = "salt-master.${var.dns_info["private"]["zone"]}"
  25. aws_partition = var.aws_partition
  26. aws_partition_alias = var.aws_partition_alias
  27. }
  28. }
  29. # Render a multi-part cloud-init config making use of the part
  30. # above, and other source files
  31. data "template_cloudinit_config" "cloud-init" {
  32. gzip = true
  33. base64_encode = true
  34. # Main cloud-config configuration file.
  35. part {
  36. filename = "init.cfg"
  37. content_type = "text/cloud-config"
  38. content = "${data.template_file.cloud-init.rendered}"
  39. }
  40. # Additional parts as needed
  41. #part {
  42. # content_type = "text/x-shellscript"
  43. # content = "ffbaz"
  44. #}
  45. }