main.tf 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. aws_region = var.aws_region
  29. }
  30. }
  31. # Render a multi-part cloud-init config making use of the part
  32. # above, and other source files
  33. data "template_cloudinit_config" "cloud-init" {
  34. gzip = true
  35. base64_encode = true
  36. # Main cloud-config configuration file.
  37. part {
  38. filename = "init.cfg"
  39. content_type = "text/cloud-config"
  40. content = data.template_file.cloud-init.rendered
  41. }
  42. # Additional parts as needed
  43. #part {
  44. # content_type = "text/x-shellscript"
  45. # content = "ffbaz"
  46. #}
  47. }