Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for "metadata_options" argument #193

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
<a name="unreleased"></a>
## [Unreleased]


- feat: Add support for "metadata_options" argument ([#191](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/191))

<a name="v2.15.0"></a>
## [v2.15.0] - 2020-06-10
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ No requirements.
| 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 |
| metadata\_options | Customize the metadata options of the instance | <code>object({<br>&nbsp;&nbsp;http_endpoint = string<br>&nbsp;&nbsp;http_tokens = string<br>&nbsp;&nbsp;http_put_response_hop_limit = number<br>})</code> | <code>{<br>&nbsp;&nbsp;http_endpoint = "enabled"<br>&nbsp;&nbsp;http_tokens = "optional"<br>&nbsp;&nbsp;http_put_response_hop_limit = 1<br>}</code> | 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 |
Expand Down Expand Up @@ -153,6 +154,7 @@ No requirements.
| 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 |
| metadata_options | List of metadata options 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 |
Expand Down
19 changes: 19 additions & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ module "ec2_with_t3_unlimited" {
associate_public_ip_address = true
}

module "ec2_with_metadata_options" {
source = "../../"

instance_count = 1

name = "example-metadata_options"
ami = data.aws_ami.amazon_linux.id
instance_type = "c5.large"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true

metadata_options = {
http_endpoint = "enabled"
http_tokens = "required"
http_put_response_hop_limit = 8
}
}

module "ec2_with_network_interface" {
source = "../../"

Expand Down
9 changes: 9 additions & 0 deletions examples/basic/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ output "credit_specification_t2_unlimited" {
value = module.ec2_with_t2_unlimited.credit_specification
}

output "metadata_options" {
description = "Metadata options for the instance"
value = module.ec2.metadata_options
}

output "metadata_options_custom" {
description = "Customized metadata options for the instance"
value = module.ec2_with_metadata_options.metadata_options
}
6 changes: 6 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ resource "aws_instance" "this" {
}
}

metadata_options {
http_endpoint = var.metadata_options["http_endpoint"]
http_tokens = var.metadata_options["http_tokens"]
http_put_response_hop_limit = var.metadata_options["http_put_response_hop_limit"]
}

dynamic "network_interface" {
for_each = var.network_interface
content {
Expand Down
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ output "credit_specification" {
value = aws_instance.this.*.credit_specification
}

output "metadata_options" {
description = "List of metadata options of instances"
value = aws_instance.this.*.metadata_options
}

output "instance_state" {
description = "List of instance states of instances"
value = aws_instance.this.*.instance_state
Expand Down
16 changes: 14 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ variable "cpu_credits" {
default = "standard"
}

variable "metadata_options" {
description = "Customize the metadata options of the instance"
type = object({
http_endpoint = string
http_tokens = string
http_put_response_hop_limit = number
})
default = {
http_endpoint = "enabled"
http_tokens = "optional"
http_put_response_hop_limit = 1
}
}

variable "use_num_suffix" {
description = "Always append numerical suffix to instance name, even if instance_count is 1"
type = bool
Expand All @@ -192,5 +206,3 @@ variable "num_suffix_format" {
type = string
default = "-%d"
}