main.tf 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. variable "secgroup" {}
  51. variable "ami" {}
  52. #---------------------
  53. # Deployer SSH keys
  54. #--------------------
  55. resource "aws_key_pair" "deployer" {
  56. key_name = "${var.stack_name}-deploy-key"
  57. public_key = "${file(var.public_key_path)}"
  58. }
  59. #---------------------
  60. # EC2 Instance
  61. #--------------------
  62. resource "aws_instance" "ec2" {
  63. ami = "${data.aws_ami.ubuntu.id}"
  64. instance_type = "${var.instance_type}"
  65. key_name = "${aws_key_pair.deployer.id}"
  66. subnet_id = "${var.subnet_id}"
  67. vpc_security_group_ids=["${var.secgroup}"]
  68. tags {
  69. Name = "${var.instance_name}"
  70. billing-category = "customers"
  71. billing-subcategory = "${var.stack_name}"
  72. role= "nuxeo.instance"
  73. managed_by="terraform"
  74. }
  75. }