@@ -105,10 +132,27 @@ data "aws_ami" "encrypted-ami" {
}
```
## Conditional creation
The following combinations are supported to conditionally create resources:
- Disable resource creation (no resources created):
```hcl
create=false
```
- Create spot instance:
```hcl
create_spot_instance=true
```
## Notes
-`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.
- 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).
- 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`
<!-- 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 |
| <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 |
| <aname="input_create"></a>[create](#input\_create) | Whether to create an instance | `bool` | `true` | no |
| <aname="input_create_spot_instance"></a>[create\_spot\_instance](#input\_create\_spot\_instance) | Depicts if the instance is a spot instance | `bool` | `false` | no |
| <aname="input_disable_api_termination"></a>[disable\_api\_termination](#input\_disable\_api\_termination) | If true, enables EC2 Instance Termination Protection | `bool` | `null` | no |
| <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 |
| <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.
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <aname="input_subnet_id"></a>[subnet\_id](#input\_subnet\_id) | The VPC Subnet ID to launch in | `string` | `null` | no |
| <aname="input_tags"></a>[tags](#input\_tags) | A mapping of tags to assign to the resource | `map(string)` | `{}` | no |
| <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.
| <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 |
| <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 |
| <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 |
| <aname="output_spot_bid_status"></a>[spot\_bid\_status](#output\_spot\_bid\_status) | The current bid status of the Spot Instance Request |
| <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 |
| <aname="output_spot_request_state"></a>[spot\_request\_state](#output\_spot\_request\_state) | The current request state of the Spot Instance Request |
| <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 |
| <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 |
| <aname="output_ec2_multiple"></a>[ec2\_multiple](#output\_ec2\_multiple) | The full output of the `ec2_module` module |
| <aname="output_ec2_spot_instance_arn"></a>[ec2\_spot\_instance\_arn](#output\_ec2\_spot\_instance\_arn) | The ARN of the instance |
| <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 |
| <aname="output_ec2_spot_instance_id"></a>[ec2\_spot\_instance\_id](#output\_ec2\_spot\_instance\_id) | The ID of the instance |
| <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` |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <aname="output_ec2_t2_unlimited_arn"></a>[ec2\_t2\_unlimited\_arn](#output\_ec2\_t2\_unlimited\_arn) | The ARN of the instance |
| <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 |
| <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.
| <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 |
| <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 |
| <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 |
| <aname="output_spot_bid_status"></a>[spot\_bid\_status](#output\_spot\_bid\_status) | The current bid status of the Spot Instance Request |
| <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 |
| <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"
value=module.ec2_spot_instance.private_dns
}
output"ec2_spot_instance_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=module.ec2_spot_instance.public_dns
}
output"ec2_spot_instance_public_ip"{
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"
value=module.ec2_spot_instance.public_ip
}
output"ec2_spot_instance_tags_all"{
description="A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block"
value=module.ec2_spot_instance.tags_all
}
output"spot_bid_status"{
description="The current bid status of the Spot Instance Request"
value=module.ec2_spot_instance.spot_bid_status
}
output"spot_request_state"{
description="The current request state of the Spot Instance Request"
value=module.ec2_spot_instance.spot_request_state
}
output"spot_instance_id"{
description="The Instance ID (if any) that is currently fulfilling the Spot Instance request"
description="Base-64 encoded encrypted password data for the instance. Useful for getting the administrator password for instances running Microsoft Windows. This attribute is only exported if `get_password_data` is true"
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"
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"
description="Depicts if the instance is a spot instance"
type=bool
default=false
}
variable"spot_price"{
description="The maximum price to request on the spot market. Defaults to on-demand price"
type=string
default=null
}
variable"spot_wait_for_fulfillment"{
description="If set, Terraform will wait for the Spot Request to be fulfilled, and will throw an error if the timeout of 10m is reached"
type=bool
default=null
}
variable"spot_type"{
description="If set to one-time, after the instance is terminated, the spot request will be closed. Default `persistent`"
type=string
default=null
}
variable"spot_launch_group"{
description="A launch group is a group of spot instances that launch together and terminate together. If left empty instances are launched and terminated individually"
type=string
default=null
}
variable"spot_block_duration_minutes"{
description="The required duration for the Spot instances, in minutes. This value must be a multiple of 60 (60, 120, 180, 240, 300, or 360)"
type=number
default=null
}
variable"spot_instance_interruption_behavior"{
description="Indicates Spot instance behavior when it is interrupted. Valid values are `terminate`, `stop`, or `hibernate`"
type=string
default=null
}
variable"spot_valid_until"{
description="The end date and time of the request, in UTC RFC3339 format(for example, YYYY-MM-DDTHH:MM:SSZ)"
type=string
default=null
}
variable"spot_valid_from"{
description="The start date and time of the request, in UTC RFC3339 format(for example, YYYY-MM-DDTHH:MM:SSZ)"