diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9729b21e..d041b782 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ repos: -- repo: git://github.com/antonbabenko/pre-commit-terraform - rev: v1.21.0 +- repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.62.3 hooks: - id: terraform_fmt - id: terraform_docs -- repo: git://github.com/pre-commit/pre-commit-hooks - rev: v2.4.0 +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 hooks: - id: check-merge-conflict diff --git a/README.md b/README.md index c3d6b5b3..0d57d5aa 100644 --- a/README.md +++ b/README.md @@ -92,70 +92,92 @@ data "aws_ami" "ubuntu-xenial" { * One of `subnet_id` or `subnet_ids` is required. If both are provided, the value of `subnet_id` is prepended to the value of `subnet_ids`. +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [aws_instance.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance) | resource | + ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|:----:|:-----:|:-----:| -| ami | ID of AMI to use for the instance | string | n/a | yes | -| associate\_public\_ip\_address | If true, the EC2 instance will have associated public IP address | bool | `"null"` | no | -| cpu\_credits | The credit option for CPU usage (unlimited or standard) | string | `"standard"` | no | -| disable\_api\_termination | If true, enables EC2 Instance Termination Protection | bool | `"false"` | no | -| ebs\_block\_device | Additional EBS block devices to attach to the instance | list(map(string)) | `[]` | no | -| ebs\_optimized | If true, the launched EC2 instance will be EBS-optimized | bool | `"false"` | no | -| ephemeral\_block\_device | Customize Ephemeral (also known as Instance Store) volumes on the instance | list(map(string)) | `[]` | no | -| get\_password\_data | If true, wait for password data to become available and retrieve it. | bool | `"false"` | no | -| iam\_instance\_profile | The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile. | string | `""` | no | -| instance\_count | Number of instances to launch | number | `"1"` | no | -| instance\_initiated\_shutdown\_behavior | Shutdown behavior for the instance | string | `""` | no | -| instance\_type | The type of instance to start | string | n/a | yes | -| ipv6\_address\_count | A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet. | number | `"null"` | no | -| ipv6\_addresses | Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface | list(string) | `"null"` | no | -| key\_name | The key name to use for the instance | string | `""` | no | -| monitoring | If true, the launched EC2 instance will have detailed monitoring enabled | bool | `"false"` | no | -| name | Name to be used on all resources as prefix | string | n/a | yes | -| network\_interface | Customize network interfaces to be attached at instance boot time | list(map(string)) | `[]` | no | -| placement\_group | The Placement Group to start the instance in | string | `""` | no | -| private\_ip | Private IP address to associate with the instance in a VPC | string | `"null"` | no | -| private\_ips | A list of private IP address to associate with the instance in a VPC. Should match the number of instances. | list(string) | `[]` | no | -| root\_block\_device | Customize details about the root block device of the instance. See Block Devices below for details | list(map(string)) | `[]` | no | -| 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 | -| subnet\_id | The VPC Subnet ID to launch in | string | `""` | no | -| subnet\_ids | A list of VPC Subnet IDs to launch in | list(string) | `[]` | no | -| tags | A mapping of tags to assign to the resource | map(string) | `{}` | no | -| tenancy | The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host. | string | `"default"` | no | -| use\_num\_suffix | Always append numerical suffix to instance name, even if instance_count is 1 | bool | `"false"` | no | -| user\_data | The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument; see user_data_base64 instead. | string | `"null"` | no | -| user\_data\_base64 | Can be used instead of user_data to pass base64-encoded binary data directly. Use this instead of user_data whenever the value is not a valid UTF-8 string. For example, gzip-encoded user data must be base64-encoded and passed via this argument to avoid corruption. | string | `"null"` | no | -| volume\_tags | A mapping of tags to assign to the devices created by the instance at launch time | map(string) | `{}` | no | -| vpc\_security\_group\_ids | A list of security group IDs to associate with | list(string) | `"null"` | no | +|------|-------------|------|---------|:--------:| +| [ami](#input\_ami) | ID of AMI to use for the instance | `string` | n/a | yes | +| [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | If true, the EC2 instance will have associated public IP address | `bool` | `null` | no | +| [cpu\_credits](#input\_cpu\_credits) | The credit option for CPU usage (unlimited or standard) | `string` | `"standard"` | no | +| [disable\_api\_termination](#input\_disable\_api\_termination) | If true, enables EC2 Instance Termination Protection | `bool` | `false` | no | +| [ebs\_block\_device](#input\_ebs\_block\_device) | Additional EBS block devices to attach to the instance | `list(map(string))` | `[]` | no | +| [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `false` | no | +| [ephemeral\_block\_device](#input\_ephemeral\_block\_device) | Customize Ephemeral (also known as Instance Store) volumes on the instance | `list(map(string))` | `[]` | no | +| [format\_fqdn](#input\_format\_fqdn) | format FQDN tag or use it as is | `bool` | `true` | no | +| [fqdn](#input\_fqdn) | Value for FQDN instance tag with fully qualified domain name | `string` | `""` | no | +| [get\_password\_data](#input\_get\_password\_data) | If true, wait for password data to become available and retrieve it. | `bool` | `false` | no | +| [iam\_instance\_profile](#input\_iam\_instance\_profile) | The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile. | `string` | `""` | no | +| [instance\_count](#input\_instance\_count) | Number of instances to launch | `number` | `1` | no | +| [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Shutdown behavior for the instance | `string` | `""` | no | +| [instance\_type](#input\_instance\_type) | The type of instance to start | `string` | n/a | yes | +| [ipv6\_address\_count](#input\_ipv6\_address\_count) | A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet. | `number` | `null` | no | +| [ipv6\_addresses](#input\_ipv6\_addresses) | Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface | `list(string)` | `null` | no | +| [key\_name](#input\_key\_name) | The key name to use for the instance | `string` | `""` | no | +| [metadata\_options](#input\_metadata\_options) | Customize the metadata options of the instance | `map(string)` |
{
"http_endpoint": "enabled",
"http_put_response_hop_limit": 1,
"http_tokens": "optional"
}
| no | +| [monitoring](#input\_monitoring) | If true, the launched EC2 instance will have detailed monitoring enabled | `bool` | `false` | no | +| [name](#input\_name) | Name to be used on all resources as prefix | `string` | n/a | yes | +| [network\_interface](#input\_network\_interface) | Customize network interfaces to be attached at instance boot time | `list(map(string))` | `[]` | no | +| [placement\_group](#input\_placement\_group) | The Placement Group to start the instance in | `string` | `""` | no | +| [private\_ip](#input\_private\_ip) | Private IP address to associate with the instance in a VPC | `string` | `null` | no | +| [private\_ips](#input\_private\_ips) | A list of private IP address to associate with the instance in a VPC. Should match the number of instances. | `list(string)` | `[]` | no | +| [root\_block\_device](#input\_root\_block\_device) | Customize details about the root block device of the instance. See Block Devices below for details | `list(map(string))` | `[]` | no | +| [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 | +| [subnet\_id](#input\_subnet\_id) | The VPC Subnet ID to launch in | `string` | `""` | no | +| [subnet\_ids](#input\_subnet\_ids) | A list of VPC Subnet IDs to launch in | `list(string)` | `[]` | no | +| [tags](#input\_tags) | A mapping of tags to assign to the resource | `map(string)` | `{}` | no | +| [tenancy](#input\_tenancy) | The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host. | `string` | `"default"` | no | +| [use\_num\_suffix](#input\_use\_num\_suffix) | Always append numerical suffix to instance name, even if instance\_count is 1 | `bool` | `false` | no | +| [user\_data](#input\_user\_data) | The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument; see user\_data\_base64 instead. | `string` | `null` | no | +| [user\_data\_base64](#input\_user\_data\_base64) | Can be used instead of user\_data to pass base64-encoded binary data directly. Use this instead of user\_data whenever the value is not a valid UTF-8 string. For example, gzip-encoded user data must be base64-encoded and passed via this argument to avoid corruption. | `string` | `null` | no | +| [volume\_tags](#input\_volume\_tags) | A mapping of tags to assign to the devices created by the instance at launch time | `map(string)` | `{}` | no | +| [vpc\_security\_group\_ids](#input\_vpc\_security\_group\_ids) | A list of security group IDs to associate with | `list(string)` | `null` | no | ## Outputs | Name | Description | |------|-------------| -| arn | List of ARNs of instances | -| availability\_zone | List of availability zones of instances | -| credit\_specification | List of credit specification of instances | -| ebs\_block\_device\_volume\_ids | List of volume IDs of EBS block devices of instances | -| id | List of IDs of instances | -| instance\_count | Number of instances to launch specified as argument to this module | -| instance\_state | List of instance states of instances | -| ipv6\_addresses | List of assigned IPv6 addresses of instances | -| key\_name | List of key names of instances | -| password\_data | List of Base-64 encoded encrypted password data for the instance | -| placement\_group | List of placement groups of instances | -| primary\_network\_interface\_id | List of IDs of the primary network interface of instances | -| private\_dns | 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 | -| private\_ip | List of private IP addresses assigned to the instances | -| public\_dns | 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 | -| public\_ip | List of public IP addresses assigned to the instances, if applicable | -| root\_block\_device\_volume\_ids | List of volume IDs of root block devices of instances | -| security\_groups | List of associated security groups of instances | -| subnet\_id | List of IDs of VPC subnets of instances | -| tags | List of tags of instances | -| volume\_tags | List of tags of volumes of instances | -| vpc\_security\_group\_ids | List of associated security groups of instances, if running in non-default VPC | - +| [arn](#output\_arn) | List of ARNs of instances | +| [availability\_zone](#output\_availability\_zone) | List of availability zones of instances | +| [credit\_specification](#output\_credit\_specification) | List of credit specification of instances | +| [ebs\_block\_device\_volume\_ids](#output\_ebs\_block\_device\_volume\_ids) | List of volume IDs of EBS block devices of instances | +| [id](#output\_id) | List of IDs of instances | +| [instance\_count](#output\_instance\_count) | Number of instances to launch specified as argument to this module | +| [instance\_state](#output\_instance\_state) | List of instance states of instances | +| [ipv6\_addresses](#output\_ipv6\_addresses) | List of assigned IPv6 addresses of instances | +| [key\_name](#output\_key\_name) | List of key names of instances | +| [password\_data](#output\_password\_data) | List of Base-64 encoded encrypted password data for the instance | +| [placement\_group](#output\_placement\_group) | List of placement groups of instances | +| [primary\_network\_interface\_id](#output\_primary\_network\_interface\_id) | List of IDs of the primary network interface of instances | +| [private\_dns](#output\_private\_dns) | 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 | +| [private\_ip](#output\_private\_ip) | List of private IP addresses assigned to the instances | +| [public\_dns](#output\_public\_dns) | 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 | +| [public\_ip](#output\_public\_ip) | List of public IP addresses assigned to the instances, if applicable | +| [root\_block\_device\_volume\_ids](#output\_root\_block\_device\_volume\_ids) | List of volume IDs of root block devices of instances | +| [security\_groups](#output\_security\_groups) | List of associated security groups of instances | +| [subnet\_id](#output\_subnet\_id) | List of IDs of VPC subnets of instances | +| [tags](#output\_tags) | List of tags of instances | +| [volume\_tags](#output\_volume\_tags) | List of tags of volumes of instances | +| [vpc\_security\_group\_ids](#output\_vpc\_security\_group\_ids) | List of associated security groups of instances, if running in non-default VPC | ## Authors diff --git a/main.tf b/main.tf index 077079b4..d1e7f411 100644 --- a/main.tf +++ b/main.tf @@ -70,6 +70,16 @@ resource "aws_instance" "this" { } } + dynamic "metadata_options" { + for_each = length(var.metadata_options) > 0 ? [var.metadata_options] : [] + + content { + http_endpoint = try(metadata_options.value.http_endpoint, "enabled") + http_tokens = try(metadata_options.value.http_tokens, "optional") + http_put_response_hop_limit = try(metadata_options.value.http_put_response_hop_limit, 1) + } + } + source_dest_check = length(var.network_interface) > 0 ? null : var.source_dest_check disable_api_termination = var.disable_api_termination instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior @@ -80,6 +90,9 @@ resource "aws_instance" "this" { { "Name" = var.instance_count > 1 || var.use_num_suffix ? format("%s-%d", var.name, count.index + 1) : var.name }, + { + "FQDN" = var.instance_count > 1 || var.format_fqdn ? format(var.fqdn, count.index + 1) : var.fqdn + }, var.tags, ) @@ -93,4 +106,13 @@ resource "aws_instance" "this" { credit_specification { cpu_credits = local.is_t_instance_type ? var.cpu_credits : null } + + lifecycle { + ignore_changes = [ + ami, + key_name, + user_data, + ebs_optimized + ] + } } diff --git a/variables.tf b/variables.tf index 3e22361f..4c29fc25 100644 --- a/variables.tf +++ b/variables.tf @@ -3,6 +3,12 @@ variable "name" { type = string } +variable "fqdn" { + description = "Value for FQDN instance tag with fully qualified domain name" + type = string + default = "" +} + variable "instance_count" { description = "Number of instances to launch" type = number @@ -187,3 +193,18 @@ variable "use_num_suffix" { default = false } +variable "format_fqdn" { + description = "format FQDN tag or use it as is" + type = bool + default = true +} + +variable "metadata_options" { + description = "Customize the metadata options of the instance" + type = map(string) + default = { + "http_endpoint" = "enabled" + "http_put_response_hop_limit" = 1 + "http_tokens" = "optional" + } +}