From 9fcea6189959ccb0b234cdf926a3948e60ca46e8 Mon Sep 17 00:00:00 2001 From: Tony Nyurkin Date: Thu, 2 Jan 2020 13:33:56 +0200 Subject: [PATCH 1/7] Add ignore changes of key_name --- README.md | 12 ++++++------ main.tf | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c3d6b5b3..ae3229d2 100644 --- a/README.md +++ b/README.md @@ -98,11 +98,11 @@ data "aws_ami" "ubuntu-xenial" { |------|-------------|:----:|:-----:|:-----:| | 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 | +| 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 | +| 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 | @@ -122,10 +122,10 @@ data "aws_ami" "ubuntu-xenial" { | 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 | +| 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 | diff --git a/main.tf b/main.tf index 077079b4..aecc3eab 100644 --- a/main.tf +++ b/main.tf @@ -93,4 +93,10 @@ resource "aws_instance" "this" { credit_specification { cpu_credits = local.is_t_instance_type ? var.cpu_credits : null } + + lifecycle { + ignore_changes = [ + key_name + ] + } } From 89a1c4bf90c939952ce472ce851e53f5ada2d0a0 Mon Sep 17 00:00:00 2001 From: Alex Vidchinkin Date: Tue, 19 May 2020 16:39:19 +0300 Subject: [PATCH 2/7] Add ignore changes of user_data --- main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index aecc3eab..dd6a7e21 100644 --- a/main.tf +++ b/main.tf @@ -96,7 +96,8 @@ resource "aws_instance" "this" { lifecycle { ignore_changes = [ - key_name + key_name, + user_data ] } } From dd80fbcf96295cebf3bbed004d0af278873206c2 Mon Sep 17 00:00:00 2001 From: Tony Nyurkin Date: Tue, 7 Jul 2020 17:17:02 +0300 Subject: [PATCH 3/7] Add ebs optimized to ignore_changes --- main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index dd6a7e21..87004482 100644 --- a/main.tf +++ b/main.tf @@ -97,7 +97,8 @@ resource "aws_instance" "this" { lifecycle { ignore_changes = [ key_name, - user_data + user_data, + ebs_optimized ] } } From 8cf45be534fbc83d57a1bc8ce703a9e7c05ed88d Mon Sep 17 00:00:00 2001 From: Alex Vidchinkin Date: Fri, 24 Dec 2021 17:31:03 +0200 Subject: [PATCH 4/7] [#179688576] Add FQDN tag for instances --- .pre-commit-config.yaml | 4 +- README.md | 132 +++++++++++++++++++++++----------------- main.tf | 3 + variables.tf | 6 ++ 4 files changed, 87 insertions(+), 58 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9729b21e..753fcbb7 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 + rev: v1.62.3 hooks: - id: terraform_fmt - id: terraform_docs - repo: git://github.com/pre-commit/pre-commit-hooks - rev: v2.4.0 + rev: v4.1.0 hooks: - id: check-merge-conflict diff --git a/README.md b/README.md index ae3229d2..8b8736b4 100644 --- a/README.md +++ b/README.md @@ -92,70 +92,90 @@ 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 | +| [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 | +| [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 87004482..af15f704 100644 --- a/main.tf +++ b/main.tf @@ -80,6 +80,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.use_num_suffix ? format(var.fqdn, count.index + 1) : var.fqdn + }, var.tags, ) diff --git a/variables.tf b/variables.tf index 3e22361f..b0f02346 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 From 79bd5850b61ce602383e94aa2d03b9fc171e1278 Mon Sep 17 00:00:00 2001 From: Alex Vidchinkin Date: Tue, 4 Jan 2022 18:35:22 +0200 Subject: [PATCH 5/7] Add format_fqdn var --- README.md | 1 + main.tf | 2 +- variables.tf | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b8736b4..7cc0e724 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ No modules. | [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 | diff --git a/main.tf b/main.tf index af15f704..97b447b8 100644 --- a/main.tf +++ b/main.tf @@ -81,7 +81,7 @@ 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.use_num_suffix ? format(var.fqdn, count.index + 1) : var.fqdn + "FQDN" = var.instance_count > 1 || var.format_fqdn ? format(var.fqdn, count.index + 1) : var.fqdn }, var.tags, ) diff --git a/variables.tf b/variables.tf index b0f02346..465c6403 100644 --- a/variables.tf +++ b/variables.tf @@ -193,3 +193,8 @@ variable "use_num_suffix" { default = false } +variable "format_fqdn" { + description = "format FQDN tag or use it as is" + type = bool + default = true +} From b82e64a9cfb918d2dabc5b03c5c81ce035580fe7 Mon Sep 17 00:00:00 2001 From: Ivan <59452689+ivanssimple@users.noreply.github.com> Date: Tue, 2 Aug 2022 09:54:30 -0700 Subject: [PATCH 6/7] [#170425434] Ignore AMI changes (#3) --- .pre-commit-config.yaml | 4 ++-- main.tf | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 753fcbb7..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 +- 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 +- repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.1.0 hooks: - id: check-merge-conflict diff --git a/main.tf b/main.tf index 97b447b8..4a2b4f6d 100644 --- a/main.tf +++ b/main.tf @@ -99,6 +99,7 @@ resource "aws_instance" "this" { lifecycle { ignore_changes = [ + ami, key_name, user_data, ebs_optimized From 91f5236336c4cc2815215802a35f4cffc11f5b79 Mon Sep 17 00:00:00 2001 From: John Madden Date: Fri, 22 Dec 2023 12:51:01 -0500 Subject: [PATCH 7/7] [#186727615] Add support, somewhat from upstream, for metadata_options --- README.md | 1 + main.tf | 10 ++++++++++ variables.tf | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 7cc0e724..0d57d5aa 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ No modules. | [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 | diff --git a/main.tf b/main.tf index 4a2b4f6d..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 diff --git a/variables.tf b/variables.tf index 465c6403..4c29fc25 100644 --- a/variables.tf +++ b/variables.tf @@ -198,3 +198,13 @@ variable "format_fqdn" { 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" + } +}