From 69daf3d65360df138e7676ab1a0ff4fbd2d24d6f Mon Sep 17 00:00:00 2001 From: johnypony3 Date: Mon, 30 Oct 2017 13:11:23 -0700 Subject: [PATCH 1/9] added spot instance work --- README.md | 7 ++++--- examples/basic/main.tf | 3 ++- main.tf | 14 +++++++++++++- outputs.tf | 35 +++++++++++++++++++++++++++++++++++ variables.tf | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e0b46241..e25df569 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Terraform module which creates EC2 instance(s) on AWS. These types of resources are supported: -* [EC2 instance](https://www.terraform.io/docs/providers/aws/r/instance.html) +* [EC2 instance](https://www.terraform.io/docs/providers/aws/r/instance.html) Usage ----- @@ -16,12 +16,13 @@ module "ec2_cluster" { name = "my-cluster" count = 5 - + ami = "ami-ebd02392" instance_type = "t2.micro" key_name = "user1" monitoring = true vpc_security_group_ids = ["sg-12345678"] + spot_price = "0.03" tags = { Terraform = "true" @@ -49,4 +50,4 @@ Module managed by [Anton Babenko](https://github.com/antonbabenko). License ------- -Apache 2 Licensed. See LICENSE for full details. \ No newline at end of file +Apache 2 Licensed. See LICENSE for full details. diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 31ef309a..12b7ddd2 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -45,7 +45,7 @@ module "security_group" { egress_rules = ["all-all"] } -module "ec2" { +module "ec2_spot" { source = "../../" name = "example" @@ -53,4 +53,5 @@ module "ec2" { instance_type = "t2.micro" vpc_security_group_ids = ["${module.security_group.this_security_group_id}"] associate_public_ip_address = true + spot_price = "0.03" } diff --git a/main.tf b/main.tf index cda3c35e..a0971648 100644 --- a/main.tf +++ b/main.tf @@ -1,7 +1,7 @@ ###### # EC2 instance ###### -resource "aws_instance" "this" { +resource "aws_spot_instance" "this" { count = "${var.count}" ami = "${var.ami}" @@ -31,6 +31,18 @@ resource "aws_instance" "this" { placement_group = "${var.placement_group}" tenancy = "${var.tenancy}" + spot_price = "${var.spot_price}" + wait_for_fulfillment = "${var.wait_for_fulfillment}" + spot_type = "${var.spot_type}" + instance_interruption_behaviour = "${var.instance_interruption_behaviour}" + launch_group = "${var.launch_group}" + block_duration_minutes = "${var.block_duration_minutes}" + + timeouts { + create = "${var.create_timeout}" + delete = "2${var.delete_timeout}h" + } + # Note: network_interface can't be specified together with associate_public_ip_address # network_interface = "${var.network_interface}" diff --git a/outputs.tf b/outputs.tf index 8a76b3bc..70d06c81 100644 --- a/outputs.tf +++ b/outputs.tf @@ -62,3 +62,38 @@ output "subnet_id" { description = "List of IDs of VPC subnets of instances" value = ["${aws_instance.this.*.}"] } + +output "spot_bid_status" { + description = "The current bid status of the Spot Instance Request." + value = ["${aws_instance.this.*.spot_bid_status}"] +} + +output "spot_request_state" { + description = "The current request state of the Spot Instance Request." + value = ["${aws_instance.this.*.spot_request_state}"] +} + +output "spot_instance_id" { + description = "The Instance ID (if any) that is currently fulfilling the Spot Instance request." + value = ["${aws_instance.this.*.spot_instance_id}"] +} + +output "public_dns" { + description = "The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC" + value = ["${aws_instance.this.*.public_dns}"] +} + +output "public_ip" { + description = "The public IP address assigned to the instance, if applicable." + value = ["${aws_instance.this.*.public_ip}"] +} + +output "private_dns" { + description = "The private DNS name assigned to the instance. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC" + value = ["${aws_instance.this.*.private_dns}"] +} + +output "private_ip" { + description = "The private IP address assigned to the instance" + value = ["${aws_instance.this.*.private_ip}"] +} diff --git a/variables.tf b/variables.tf index 90851a61..20069d94 100644 --- a/variables.tf +++ b/variables.tf @@ -129,3 +129,37 @@ variable "network_interface" { description = "Customize network interfaces to be attached at instance boot time" default = [] } + +variable "spot_price" { + type = "string" + description = "The maximum hourly price (bid) you are willing to pay for the instance, e.g. 0.10" +} + +variable "launch_group" { + type = "string" + description = "Group name to assign the instances to so they can be started/stopped in unison, e.g. purple-plutonium" + default = "defaulted" +} + +variable "instance_interruption_behaviour" { + type = "string" + description = "Whether a Spot instance stops or terminates when it is interrupted, can be stop or terminate" +} + +variable "block_duration_minutes" { + type = "string" + description = "(Optional) The required duration for the Spot instances, in minutes. This value must be a multiple of 60 (60, 120, 180, 240, 300, or 360)." +} + +variable "spot_type" { + type = "string" + description = "(Optional; Default: 'persistent') If set to 'one-time', after the instance is terminated, the spot request will be closed. Also, Terraform can't manage one-time spot requests, just launch them." +} + +variable "create_timeout" { + description = "(Defaults to 10 mins) Used when requesting the spot instance (only valid if wait_for_fulfillment = true)" +} + +variable "delete_timeout" { + description = "(Defaults to 10 mins) Used when terminating all instances launched via the given spot instance request" +} From 3e60379d12cc2e88188453bfa057809a63c22292 Mon Sep 17 00:00:00 2001 From: johnypony3 Date: Mon, 30 Oct 2017 13:43:02 -0700 Subject: [PATCH 2/9] updated a few optional values and misc copy --- README.md | 2 +- variables.tf | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e25df569..6f50687e 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ module "ec2_cluster" { Examples -------- -* [Basic EC2 instance](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/basic) +* [Basic EC2 instance](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/basic) Limitations ----------- diff --git a/variables.tf b/variables.tf index 20069d94..724b998b 100644 --- a/variables.tf +++ b/variables.tf @@ -154,12 +154,15 @@ variable "block_duration_minutes" { variable "spot_type" { type = "string" description = "(Optional; Default: 'persistent') If set to 'one-time', after the instance is terminated, the spot request will be closed. Also, Terraform can't manage one-time spot requests, just launch them." + default = "persistent" } variable "create_timeout" { description = "(Defaults to 10 mins) Used when requesting the spot instance (only valid if wait_for_fulfillment = true)" + default = "10" } variable "delete_timeout" { description = "(Defaults to 10 mins) Used when terminating all instances launched via the given spot instance request" + default = "10" } From f5f5dc6c2493f47a5e7de2861c27966325198c14 Mon Sep 17 00:00:00 2001 From: johnypony3 Date: Mon, 30 Oct 2017 13:50:59 -0700 Subject: [PATCH 3/9] added defaults to all but one variable --- variables.tf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 724b998b..ce45d3dd 100644 --- a/variables.tf +++ b/variables.tf @@ -138,17 +138,19 @@ variable "spot_price" { variable "launch_group" { type = "string" description = "Group name to assign the instances to so they can be started/stopped in unison, e.g. purple-plutonium" - default = "defaulted" + default = "default" } variable "instance_interruption_behaviour" { type = "string" description = "Whether a Spot instance stops or terminates when it is interrupted, can be stop or terminate" + default = "terminates" } variable "block_duration_minutes" { type = "string" description = "(Optional) The required duration for the Spot instances, in minutes. This value must be a multiple of 60 (60, 120, 180, 240, 300, or 360)." + default = "60" } variable "spot_type" { From ce1bb7f8b4e82fc059e2c74bad9c9c1029f3d740 Mon Sep 17 00:00:00 2001 From: johnypony3 Date: Mon, 30 Oct 2017 13:52:31 -0700 Subject: [PATCH 4/9] added defaults to all variables --- variables.tf | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/variables.tf b/variables.tf index ce45d3dd..20bb039b 100644 --- a/variables.tf +++ b/variables.tf @@ -133,6 +133,7 @@ variable "network_interface" { variable "spot_price" { type = "string" description = "The maximum hourly price (bid) you are willing to pay for the instance, e.g. 0.10" + default = "0.01" } variable "launch_group" { @@ -144,13 +145,13 @@ variable "launch_group" { variable "instance_interruption_behaviour" { type = "string" description = "Whether a Spot instance stops or terminates when it is interrupted, can be stop or terminate" - default = "terminates" + default = "terminate" } variable "block_duration_minutes" { type = "string" description = "(Optional) The required duration for the Spot instances, in minutes. This value must be a multiple of 60 (60, 120, 180, 240, 300, or 360)." - default = "60" + default = 60 } variable "spot_type" { @@ -161,10 +162,10 @@ variable "spot_type" { variable "create_timeout" { description = "(Defaults to 10 mins) Used when requesting the spot instance (only valid if wait_for_fulfillment = true)" - default = "10" + default = 10 } variable "delete_timeout" { description = "(Defaults to 10 mins) Used when terminating all instances launched via the given spot instance request" - default = "10" + default = 10 } From 2924b07a5ff8e486c04331d0767907e1c0f22dc8 Mon Sep 17 00:00:00 2001 From: johnypony3 Date: Mon, 30 Oct 2017 14:27:46 -0700 Subject: [PATCH 5/9] a few issues arose while testing --- main.tf | 6 ++--- outputs.tf | 76 ++++++---------------------------------------------- variables.tf | 13 ++++++--- 3 files changed, 20 insertions(+), 75 deletions(-) diff --git a/main.tf b/main.tf index a0971648..6ceb5edc 100644 --- a/main.tf +++ b/main.tf @@ -1,7 +1,7 @@ ###### -# EC2 instance +# EC2 spot instance ###### -resource "aws_spot_instance" "this" { +resource "aws_spot_instance_request" "this" { count = "${var.count}" ami = "${var.ami}" @@ -40,7 +40,7 @@ resource "aws_spot_instance" "this" { timeouts { create = "${var.create_timeout}" - delete = "2${var.delete_timeout}h" + delete = "${var.delete_timeout}" } # Note: network_interface can't be specified together with associate_public_ip_address diff --git a/outputs.tf b/outputs.tf index 70d06c81..bd955163 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,99 +1,39 @@ output "id" { description = "List of IDs of instances" - value = ["${aws_instance.this.*.id}"] -} - -output "availability_zone" { - description = "List of availability zones of instances" - value = ["${aws_instance.this.*.availability_zone}"] -} - -output "placement_group" { - description = "List of placement groups of instances" - value = ["${aws_instance.this.*.placement_group}"] -} - -output "key_name" { - description = "List of key names of instances" - value = ["${aws_instance.this.*.key_name}"] + value = ["${aws_spot_instance_request.this.*.id}"] } output "public_dns" { description = "List of public DNS names assigned to the instances. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC" - value = ["${aws_instance.this.*.public_dns}"] + value = ["${aws_spot_instance_request.this.*.public_dns}"] } output "public_ip" { description = "List of public IP addresses assigned to the instances, if applicable" - value = ["${aws_instance.this.*.public_ip}"] -} - -output "network_interface_id" { - description = "List of IDs of the network interface of instances" - value = ["${aws_instance.this.*.network_interface_id}"] -} - -output "primary_network_interface_id" { - description = "List of IDs of the primary network interface of instances" - value = ["${aws_instance.this.*.primary_network_interface_id}"] + value = ["${aws_spot_instance_request.this.*.public_ip}"] } output "private_dns" { description = "List of private DNS names assigned to the instances. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC" - value = ["${aws_instance.this.*.private_dns}"] + value = ["${aws_spot_instance_request.this.*.private_dns}"] } output "private_ip" { description = "List of private IP addresses assigned to the instances" - value = ["${aws_instance.this.*.private_ip}"] -} - -output "security_groups" { - description = "List of associated security groups of instances" - value = ["${aws_instance.this.*.security_groups}"] -} - -output "vpc_security_group_ids" { - description = "List of associated security groups of instances, if running in non-default VPC" - value = ["${aws_instance.this.*.vpc_security_group_ids}"] -} - -output "subnet_id" { - description = "List of IDs of VPC subnets of instances" - value = ["${aws_instance.this.*.}"] + value = ["${aws_spot_instance_request.this.*.private_ip}"] } output "spot_bid_status" { description = "The current bid status of the Spot Instance Request." - value = ["${aws_instance.this.*.spot_bid_status}"] + value = ["${aws_spot_instance_request.this.*.spot_bid_status}"] } output "spot_request_state" { description = "The current request state of the Spot Instance Request." - value = ["${aws_instance.this.*.spot_request_state}"] + value = ["${aws_spot_instance_request.this.*.spot_request_state}"] } output "spot_instance_id" { description = "The Instance ID (if any) that is currently fulfilling the Spot Instance request." - value = ["${aws_instance.this.*.spot_instance_id}"] -} - -output "public_dns" { - description = "The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC" - value = ["${aws_instance.this.*.public_dns}"] -} - -output "public_ip" { - description = "The public IP address assigned to the instance, if applicable." - value = ["${aws_instance.this.*.public_ip}"] -} - -output "private_dns" { - description = "The private DNS name assigned to the instance. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC" - value = ["${aws_instance.this.*.private_dns}"] -} - -output "private_ip" { - description = "The private IP address assigned to the instance" - value = ["${aws_instance.this.*.private_ip}"] + value = ["${aws_spot_instance_request.this.*.spot_instance_id}"] } diff --git a/variables.tf b/variables.tf index 20bb039b..8e51b2db 100644 --- a/variables.tf +++ b/variables.tf @@ -136,10 +136,15 @@ variable "spot_price" { default = "0.01" } +variable "wait_for_fulfillment" { + description = "(Optional; Default: false) If set, Terraform will wait for the Spot Request to be fulfilled, and will throw an error if the timeout of 10m is reached." + default = false +} + variable "launch_group" { type = "string" description = "Group name to assign the instances to so they can be started/stopped in unison, e.g. purple-plutonium" - default = "default" + default = "" } variable "instance_interruption_behaviour" { @@ -151,7 +156,7 @@ variable "instance_interruption_behaviour" { variable "block_duration_minutes" { type = "string" description = "(Optional) The required duration for the Spot instances, in minutes. This value must be a multiple of 60 (60, 120, 180, 240, 300, or 360)." - default = 60 + default = "0" } variable "spot_type" { @@ -162,10 +167,10 @@ variable "spot_type" { variable "create_timeout" { description = "(Defaults to 10 mins) Used when requesting the spot instance (only valid if wait_for_fulfillment = true)" - default = 10 + default = "10m" } variable "delete_timeout" { description = "(Defaults to 10 mins) Used when terminating all instances launched via the given spot instance request" - default = 10 + default = "10m" } From 2d34b26ae5451dc229391476b9d4d8af6f2ad1c2 Mon Sep 17 00:00:00 2001 From: johnypony3 Date: Mon, 30 Oct 2017 15:19:27 -0700 Subject: [PATCH 6/9] documentation cleanup --- README.md | 12 ++++----- examples/basic/main.tf | 3 +-- examples/spot/README.md | 21 +++++++++++++++ examples/spot/main.tf | 57 ++++++++++++++++++++++++++++++++++++++++ examples/spot/outputs.tf | 19 ++++++++++++++ 5 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 examples/spot/README.md create mode 100644 examples/spot/main.tf create mode 100644 examples/spot/outputs.tf diff --git a/README.md b/README.md index 6f50687e..474dc91e 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,18 @@ AWS EC2 Instance Terraform module ================================= -Terraform module which creates EC2 instance(s) on AWS. +Terraform module which creates EC2 Spot instance(s) request(s) on AWS. These types of resources are supported: -* [EC2 instance](https://www.terraform.io/docs/providers/aws/r/instance.html) +* [EC2 Spot Instance Request](https://www.terraform.io/docs/providers/aws/r/spot_instance_request.html) Usage ----- ```hcl -module "ec2_cluster" { - source = "terraform-aws-modules/ec2-instance/aws" +module "ec2_spot_cluster" { + source = "johnypony3/ec2-spot-instance/aws" name = "my-cluster" count = 5 @@ -34,7 +34,7 @@ module "ec2_cluster" { Examples -------- -* [Basic EC2 instance](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/basic) +* [Basic EC2 Spot instance](https://github.com/johnypony3/terraform-aws-ec2-spot-instance/tree/master/examples/spot) Limitations ----------- @@ -46,7 +46,7 @@ Authors ------- Module managed by [Anton Babenko](https://github.com/antonbabenko). - +Temporarily managed by [johnypony3](https://github.com/johnypony3) License ------- diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 12b7ddd2..31ef309a 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -45,7 +45,7 @@ module "security_group" { egress_rules = ["all-all"] } -module "ec2_spot" { +module "ec2" { source = "../../" name = "example" @@ -53,5 +53,4 @@ module "ec2_spot" { instance_type = "t2.micro" vpc_security_group_ids = ["${module.security_group.this_security_group_id}"] associate_public_ip_address = true - spot_price = "0.03" } diff --git a/examples/spot/README.md b/examples/spot/README.md new file mode 100644 index 00000000..1462b598 --- /dev/null +++ b/examples/spot/README.md @@ -0,0 +1,21 @@ +Basic EC2 spot instance request +================== + +Configuration in this directory creates single EC2 spot instance request with minimum set of arguments: AMI ID and instance type. + +Unspecified arguments for security group id and subnet are inherited from the default VPC. + +This example outputs instance id and public DNS name as a single value and as a list. + +Usage +===== + +To run this example you need to execute: + +```bash +$ terraform init +$ terraform plan +$ terraform apply +``` + +Note that this example may create resources which can cost money. Run `terraform destroy` when you don't need these resources. diff --git a/examples/spot/main.tf b/examples/spot/main.tf new file mode 100644 index 00000000..12b7ddd2 --- /dev/null +++ b/examples/spot/main.tf @@ -0,0 +1,57 @@ +provider "aws" { + region = "eu-west-1" +} + +################################################################## +# Data sources to get VPC, subnet, security group and AMI details +################################################################## +data "aws_vpc" "default" { + default = true +} + +data "aws_subnet_ids" "all" { + vpc_id = "${data.aws_vpc.default.id}" +} + +data "aws_ami" "amazon_linux" { + most_recent = true + + filter { + name = "name" + + values = [ + "amzn-ami-hvm-*-x86_64-gp2", + ] + } + + filter { + name = "owner-alias" + + values = [ + "amazon", + ] + } +} + +module "security_group" { + source = "terraform-aws-modules/security-group/aws" + + name = "example" + description = "Security group for example usage with EC2 instance" + vpc_id = "${data.aws_vpc.default.id}" + + ingress_cidr_blocks = ["0.0.0.0/0"] + ingress_rules = ["http-80-tcp", "all-icmp"] + egress_rules = ["all-all"] +} + +module "ec2_spot" { + source = "../../" + + name = "example" + ami = "${data.aws_ami.amazon_linux.id}" + instance_type = "t2.micro" + vpc_security_group_ids = ["${module.security_group.this_security_group_id}"] + associate_public_ip_address = true + spot_price = "0.03" +} diff --git a/examples/spot/outputs.tf b/examples/spot/outputs.tf new file mode 100644 index 00000000..e87e2d8b --- /dev/null +++ b/examples/spot/outputs.tf @@ -0,0 +1,19 @@ +output "id" { + description = "List of IDs of instances" + value = ["${module.ec2.id}"] +} + +output "public_dns" { + description = "List of public DNS names assigned to the instances" + value = ["${module.ec2.public_dns}"] +} + +output "instance_id" { + description = "EC2 instance ID" + value = "${module.ec2.id[0]}" +} + +output "instance_public_dns" { + description = "Public DNS name assigned to the EC2 instance" + value = "${module.ec2.public_dns[0]}" +} From a5407fcc60c3bdbe2113196c07cba712ddb56c0d Mon Sep 17 00:00:00 2001 From: johnypony3 Date: Mon, 30 Oct 2017 15:21:01 -0700 Subject: [PATCH 7/9] made spot_price required --- variables.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/variables.tf b/variables.tf index 8e51b2db..0632eb56 100644 --- a/variables.tf +++ b/variables.tf @@ -133,7 +133,6 @@ variable "network_interface" { variable "spot_price" { type = "string" description = "The maximum hourly price (bid) you are willing to pay for the instance, e.g. 0.10" - default = "0.01" } variable "wait_for_fulfillment" { From 283eccb7481a6ac3f058bd427de13b31abda415a Mon Sep 17 00:00:00 2001 From: johnypony3 Date: Wed, 1 Nov 2017 04:49:59 -0700 Subject: [PATCH 8/9] cleanup, better outputs --- README.md | 8 +++--- examples/basic/README.md | 4 +-- examples/basic/main.tf | 5 ++-- examples/basic/outputs.tf | 38 +++++++++++++++++++------- examples/spot/README.md | 21 --------------- examples/spot/main.tf | 57 --------------------------------------- examples/spot/outputs.tf | 19 ------------- 7 files changed, 38 insertions(+), 114 deletions(-) delete mode 100644 examples/spot/README.md delete mode 100644 examples/spot/main.tf delete mode 100644 examples/spot/outputs.tf diff --git a/README.md b/README.md index 474dc91e..ccfae393 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -AWS EC2 Instance Terraform module -================================= +AWS EC2 Spot Instance Terraform module +====================================== -Terraform module which creates EC2 Spot instance(s) request(s) on AWS. +Terraform module which creates EC2 Spot Instance(s) request(s) on AWS. These types of resources are supported: -* [EC2 Spot Instance Request](https://www.terraform.io/docs/providers/aws/r/spot_instance_request.html) +* [EC2 Spot Instance ](https://www.terraform.io/docs/providers/aws/r/spot_instance_request.html) Usage ----- diff --git a/examples/basic/README.md b/examples/basic/README.md index 27a1f5f5..1462b598 100644 --- a/examples/basic/README.md +++ b/examples/basic/README.md @@ -1,7 +1,7 @@ -Basic EC2 instance +Basic EC2 spot instance request ================== -Configuration in this directory creates single EC2 instance with minimum set of arguments: AMI ID and instance type. +Configuration in this directory creates single EC2 spot instance request with minimum set of arguments: AMI ID and instance type. Unspecified arguments for security group id and subnet are inherited from the default VPC. diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 31ef309a..4dd43d72 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -37,7 +37,7 @@ module "security_group" { source = "terraform-aws-modules/security-group/aws" name = "example" - description = "Security group for example usage with EC2 instance" + description = "Security group" vpc_id = "${data.aws_vpc.default.id}" ingress_cidr_blocks = ["0.0.0.0/0"] @@ -45,7 +45,7 @@ module "security_group" { egress_rules = ["all-all"] } -module "ec2" { +module "ec2_spot" { source = "../../" name = "example" @@ -53,4 +53,5 @@ module "ec2" { instance_type = "t2.micro" vpc_security_group_ids = ["${module.security_group.this_security_group_id}"] associate_public_ip_address = true + spot_price = "0.03" } diff --git a/examples/basic/outputs.tf b/examples/basic/outputs.tf index e87e2d8b..b72e6492 100644 --- a/examples/basic/outputs.tf +++ b/examples/basic/outputs.tf @@ -1,19 +1,39 @@ output "id" { description = "List of IDs of instances" - value = ["${module.ec2.id}"] + value = ["${module.ec2_spot.id}"] } output "public_dns" { - description = "List of public DNS names assigned to the instances" - value = ["${module.ec2.public_dns}"] + description = "List of public DNS names assigned to the instances. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC" + value = ["${module.ec2_spot.public_dns}"] } -output "instance_id" { - description = "EC2 instance ID" - value = "${module.ec2.id[0]}" +output "public_ip" { + description = "List of public IP addresses assigned to the instances, if applicable" + value = ["${module.ec2_spot.public_ip}"] } -output "instance_public_dns" { - description = "Public DNS name assigned to the EC2 instance" - value = "${module.ec2.public_dns[0]}" +output "private_dns" { + description = "List of private DNS names assigned to the instances. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC" + value = ["${module.ec2_spot.private_dns}"] +} + +output "private_ip" { + description = "List of private IP addresses assigned to the instances" + value = ["${module.ec2_spot.private_ip}"] +} + +output "spot_bid_status" { + description = "The current bid status of the Spot Instance Request." + value = ["${module.ec2_spot.spot_bid_status}"] +} + +output "spot_request_state" { + description = "The current request state of the Spot Instance Request." + value = ["${module.ec2_spot.spot_request_state}"] +} + +output "spot_instance_id" { + description = "The Instance ID (if any) that is currently fulfilling the Spot Instance request." + value = ["${module.ec2_spot.spot_instance_id}"] } diff --git a/examples/spot/README.md b/examples/spot/README.md deleted file mode 100644 index 1462b598..00000000 --- a/examples/spot/README.md +++ /dev/null @@ -1,21 +0,0 @@ -Basic EC2 spot instance request -================== - -Configuration in this directory creates single EC2 spot instance request with minimum set of arguments: AMI ID and instance type. - -Unspecified arguments for security group id and subnet are inherited from the default VPC. - -This example outputs instance id and public DNS name as a single value and as a list. - -Usage -===== - -To run this example you need to execute: - -```bash -$ terraform init -$ terraform plan -$ terraform apply -``` - -Note that this example may create resources which can cost money. Run `terraform destroy` when you don't need these resources. diff --git a/examples/spot/main.tf b/examples/spot/main.tf deleted file mode 100644 index 12b7ddd2..00000000 --- a/examples/spot/main.tf +++ /dev/null @@ -1,57 +0,0 @@ -provider "aws" { - region = "eu-west-1" -} - -################################################################## -# Data sources to get VPC, subnet, security group and AMI details -################################################################## -data "aws_vpc" "default" { - default = true -} - -data "aws_subnet_ids" "all" { - vpc_id = "${data.aws_vpc.default.id}" -} - -data "aws_ami" "amazon_linux" { - most_recent = true - - filter { - name = "name" - - values = [ - "amzn-ami-hvm-*-x86_64-gp2", - ] - } - - filter { - name = "owner-alias" - - values = [ - "amazon", - ] - } -} - -module "security_group" { - source = "terraform-aws-modules/security-group/aws" - - name = "example" - description = "Security group for example usage with EC2 instance" - vpc_id = "${data.aws_vpc.default.id}" - - ingress_cidr_blocks = ["0.0.0.0/0"] - ingress_rules = ["http-80-tcp", "all-icmp"] - egress_rules = ["all-all"] -} - -module "ec2_spot" { - source = "../../" - - name = "example" - ami = "${data.aws_ami.amazon_linux.id}" - instance_type = "t2.micro" - vpc_security_group_ids = ["${module.security_group.this_security_group_id}"] - associate_public_ip_address = true - spot_price = "0.03" -} diff --git a/examples/spot/outputs.tf b/examples/spot/outputs.tf deleted file mode 100644 index e87e2d8b..00000000 --- a/examples/spot/outputs.tf +++ /dev/null @@ -1,19 +0,0 @@ -output "id" { - description = "List of IDs of instances" - value = ["${module.ec2.id}"] -} - -output "public_dns" { - description = "List of public DNS names assigned to the instances" - value = ["${module.ec2.public_dns}"] -} - -output "instance_id" { - description = "EC2 instance ID" - value = "${module.ec2.id[0]}" -} - -output "instance_public_dns" { - description = "Public DNS name assigned to the EC2 instance" - value = "${module.ec2.public_dns[0]}" -} From 0004c2c1f064c1d5d5fc9c51f5c4998e61397d5a Mon Sep 17 00:00:00 2001 From: johnypony3 Date: Wed, 1 Nov 2017 04:55:59 -0700 Subject: [PATCH 9/9] commited wrong file --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ccfae393..8c039727 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -AWS EC2 Spot Instance Terraform module -====================================== +AWS EC2 Spot Instance Request Terraform module +================================= -Terraform module which creates EC2 Spot Instance(s) request(s) on AWS. +Terraform module which creates EC2 Spot Request request(s) on AWS. These types of resources are supported: -* [EC2 Spot Instance ](https://www.terraform.io/docs/providers/aws/r/spot_instance_request.html) +* [EC2 Spot Instance Request](https://www.terraform.io/docs/providers/aws/r/spot_instance_request.html) Usage ----- @@ -45,8 +45,8 @@ Limitations Authors ------- -Module managed by [Anton Babenko](https://github.com/antonbabenko). -Temporarily managed by [johnypony3](https://github.com/johnypony3) +Module based on the work of [Anton Babenko](https://github.com/antonbabenko). +Written and managed by [johnypony3](https://github.com/johnypony3) License -------