You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -105,10 +132,27 @@ data "aws_ami" "encrypted-ami" {
105
132
}
106
133
```
107
134
135
+
## Conditional creation
136
+
137
+
The following combinations are supported to conditionally create resources:
138
+
139
+
- Disable resource creation (no resources created):
140
+
141
+
```hcl
142
+
create = false
143
+
```
144
+
145
+
- Create spot instance:
146
+
147
+
```hcl
148
+
create_spot_instance = true
149
+
```
150
+
108
151
## Notes
109
152
110
153
-`network_interface` can't be specified together with `vpc_security_group_ids`, `associate_public_ip_address`, `subnet_id`. See [complete example](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/complete) for details.
111
154
- Changes in `ebs_block_device` argument will be ignored. Use [aws_volume_attachment](https://www.terraform.io/docs/providers/aws/r/volume_attachment.html) resource to attach and detach volumes from AWS EC2 instances. See [this example](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/volume-attachment).
155
+
- In regards to spot instances, you must grant the `AWSServiceRoleForEC2Spot` service-linked role access to any custom KMS keys, otherwise your spot request and instances will fail with `bad parameters`. You can see more details about why the request failed by using the awscli and `aws ec2 describe-spot-instance-requests`
112
156
113
157
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
| <aname="input_cpu_credits"></a> [cpu\_credits](#input\_cpu\_credits)| The credit option for CPU usage (unlimited or standard) |`string`|`null`| no |
147
192
| <aname="input_cpu_threads_per_core"></a> [cpu\_threads\_per\_core](#input\_cpu\_threads\_per\_core)| Sets the number of CPU threads per core for an instance (has no effect unless cpu\_core\_count is also set). |`number`|`null`| no |
148
193
| <aname="input_create"></a> [create](#input\_create)| Whether to create an instance |`bool`|`true`| no |
194
+
| <aname="input_create_spot_instance"></a> [create\_spot\_instance](#input\_create\_spot\_instance)| Depicts if the instance is a spot instance |`bool`|`false`| no |
149
195
| <aname="input_disable_api_termination"></a> [disable\_api\_termination](#input\_disable\_api\_termination)| If true, enables EC2 Instance Termination Protection |`bool`|`null`| no |
150
196
| <aname="input_ebs_block_device"></a> [ebs\_block\_device](#input\_ebs\_block\_device)| Additional EBS block devices to attach to the instance |`list(map(string))`|`[]`| no |
151
197
| <aname="input_ebs_optimized"></a> [ebs\_optimized](#input\_ebs\_optimized)| If true, the launched EC2 instance will be EBS-optimized |`bool`|`null`| no |
@@ -171,6 +217,14 @@ No modules.
171
217
| <aname="input_root_block_device"></a> [root\_block\_device](#input\_root\_block\_device)| Customize details about the root block device of the instance. See Block Devices below for details |`list(any)`|`[]`| no |
172
218
| <aname="input_secondary_private_ips"></a> [secondary\_private\_ips](#input\_secondary\_private\_ips)| A list of secondary private IPv4 addresses to assign to the instance's primary network interface (eth0) in a VPC. Can only be assigned to the primary network interface (eth0) attached at instance creation, not a pre-existing network interface i.e. referenced in a `network_interface block`|`list(string)`|`null`| no |
173
219
| <aname="input_source_dest_check"></a> [source\_dest\_check](#input\_source\_dest\_check)| Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs. |`bool`|`true`| no |
220
+
| <aname="input_spot_block_duration_minutes"></a> [spot\_block\_duration\_minutes](#input\_spot\_block\_duration\_minutes)| The required duration for the Spot instances, in minutes. This value must be a multiple of 60 (60, 120, 180, 240, 300, or 360) |`number`|`null`| no |
221
+
| <aname="input_spot_instance_interruption_behavior"></a> [spot\_instance\_interruption\_behavior](#input\_spot\_instance\_interruption\_behavior)| Indicates Spot instance behavior when it is interrupted. Valid values are `terminate`, `stop`, or `hibernate`|`string`|`null`| no |
222
+
| <aname="input_spot_launch_group"></a> [spot\_launch\_group](#input\_spot\_launch\_group)| A launch group is a group of spot instances that launch together and terminate together. If left empty instances are launched and terminated individually |`string`|`null`| no |
223
+
| <aname="input_spot_price"></a> [spot\_price](#input\_spot\_price)| The maximum price to request on the spot market. Defaults to on-demand price |`string`|`null`| no |
224
+
| <aname="input_spot_type"></a> [spot\_type](#input\_spot\_type)| If set to one-time, after the instance is terminated, the spot request will be closed. Default `persistent`|`string`|`null`| no |
225
+
| <aname="input_spot_valid_from"></a> [spot\_valid\_from](#input\_spot\_valid\_from)| The start date and time of the request, in UTC RFC3339 format(for example, YYYY-MM-DDTHH:MM:SSZ) |`string`|`null`| no |
226
+
| <aname="input_spot_valid_until"></a> [spot\_valid\_until](#input\_spot\_valid\_until)| The end date and time of the request, in UTC RFC3339 format(for example, YYYY-MM-DDTHH:MM:SSZ) |`string`|`null`| no |
227
+
| <aname="input_spot_wait_for_fulfillment"></a> [spot\_wait\_for\_fulfillment](#input\_spot\_wait\_for\_fulfillment)| If set, Terraform will wait for the Spot Request to be fulfilled, and will throw an error if the timeout of 10m is reached |`bool`|`null`| no |
174
228
| <aname="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id)| The VPC Subnet ID to launch in |`string`|`null`| no |
175
229
| <aname="input_tags"></a> [tags](#input\_tags)| A mapping of tags to assign to the resource |`map(string)`|`{}`| no |
176
230
| <aname="input_tenancy"></a> [tenancy](#input\_tenancy)| The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host. |`string`|`null`| no |
@@ -194,6 +248,9 @@ No modules.
194
248
| <aname="output_private_dns"></a> [private\_dns](#output\_private\_dns)| 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 |
195
249
| <aname="output_public_dns"></a> [public\_dns](#output\_public\_dns)| The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC |
196
250
| <aname="output_public_ip"></a> [public\_ip](#output\_public\_ip)| The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
251
+
| <aname="output_spot_bid_status"></a> [spot\_bid\_status](#output\_spot\_bid\_status)| The current bid status of the Spot Instance Request |
252
+
| <aname="output_spot_instance_id"></a> [spot\_instance\_id](#output\_spot\_instance\_id)| The Instance ID (if any) that is currently fulfilling the Spot Instance request |
253
+
| <aname="output_spot_request_state"></a> [spot\_request\_state](#output\_spot\_request\_state)| The current request state of the Spot Instance Request |
197
254
| <aname="output_tags_all"></a> [tags\_all](#output\_tags\_all)| A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
| <aname="output_ec2_complete_public_ip"></a> [ec2\_complete\_public\_ip](#output\_ec2\_complete\_public\_ip)| The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
70
71
| <aname="output_ec2_complete_tags_all"></a> [ec2\_complete\_tags\_all](#output\_ec2\_complete\_tags\_all)| A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
71
72
| <aname="output_ec2_multiple"></a> [ec2\_multiple](#output\_ec2\_multiple)| The full output of the `ec2_module` module |
73
+
| <aname="output_ec2_spot_instance_arn"></a> [ec2\_spot\_instance\_arn](#output\_ec2\_spot\_instance\_arn)| The ARN of the instance |
74
+
| <aname="output_ec2_spot_instance_capacity_reservation_specification"></a> [ec2\_spot\_instance\_capacity\_reservation\_specification](#output\_ec2\_spot\_instance\_capacity\_reservation\_specification)| Capacity reservation specification of the instance |
75
+
| <aname="output_ec2_spot_instance_id"></a> [ec2\_spot\_instance\_id](#output\_ec2\_spot\_instance\_id)| The ID of the instance |
76
+
| <aname="output_ec2_spot_instance_instance_state"></a> [ec2\_spot\_instance\_instance\_state](#output\_ec2\_spot\_instance\_instance\_state)| The state of the instance. One of: `pending`, `running`, `shutting-down`, `terminated`, `stopping`, `stopped`|
77
+
| <aname="output_ec2_spot_instance_primary_network_interface_id"></a> [ec2\_spot\_instance\_primary\_network\_interface\_id](#output\_ec2\_spot\_instance\_primary\_network\_interface\_id)| The ID of the instance's primary network interface |
78
+
| <aname="output_ec2_spot_instance_private_dns"></a> [ec2\_spot\_instance\_private\_dns](#output\_ec2\_spot\_instance\_private\_dns)| 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 |
79
+
| <aname="output_ec2_spot_instance_public_dns"></a> [ec2\_spot\_instance\_public\_dns](#output\_ec2\_spot\_instance\_public\_dns)| The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC |
80
+
| <aname="output_ec2_spot_instance_public_ip"></a> [ec2\_spot\_instance\_public\_ip](#output\_ec2\_spot\_instance\_public\_ip)| The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
81
+
| <aname="output_ec2_spot_instance_tags_all"></a> [ec2\_spot\_instance\_tags\_all](#output\_ec2\_spot\_instance\_tags\_all)| A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
72
82
| <aname="output_ec2_t2_unlimited_arn"></a> [ec2\_t2\_unlimited\_arn](#output\_ec2\_t2\_unlimited\_arn)| The ARN of the instance |
73
83
| <aname="output_ec2_t2_unlimited_capacity_reservation_specification"></a> [ec2\_t2\_unlimited\_capacity\_reservation\_specification](#output\_ec2\_t2\_unlimited\_capacity\_reservation\_specification)| Capacity reservation specification of the instance |
74
84
| <aname="output_ec2_t2_unlimited_id"></a> [ec2\_t2\_unlimited\_id](#output\_ec2\_t2\_unlimited\_id)| The ID of the instance |
@@ -87,4 +97,7 @@ No inputs.
87
97
| <aname="output_ec2_t3_unlimited_public_dns"></a> [ec2\_t3\_unlimited\_public\_dns](#output\_ec2\_t3\_unlimited\_public\_dns)| The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC |
88
98
| <aname="output_ec2_t3_unlimited_public_ip"></a> [ec2\_t3\_unlimited\_public\_ip](#output\_ec2\_t3\_unlimited\_public\_ip)| The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
89
99
| <aname="output_ec2_t3_unlimited_tags_all"></a> [ec2\_t3\_unlimited\_tags\_all](#output\_ec2\_t3\_unlimited\_tags\_all)| A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
100
+
| <aname="output_spot_bid_status"></a> [spot\_bid\_status](#output\_spot\_bid\_status)| The current bid status of the Spot Instance Request |
101
+
| <aname="output_spot_instance_id"></a> [spot\_instance\_id](#output\_spot\_instance\_id)| The Instance ID (if any) that is currently fulfilling the Spot Instance request |
102
+
| <aname="output_spot_request_state"></a> [spot\_request\_state](#output\_spot\_request\_state)| The current request state of the Spot Instance Request |
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"
173
+
value=module.ec2_spot_instance.private_dns
174
+
}
175
+
176
+
output"ec2_spot_instance_public_dns" {
177
+
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"
178
+
value=module.ec2_spot_instance.public_dns
179
+
}
180
+
181
+
output"ec2_spot_instance_public_ip" {
182
+
description="The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached"
183
+
value=module.ec2_spot_instance.public_ip
184
+
}
185
+
186
+
output"ec2_spot_instance_tags_all" {
187
+
description="A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block"
188
+
value=module.ec2_spot_instance.tags_all
189
+
}
190
+
191
+
output"spot_bid_status" {
192
+
description="The current bid status of the Spot Instance Request"
193
+
value=module.ec2_spot_instance.spot_bid_status
194
+
}
195
+
196
+
output"spot_request_state" {
197
+
description="The current request state of the Spot Instance Request"
198
+
value=module.ec2_spot_instance.spot_request_state
199
+
}
200
+
201
+
output"spot_instance_id" {
202
+
description="The Instance ID (if any) that is currently fulfilling the Spot Instance request"
0 commit comments