Skip to content

Commit

Permalink
feat(aws_instance): add instance market options block
Browse files Browse the repository at this point in the history
  • Loading branch information
haidargit committed Aug 19, 2024
1 parent 6cea431 commit 9259333
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 27 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ Available targets:
| <a name="input_external_network_interfaces"></a> [external\_network\_interfaces](#input\_external\_network\_interfaces) | The external interface definitions to attach to the instances. This depends on the instance type | <pre>list(object({<br> delete_on_termination = bool<br> device_index = number<br> network_card_index = number<br> network_interface_id = string<br> }))</pre> | `null` | no |
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
| <a name="input_instance_initiated_shutdown_behavior"></a> [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Specifies whether an instance stops or terminates when you initiate shutdown from the instance. Can be one of 'stop' or 'terminate'. | `string` | `null` | no |
| <a name="input_instance_market_options_enabled"></a> [instance\_market\_options\_enabled](#input\_instance\_market\_options\_enabled) | Wheter to enable the purchasing option for the instances | `bool` | `false` | no |
| <a name="input_instance_profile"></a> [instance\_profile](#input\_instance\_profile) | A pre-defined profile to attach to the instance (default is to build our own) | `string` | `""` | no |
| <a name="input_instance_profile_enabled"></a> [instance\_profile\_enabled](#input\_instance\_profile\_enabled) | Whether an IAM instance profile is created to pass a role to an Amazon EC2 instance when the instance starts | `bool` | `true` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The type of the instance | `string` | `"t2.micro"` | no |
Expand Down Expand Up @@ -327,7 +326,7 @@ Available targets:
| <a name="output_security_group_id"></a> [security\_group\_id](#output\_security\_group\_id) | EC2 instance Security Group ID |
| <a name="output_security_group_ids"></a> [security\_group\_ids](#output\_security\_group\_ids) | IDs on the AWS Security Groups associated with the instance |
| <a name="output_security_group_name"></a> [security\_group\_name](#output\_security\_group\_name) | EC2 instance Security Group name |
| <a name="output_spot_instance_request_id"></a> [spot\_instance\_request\_id](#output\_spot\_instance\_request\_id) | the ID of the Spot Instance request |
| <a name="output_spot_instance_request_id"></a> [spot\_instance\_request\_id](#output\_spot\_instance\_request\_id) | ID of the Spot Instance request |
| <a name="output_ssh_key_pair"></a> [ssh\_key\_pair](#output\_ssh\_key\_pair) | Name of the SSH key pair provisioned on the instance |
<!-- markdownlint-restore -->

Expand Down
3 changes: 1 addition & 2 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
| <a name="input_external_network_interfaces"></a> [external\_network\_interfaces](#input\_external\_network\_interfaces) | The external interface definitions to attach to the instances. This depends on the instance type | <pre>list(object({<br> delete_on_termination = bool<br> device_index = number<br> network_card_index = number<br> network_interface_id = string<br> }))</pre> | `null` | no |
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
| <a name="input_instance_initiated_shutdown_behavior"></a> [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Specifies whether an instance stops or terminates when you initiate shutdown from the instance. Can be one of 'stop' or 'terminate'. | `string` | `null` | no |
| <a name="input_instance_market_options_enabled"></a> [instance\_market\_options\_enabled](#input\_instance\_market\_options\_enabled) | Wheter to enable the purchasing option for the instances | `bool` | `false` | no |
| <a name="input_instance_profile"></a> [instance\_profile](#input\_instance\_profile) | A pre-defined profile to attach to the instance (default is to build our own) | `string` | `""` | no |
| <a name="input_instance_profile_enabled"></a> [instance\_profile\_enabled](#input\_instance\_profile\_enabled) | Whether an IAM instance profile is created to pass a role to an Amazon EC2 instance when the instance starts | `bool` | `true` | no |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The type of the instance | `string` | `"t2.micro"` | no |
Expand Down Expand Up @@ -168,6 +167,6 @@
| <a name="output_security_group_id"></a> [security\_group\_id](#output\_security\_group\_id) | EC2 instance Security Group ID |
| <a name="output_security_group_ids"></a> [security\_group\_ids](#output\_security\_group\_ids) | IDs on the AWS Security Groups associated with the instance |
| <a name="output_security_group_name"></a> [security\_group\_name](#output\_security\_group\_name) | EC2 instance Security Group name |
| <a name="output_spot_instance_request_id"></a> [spot\_instance\_request\_id](#output\_spot\_instance\_request\_id) | the ID of the Spot Instance request |
| <a name="output_spot_instance_request_id"></a> [spot\_instance\_request\_id](#output\_spot\_instance\_request\_id) | ID of the Spot Instance request |
| <a name="output_ssh_key_pair"></a> [ssh\_key\_pair](#output\_ssh\_key\_pair) | Name of the SSH key pair provisioned on the instance |
<!-- markdownlint-restore -->
2 changes: 0 additions & 2 deletions examples/complete/fixtures.us-east-2.spot.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ ssh_public_key_path = "/secrets"

metric_treat_missing_data = "notBreaching"

instance_market_options_enabled = true

market_type = "spot"

spot_options_attributes = [{
Expand Down
1 change: 0 additions & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ module "ec2_instance" {
instance_profile = aws_iam_instance_profile.test.name
tenancy = var.tenancy
metric_treat_missing_data = var.metric_treat_missing_data
instance_market_options_enabled = var.instance_market_options_enabled
market_type = var.market_type
spot_options_attributes = var.spot_options_attributes

Expand Down
4 changes: 2 additions & 2 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ output "security_group_name" {
}

output "instance_lifecycle" {
value = var.instance_market_options_enabled ? module.ec2_instance.instance_lifecycle : null
value = var.spot_options_attributes != [] ? module.ec2_instance.instance_lifecycle : null
description = "Indicates whether this is a Spot Instance or a Scheduled Instance"
}

output "spot_instance_request_id" {
value = var.instance_market_options_enabled && var.market_type == "spot" ? module.ec2_instance.spot_instance_request_id : null
value = var.spot_options_attributes != [] && var.market_type == "spot" ? module.ec2_instance.spot_instance_request_id : null
description = "the ID of the Spot Instance request"
}
6 changes: 0 additions & 6 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ variable "metric_treat_missing_data" {
}
}

variable "instance_market_options_enabled" {
type = bool
description = "Wheter to enable the purchasing option for the instances"
default = false
}

variable "market_type" {
type = string
description = "(Optional) Type of market for the instance. Valid values are `spot` and `capacity-block`. Defaults to `spot`. Required if a non-empty value is provided for `spot_options_attributes`."
Expand Down
5 changes: 1 addition & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ resource "aws_instance" "default" {
cpu_credits = var.burstable_mode
}

dynamic "instance_market_options" {
for_each = var.instance_market_options_enabled ? [var.spot_options_attributes] : []
content {
instance_market_options {
market_type = var.market_type

dynamic "spot_options" {
Expand All @@ -182,7 +180,6 @@ resource "aws_instance" "default" {
valid_until = spot_options.value.valid_until
}
}
}
}

tags = module.this.tags
Expand Down
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ output "security_group_name" {
}

output "instance_lifecycle" {
value = var.instance_market_options_enabled ? aws_instance.default[*].instance_lifecycle : null
value = var.spot_options_attributes != [] ? aws_instance.default[*].instance_lifecycle : null
description = "Indicates whether this is a Spot Instance or a Scheduled Instance"
}

output "spot_instance_request_id" {
value = var.instance_market_options_enabled && var.market_type == "spot" ? aws_instance.default[*].spot_instance_request_id : null
value = var.spot_options_attributes != [] && var.market_type == "spot" ? aws_instance.default[*].spot_instance_request_id : null
description = "ID of the Spot Instance request"
}
6 changes: 0 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ variable "burstable_mode" {
default = null
}

variable "instance_market_options_enabled" {
type = bool
description = "Whether to enable the purchasing option for the instances"
default = false
}

variable "market_type" {
type = string
description = "Type of market for the instance. Valid values are `spot` and `capacity-block`. Defaults to `spot`. Required if a non-empty value is provided for `spot_options_attributes`."
Expand Down

0 comments on commit 9259333

Please sign in to comment.