Commit ef28a16d authored by Jeremy Ciak's avatar Jeremy Ciak Committed by GitHub

feat: Add support for metadata_options argument (#193)

parent 4c8ffba6
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.31.0
rev: v1.44.0
hooks:
- id: terraform_fmt
- id: terraform_validate
- id: terraform_docs
- id: terraform_tflint
args:
- '--args=--only=terraform_deprecated_interpolation'
- '--args=--only=terraform_deprecated_index'
- '--args=--only=terraform_unused_declarations'
- '--args=--only=terraform_comment_syntax'
- '--args=--only=terraform_documented_outputs'
- '--args=--only=terraform_documented_variables'
- '--args=--only=terraform_typed_variables'
- '--args=--only=terraform_module_pinned_source'
- '--args=--only=terraform_naming_convention'
- '--args=--only=terraform_required_version'
- '--args=--only=terraform_required_providers'
- '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote'
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v3.3.0
hooks:
- id: check-merge-conflict
......@@ -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
......
......@@ -94,13 +94,16 @@ data "aws_ami" "ubuntu-xenial" {
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
No requirements.
| Name | Version |
|------|---------|
| terraform | >= 0.12.6 |
| aws | >= 2.65 |
## Providers
| Name | Version |
|------|---------|
| aws | n/a |
| aws | >= 2.65 |
## Inputs
......@@ -121,6 +124,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 | `map(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 |
......@@ -153,6 +157,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 |
......
......@@ -17,13 +17,16 @@ Note that this example may create resources which can cost money. Run `terraform
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
No requirements.
| Name | Version |
|------|---------|
| terraform | >= 0.12.6 |
| aws | >= 2.65 |
## Providers
| Name | Version |
|------|---------|
| aws | n/a |
| aws | >= 2.65 |
## Inputs
......@@ -40,6 +43,8 @@ No input.
| ids\_t2 | List of IDs of t2-type instances |
| instance\_id | EC2 instance ID |
| instance\_public\_dns | Public DNS name assigned to the EC2 instance |
| metadata\_options | Metadata options for the instance |
| metadata\_options\_custom | Customized metadata options for the instance |
| placement\_group | List of placement group |
| public\_dns | List of public DNS names assigned to the instances |
| root\_block\_device\_volume\_ids | List of volume IDs of root block devices of instances |
......
......@@ -83,7 +83,7 @@ module "ec2" {
ami = data.aws_ami.amazon_linux.id
instance_type = "c5.large"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
// private_ips = ["172.31.32.5", "172.31.46.20"]
# private_ips = ["172.31.32.5", "172.31.46.20"]
vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true
placement_group = aws_placement_group.web.id
......@@ -123,7 +123,7 @@ module "ec2_with_t2_unlimited" {
instance_type = "t2.micro"
cpu_credits = "unlimited"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
// private_ip = "172.31.32.10"
# private_ip = "172.31.32.10"
vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true
}
......@@ -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 = "t2.small"
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 = "../../"
......
......@@ -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
}
terraform {
required_version = ">= 0.12.6"
required_providers {
aws = ">= 2.65"
}
}
......@@ -21,19 +21,22 @@ Note that this example may create resources which can cost money. Run `terraform
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
No requirements.
| Name | Version |
|------|---------|
| terraform | >= 0.12.6 |
| aws | >= 2.65 |
## Providers
| Name | Version |
|------|---------|
| aws | n/a |
| aws | >= 2.65 |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| instances\_number | n/a | `number` | `1` | no |
| instances\_number | NUmber of instances | `number` | `1` | no |
## Outputs
......
......@@ -2,10 +2,6 @@ provider "aws" {
region = "eu-west-1"
}
variable "instances_number" {
default = 1
}
##################################################################
# Data sources to get VPC, subnet, security group and AMI details
##################################################################
......
variable "instances_number" {
description = "NUmber of instances"
type = number
default = 1
}
terraform {
required_version = ">= 0.12.6"
required_providers {
aws = ">= 2.65"
}
}
......@@ -61,6 +61,15 @@ resource "aws_instance" "this" {
}
}
dynamic "metadata_options" {
for_each = length(keys(var.metadata_options)) == 0 ? [] : [var.metadata_options]
content {
http_endpoint = lookup(metadata_options.value, "http_endpoint", "enabled")
http_tokens = lookup(metadata_options.value, "http_tokens", "optional")
http_put_response_hop_limit = lookup(metadata_options.value, "http_put_response_hop_limit", "1")
}
}
dynamic "network_interface" {
for_each = var.network_interface
content {
......
......@@ -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
......
......@@ -181,6 +181,12 @@ variable "cpu_credits" {
default = "standard"
}
variable "metadata_options" {
description = "Customize the metadata options of the instance"
type = map(string)
default = {}
}
variable "use_num_suffix" {
description = "Always append numerical suffix to instance name, even if instance_count is 1"
type = bool
......@@ -192,5 +198,3 @@ variable "num_suffix_format" {
type = string
default = "-%d"
}
terraform {
required_version = ">= 0.12.6"
required_providers {
aws = ">= 2.65"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment