Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions modules/instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ No modules.
| <a name="input_availability_zone"></a> [availability\_zone](#input\_availability\_zone) | (Optional) AZ (Availability Zone) to create the instance in. | `string` | `null` | no |
| <a name="input_cpu_credit_specification"></a> [cpu\_credit\_specification](#input\_cpu\_credit\_specification) | (Optional) The specification for CPU credit. A credit specification is only available for T2, T3, and T3a instances. Valid values are `STANDARD` or `UNLIMITED`. T3 instances are launched as `UNLIMITED` by default. T2 instances are launched as `STANDARD` by default. | `string` | `null` | no |
| <a name="input_cpu_options"></a> [cpu\_options](#input\_cpu\_options) | (Optional) The configuration of the CPU options to optimize the instance for specific workloads or business needs. You can specify these CPU options during instance launch. There is no additional or reduced charge for specifying CPU options. `cpu_options` block as defined below.<br> (Optional) `core_count` - Sets the number of CPU cores for an instance. This option is only supported on creation of instance type that support CPU Options CPU Cores and Threads Per CPU Core Per Instance Type - specifying this option for unsupported instance types will return an error from the EC2 API.<br> (Optional) `threads_per_core` - Set the number of CPU threads per core for the instance. If set to to 1, hyperthreading is disabled on the launched instance. | <pre>object({<br> core_count = number<br> threads_per_core = number<br> })</pre> | `null` | no |
| <a name="input_dns_resource_name_ipv4_enabled"></a> [dns\_resource\_name\_ipv4\_enabled](#input\_dns\_resource\_name\_ipv4\_enabled) | (Optional) Whether to resolve the IPv4 address of the EC2 instance for requests to your resource-name based domain. | `bool` | `null` | no |
| <a name="input_dns_resource_name_ipv6_enabled"></a> [dns\_resource\_name\_ipv6\_enabled](#input\_dns\_resource\_name\_ipv6\_enabled) | (Optional) Whether to resolve the IPv6 address of the EC2 instance for requests to your resource-name based domain. | `bool` | `null` | no |
| <a name="input_ebs_optimized"></a> [ebs\_optimized](#input\_ebs\_optimized) | (Optional) Whether to enable additional, dedicated throughput between Amazon EC2 and Amazon EBS. The launched EC2 instance will be EBS-optimized if true. Note that if this is not set on an instance type that is optimized by default then this will show as disabled but if the instance type is optimized by default then there is no need to set this and there is no effect to disabling it. | `bool` | `null` | no |
| <a name="input_eip_associations"></a> [eip\_associations](#input\_eip\_associations) | (Optional) A list of configurations to associate Elastic IPs to the network interfaces of the instance. Each `eip_associations` block as defined below.<br> (Required) `eip` - The allocation ID of Elastic IP to associate.<br> (Optional) `private_ip` - The primary or secondary private IP address to associate with the Elastic IP address. If no private IP address is specified, the Elastic IP address is associated with the primary private IP address. | `list(map(string))` | `[]` | no |
| <a name="input_host_id"></a> [host\_id](#input\_host\_id) | (Optional) The ID of a dedicated host that the instance will be assigned to. Use when an instance is to be launched on a specific dedicated host. | `string` | `null` | no |
| <a name="input_hostname_type"></a> [hostname\_type](#input\_hostname\_type) | (Optional) The type of hostname for the EC2 instances. For IPv4 only subnets, an instance DNS name must be based on the instance IPv4 address. For IPv6 native subnets, an instance DNS name must be based on the instance ID. For dual-stack subnets, you can specify whether DNS names use the instance IPv4 address or the instance ID. Valid values are `IP_V4` and `RESOURCE_NAME`. | `string` | `null` | no |
| <a name="input_instance_profile"></a> [instance\_profile](#input\_instance\_profile) | (Optional) The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile. Ensure your credentials have the correct permission to assign the instance profile according to the EC2 documentation, notably `iam:PassRole`. | `string` | `null` | no |
| <a name="input_launch_template"></a> [launch\_template](#input\_launch\_template) | (Optional) The configuration for launch template of the instance. Launch Template parameters will be used only once during instance creation. If you want to update existing instance you need to change parameters directly. Updating Launch Template specification will force a new instance. Any other instance parameters that you specify will override the same parameters in the launch template. `launch_template` block as defined below.<br> (Optional) `id` - The ID of the launch template. Conflicts with `name`.<br> (Optional) `name` - The name of the launch template. Conflicts with `id`.<br> (Optional) `version` - The version of launch template. Valid value is a specific version number, `$Latest` or `$Default`. Defaults to `$Default`. | `map(string)` | `null` | no |
| <a name="input_metadata_options"></a> [metadata\_options](#input\_metadata\_options) | (Optional) The configuration for metadata of the instance. `metadata_options` block as defined below.<br> (Optional) `http_enabled` - Whether the metadata service is available. You can turn off access to your instance metadata by disabling the HTTP endpoint of the instance metadata service. Defaults to `true`.<br> (Optional) `http_token_required` - Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2 (IMDSv2). Defaults to `false`.<br> (Optional) `http_put_response_hop_limit` - A desired HTTP PUT response hop limit for instance metadata requests. The larger the number, the further instance metadata requests can travel. Valid values are integer from `1` to `64`. Defaults to `1`.<br> (Optional) `instance_tags_enabled` - Whether to enable the access to instance tags from the instance metadata service. Defaults to `false`. | `any` | `null` | no |
Expand Down Expand Up @@ -93,12 +96,12 @@ No modules.
| <a name="output_launch_template"></a> [launch\_template](#output\_launch\_template) | The configuration for launch template of the instance. |
| <a name="output_metadata"></a> [metadata](#output\_metadata) | The configuration for metadata of the instance. |
| <a name="output_name"></a> [name](#output\_name) | The name of the instance. |
| <a name="output_network"></a> [network](#output\_network) | The network configuration for the instance.<br> `availability_zone` - The Availability Zone of the instance.<br> `subnet_id` - The ID of subnet of the launched instance.<br> `source_dest_check_enabled` - Whether the traffic is routed to the instance when the destination address does not match the instance.<br> `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.<br> `private_ip` - The private IP address assigned to the instance.<br> `secondary_private_ips` - A list of secondary private IPv4 addresses assigned to the instance's primary network interface. |
| <a name="output_network"></a> [network](#output\_network) | The network configuration for the instance.<br> `availability_zone` - The Availability Zone of the instance.<br> `subnet_id` - The ID of subnet of the launched instance.<br> `source_dest_check_enabled` - Whether the traffic is routed to the instance when the destination address does not match the instance.<br><br> `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.<br> `private_ip` - The private IP address assigned to the instance.<br> `secondary_private_ips` - A list of secondary private IPv4 addresses assigned to the instance's primary network interface.<br><br> `hostname_type` - The type of hostname for the EC2 instances.<br> `dns_resource_name_ipv4_enabled` - Whether to resolve the IPv4 address of the EC2 instance for requests to your resource-name based domain.<br> `dns_resource_name_ipv6_enabled` - Whether to resolve the IPv6 address of the EC2 instance for requests to your resource-name based domain. |
| <a name="output_private_domain"></a> [private\_domain](#output\_private\_domain) | 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. |
| <a name="output_public_domain"></a> [public\_domain](#output\_public\_domain) | The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC. |
| <a name="output_ssh_key"></a> [ssh\_key](#output\_ssh\_key) | The name of the SSH Key to access the instance. |
| <a name="output_state"></a> [state](#output\_state) | The state of the instance. One of: `pending`, `running`, `shutting-down`, `terminated`, `stopping`, `stopped`. |
| <a name="output_storage"></a> [storage](#output\_storage) | The configuration of storage for the instance. |
| <a name="output_test"></a> [test](#output\_test) | The configuration of rule groups associated with the firewall. |
| <a name="output_type"></a> [type](#output\_type) | The instance type to use for the instance. |
| <a name="output_zzz"></a> [zzz](#output\_zzz) | The configuration of rule groups associated with the firewall. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
22 changes: 21 additions & 1 deletion modules/instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ locals {

locals {
is_t_type = replace(var.type, "/^t(2|3|3a){1}\\..*$/", "1") == "1" ? true : false
hostname_type = {
"IP_V4" = "ip-name"
"RESOURCE_NAME" = "resource-name"
}
}


Expand All @@ -32,7 +36,6 @@ locals {
#
# - `ipv6_address_count`
# - `ipv6_addresses`
# - `private_dns_name_options`
# - `network_interface`
#
# - `ephemeral_block_device`
Expand Down Expand Up @@ -73,6 +76,15 @@ resource "aws_instance" "this" {
private_ip = var.private_ip
secondary_private_ips = var.secondary_private_ips

# The options for the instance hostname. The default values are inherited from the subnet.
private_dns_name_options {
hostname_type = try(local.hostname_type[var.hostname_type], null)

# TODO: re-create on change below. bug.
enable_resource_name_dns_a_record = var.dns_resource_name_ipv4_enabled
enable_resource_name_dns_aaaa_record = var.dns_resource_name_ipv6_enabled
}


## Metadata
dynamic "metadata_options" {
Expand Down Expand Up @@ -182,6 +194,14 @@ resource "aws_spot_instance_request" "this" {
private_ip = var.private_ip
secondary_private_ips = var.secondary_private_ips

# The options for the instance hostname. The default values are inherited from the subnet.
private_dns_name_options {
hostname_type = try(local.hostname_type[var.hostname_type], null)

enable_resource_name_dns_a_record = var.dns_resource_name_ipv4_enabled
enable_resource_name_dns_aaaa_record = var.dns_resource_name_ipv6_enabled
}


## Metadata
dynamic "metadata_options" {
Expand Down
17 changes: 14 additions & 3 deletions modules/instance/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ output "network" {
`availability_zone` - The Availability Zone of the instance.
`subnet_id` - The ID of subnet of the launched instance.
`source_dest_check_enabled` - Whether the traffic is routed to the instance when the destination address does not match the 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.
`private_ip` - The private IP address assigned to the instance.
`secondary_private_ips` - A list of secondary private IPv4 addresses assigned to the instance's primary network interface.

`hostname_type` - The type of hostname for the EC2 instances.
`dns_resource_name_ipv4_enabled` - Whether to resolve the IPv4 address of the EC2 instance for requests to your resource-name based domain.
`dns_resource_name_ipv6_enabled` - Whether to resolve the IPv6 address of the EC2 instance for requests to your resource-name based domain.
EOF
value = {
availability_zone = try(aws_instance.this[0].availability_zone, aws_spot_instance_request.this[0].availability_zone)
Expand All @@ -78,6 +83,13 @@ output "network" {
private_ip = association.private_ip_address
}
}

hostname_type = {
for k, v in local.hostname_type :
v => k
}[try(aws_instance.this[0].private_dns_name_options[0].hostname_type, aws_spot_instance_request.this[0].private_dns_name_options[0].hostname_type)]
dns_resource_name_ipv4_enabled = try(aws_instance.this[0].private_dns_name_options[0].enable_resource_name_dns_a_record, aws_spot_instance_request.this[0].private_dns_name_options[0].enable_resource_name_dns_a_record)
dns_resource_name_ipv6_enabled = try(aws_instance.this[0].private_dns_name_options[0].enable_resource_name_dns_aaaa_record, aws_spot_instance_request.this[0].private_dns_name_options[0].enable_resource_name_dns_aaaa_record)
}
}

Expand Down Expand Up @@ -176,12 +188,11 @@ output "ami_snapshots" {
}
}

output "test" {
output "zzz" {
description = "The configuration of rule groups associated with the firewall."
value = {
for k, v in try(aws_instance.this[0], aws_spot_instance_request.this[0]) :
k => v
if !contains(["arn", "id", "availability_zone", "disable_api_stop", "disable_api_termination", "instance_state", "private_ip", "private_dns", "public_ip", "public_dns", "tags", "tags_all", "security_grouops", "cpu_core_count", "cpu_threads_per_core", "subnet_id", "timeouts", "credit_specification", "monitoring", "instance_initiated_shutdown_behavior", "maintenance_options", "placement_group", "placement_partition_number", "host_id", "tenancy", "key_name", "instance_type", "ami", "source_dest_check", "iam_instance_profile", "associate_public_ip_address", "ebs_optimized", "secondary_private_ips", "security_groups", "vpc_security_group_ids", "hibernation", "volume_tags", "enclave_options", "metadata_options", "launch_template"], k)
if !contains(["arn", "id", "availability_zone", "disable_api_stop", "disable_api_termination", "instance_state", "private_ip", "private_dns", "public_ip", "public_dns", "tags", "tags_all", "security_grouops", "cpu_core_count", "cpu_threads_per_core", "subnet_id", "timeouts", "credit_specification", "monitoring", "instance_initiated_shutdown_behavior", "maintenance_options", "placement_group", "placement_partition_number", "host_id", "tenancy", "key_name", "instance_type", "ami", "source_dest_check", "iam_instance_profile", "associate_public_ip_address", "ebs_optimized", "secondary_private_ips", "security_groups", "vpc_security_group_ids", "hibernation", "volume_tags", "enclave_options", "metadata_options", "launch_template", "private_dns_name_options"], k)
}

}
18 changes: 18 additions & 0 deletions modules/instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ variable "eip_associations" {
nullable = false
}

variable "hostname_type" {
description = "(Optional) The type of hostname for the EC2 instances. For IPv4 only subnets, an instance DNS name must be based on the instance IPv4 address. For IPv6 native subnets, an instance DNS name must be based on the instance ID. For dual-stack subnets, you can specify whether DNS names use the instance IPv4 address or the instance ID. Valid values are `IP_V4` and `RESOURCE_NAME`."
type = string
default = null
}

variable "dns_resource_name_ipv4_enabled" {
description = "(Optional) Whether to resolve the IPv4 address of the EC2 instance for requests to your resource-name based domain."
type = bool
default = null
}

variable "dns_resource_name_ipv6_enabled" {
description = "(Optional) Whether to resolve the IPv6 address of the EC2 instance for requests to your resource-name based domain."
type = bool
default = null
}

variable "metadata_options" {
description = <<EOF
(Optional) The configuration for metadata of the instance. `metadata_options` block as defined below.
Expand Down