main.tf 1.7 KB

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