main.tf 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. locals {
  2. owner = var.aws_partition == "aws-us-gov" ? "513442679011" : "099720109477"
  3. }
  4. data "aws_ami" "ubuntu" {
  5. most_recent = true
  6. owners = [ local.owner ]
  7. filter {
  8. name = "name"
  9. values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
  10. }
  11. #filter {
  12. # name = "image-id"
  13. # values = [ "ami-0a4050943619c0460" ]
  14. #}
  15. filter {
  16. name = "root-device-type"
  17. values = ["ebs"]
  18. }
  19. filter {
  20. name = "virtualization-type"
  21. values = ["hvm"]
  22. }
  23. }
  24. module "test_instance" {
  25. source = "terraform-aws-modules/ec2-instance/aws"
  26. version = "~> 2.0"
  27. name = "test_instance"
  28. instance_count = var.create_test_instance ? 1 : 0
  29. disable_api_termination = false # the test instance can always be destroyed
  30. ami = data.aws_ami.ubuntu.image_id
  31. instance_type = "t3a.micro"
  32. key_name = var.test_instance_key_name
  33. vpc_security_group_ids = var.security_group_ids
  34. subnet_id = var.subnet_id
  35. tags = merge(var.standard_tags, var.tags)
  36. ebs_optimized = true
  37. monitoring = false # Do we use this?
  38. user_data_base64 = "${data.template_cloudinit_config.cloud-init.rendered}"
  39. }
  40. data "template_file" "cloud-init" {
  41. # Should these be in a common directory? I suspect they'd be reusable
  42. template = "${file("${path.module}/cloud-init/cloud-init.tpl")}"
  43. vars = {
  44. hostname = "test_instance"
  45. fqdn = "test_instance.${var.dns_info["private"]["zone"]}"
  46. environment = var.environment
  47. }
  48. }
  49. # Render a multi-part cloud-init config making use of the part
  50. # above, and other source files
  51. data "template_cloudinit_config" "cloud-init" {
  52. gzip = true
  53. base64_encode = true
  54. # Main cloud-config configuration file.
  55. part {
  56. filename = "init.cfg"
  57. content_type = "text/cloud-config"
  58. content = "${data.template_file.cloud-init.rendered}"
  59. }
  60. # Additional parts as needed
  61. #part {
  62. # content_type = "text/x-shellscript"
  63. # content = "ffbaz"
  64. #}
  65. }