main.tf 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #-------------------------------
  2. # Create Nuxeo Ubuntu Instance
  3. #-------------------------------
  4. # Create a new EC2 instance
  5. variable "stack_name" {
  6. type = "string"
  7. description = "Name of the Stack/Env that this instance will used for"
  8. }
  9. variable "ubuntu_releases" {
  10. default = {
  11. trusty = "trusty-14.04"
  12. xenial = "xenial-16.04"
  13. yakkety = "yakkety-16.10"
  14. }
  15. }
  16. variable "os_release" {
  17. type = "string"
  18. description = "Ubuntu Release"
  19. default = "xenial"
  20. }
  21. variable "instance_type" {
  22. type = "string"
  23. description = "EC2 Instance Type"
  24. default = "t2.micro"
  25. }
  26. variable "instance_name" {
  27. type = "string"
  28. description = "Name to be give to this instance"
  29. }
  30. # Lookup on Amazon for the right AMI for Ubuntu on any region
  31. data "aws_ami" "ubuntu" {
  32. most_recent = true
  33. filter {
  34. name = "name"
  35. values = ["ubuntu/images/hvm-ssd/ubuntu-${lookup(var.ubuntu_releases, var.os_release)}-amd64-server-*"]
  36. }
  37. filter {
  38. name = "virtualization-type"
  39. values = ["hvm"]
  40. }
  41. owners = ["099720109477"] # Canonical
  42. }
  43. variable "subnet_id" {
  44. type = "string"
  45. }
  46. variable "public_key_path" {
  47. type = "string"
  48. description = "Local Path to the Pub Key to put on server"
  49. }
  50. #---------------------
  51. # Deployer SSH keys
  52. #--------------------
  53. resource "aws_key_pair" "deployer" {
  54. key_name = "deployer-key"
  55. public_key = "${file(var.public_key_path)}"
  56. }
  57. #---------------------
  58. # EC2 Instance
  59. #--------------------
  60. resource "aws_instance" "ec2" {
  61. ami = "${data.aws_ami.ubuntu.id}"
  62. instance_type = "${var.instance_type}"
  63. key_name = "${aws_key_pair.deployer.id}"
  64. subnet_id = "${var.subnet_id}"
  65. tags {
  66. Name = "${var.instance_name}"
  67. billing-category = "customers"
  68. billing-subcategory = "${var.stack_name}"
  69. role= "nuxeo.instance"
  70. managed_by="terraform"
  71. }
  72. }