Skip to content

Commit ef28a16

Browse files
authored
feat: Add support for metadata_options argument (#193)
1 parent 4c8ffba commit ef28a16

File tree

16 files changed

+115
-18
lines changed

16 files changed

+115
-18
lines changed

.pre-commit-config.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.31.0
3+
rev: v1.44.0
44
hooks:
55
- id: terraform_fmt
6+
- id: terraform_validate
67
- id: terraform_docs
8+
- id: terraform_tflint
9+
args:
10+
- '--args=--only=terraform_deprecated_interpolation'
11+
- '--args=--only=terraform_deprecated_index'
12+
- '--args=--only=terraform_unused_declarations'
13+
- '--args=--only=terraform_comment_syntax'
14+
- '--args=--only=terraform_documented_outputs'
15+
- '--args=--only=terraform_documented_variables'
16+
- '--args=--only=terraform_typed_variables'
17+
- '--args=--only=terraform_module_pinned_source'
18+
- '--args=--only=terraform_naming_convention'
19+
- '--args=--only=terraform_required_version'
20+
- '--args=--only=terraform_required_providers'
21+
- '--args=--only=terraform_standard_module_structure'
22+
- '--args=--only=terraform_workspace_remote'
723
- repo: git://github.com/pre-commit/pre-commit-hooks
8-
rev: v3.1.0
24+
rev: v3.3.0
925
hooks:
1026
- id: check-merge-conflict

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
<a name="unreleased"></a>
66
## [Unreleased]
77

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

1010
<a name="v2.15.0"></a>
1111
## [v2.15.0] - 2020-06-10

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,16 @@ data "aws_ami" "ubuntu-xenial" {
9494
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
9595
## Requirements
9696

97-
No requirements.
97+
| Name | Version |
98+
|------|---------|
99+
| terraform | >= 0.12.6 |
100+
| aws | >= 2.65 |
98101

99102
## Providers
100103

101104
| Name | Version |
102105
|------|---------|
103-
| aws | n/a |
106+
| aws | >= 2.65 |
104107

105108
## Inputs
106109

@@ -121,6 +124,7 @@ No requirements.
121124
| 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 |
122125
| 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 |
123126
| key\_name | The key name to use for the instance | `string` | `""` | no |
127+
| metadata\_options | Customize the metadata options of the instance | `map(string)` | `{}` | no |
124128
| monitoring | If true, the launched EC2 instance will have detailed monitoring enabled | `bool` | `false` | no |
125129
| name | Name to be used on all resources as prefix | `string` | n/a | yes |
126130
| network\_interface | Customize network interfaces to be attached at instance boot time | `list(map(string))` | `[]` | no |
@@ -153,6 +157,7 @@ No requirements.
153157
| instance\_state | List of instance states of instances |
154158
| ipv6\_addresses | List of assigned IPv6 addresses of instances |
155159
| key\_name | List of key names of instances |
160+
| metadata\_options | List of metadata options of instances |
156161
| password\_data | List of Base-64 encoded encrypted password data for the instance |
157162
| placement\_group | List of placement groups of instances |
158163
| primary\_network\_interface\_id | List of IDs of the primary network interface of instances |

examples/basic/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ Note that this example may create resources which can cost money. Run `terraform
1717
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1818
## Requirements
1919

20-
No requirements.
20+
| Name | Version |
21+
|------|---------|
22+
| terraform | >= 0.12.6 |
23+
| aws | >= 2.65 |
2124

2225
## Providers
2326

2427
| Name | Version |
2528
|------|---------|
26-
| aws | n/a |
29+
| aws | >= 2.65 |
2730

2831
## Inputs
2932

@@ -40,6 +43,8 @@ No input.
4043
| ids\_t2 | List of IDs of t2-type instances |
4144
| instance\_id | EC2 instance ID |
4245
| instance\_public\_dns | Public DNS name assigned to the EC2 instance |
46+
| metadata\_options | Metadata options for the instance |
47+
| metadata\_options\_custom | Customized metadata options for the instance |
4348
| placement\_group | List of placement group |
4449
| public\_dns | List of public DNS names assigned to the instances |
4550
| root\_block\_device\_volume\_ids | List of volume IDs of root block devices of instances |

examples/basic/main.tf

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module "ec2" {
8383
ami = data.aws_ami.amazon_linux.id
8484
instance_type = "c5.large"
8585
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
86-
// private_ips = ["172.31.32.5", "172.31.46.20"]
86+
# private_ips = ["172.31.32.5", "172.31.46.20"]
8787
vpc_security_group_ids = [module.security_group.this_security_group_id]
8888
associate_public_ip_address = true
8989
placement_group = aws_placement_group.web.id
@@ -123,7 +123,7 @@ module "ec2_with_t2_unlimited" {
123123
instance_type = "t2.micro"
124124
cpu_credits = "unlimited"
125125
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
126-
// private_ip = "172.31.32.10"
126+
# private_ip = "172.31.32.10"
127127
vpc_security_group_ids = [module.security_group.this_security_group_id]
128128
associate_public_ip_address = true
129129
}
@@ -142,6 +142,25 @@ module "ec2_with_t3_unlimited" {
142142
associate_public_ip_address = true
143143
}
144144

145+
module "ec2_with_metadata_options" {
146+
source = "../../"
147+
148+
instance_count = 1
149+
150+
name = "example-metadata_options"
151+
ami = data.aws_ami.amazon_linux.id
152+
instance_type = "t2.small"
153+
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
154+
vpc_security_group_ids = [module.security_group.this_security_group_id]
155+
associate_public_ip_address = true
156+
157+
metadata_options = {
158+
http_endpoint = "enabled"
159+
http_tokens = "required"
160+
http_put_response_hop_limit = 8
161+
}
162+
}
163+
145164
module "ec2_with_network_interface" {
146165
source = "../../"
147166

examples/basic/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ output "credit_specification_t2_unlimited" {
6363
value = module.ec2_with_t2_unlimited.credit_specification
6464
}
6565

66+
output "metadata_options" {
67+
description = "Metadata options for the instance"
68+
value = module.ec2.metadata_options
69+
}
70+
71+
output "metadata_options_custom" {
72+
description = "Customized metadata options for the instance"
73+
value = module.ec2_with_metadata_options.metadata_options
74+
}

examples/basic/variables.tf

Whitespace-only changes.

examples/basic/versions.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
terraform {
2+
required_version = ">= 0.12.6"
3+
4+
required_providers {
5+
aws = ">= 2.65"
6+
}
7+
}

examples/volume-attachment/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@ Note that this example may create resources which can cost money. Run `terraform
2121
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2222
## Requirements
2323

24-
No requirements.
24+
| Name | Version |
25+
|------|---------|
26+
| terraform | >= 0.12.6 |
27+
| aws | >= 2.65 |
2528

2629
## Providers
2730

2831
| Name | Version |
2932
|------|---------|
30-
| aws | n/a |
33+
| aws | >= 2.65 |
3134

3235
## Inputs
3336

3437
| Name | Description | Type | Default | Required |
3538
|------|-------------|------|---------|:--------:|
36-
| instances\_number | n/a | `number` | `1` | no |
39+
| instances\_number | NUmber of instances | `number` | `1` | no |
3740

3841
## Outputs
3942

examples/volume-attachment/main.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ provider "aws" {
22
region = "eu-west-1"
33
}
44

5-
variable "instances_number" {
6-
default = 1
7-
}
8-
95
##################################################################
106
# Data sources to get VPC, subnet, security group and AMI details
117
##################################################################

0 commit comments

Comments
 (0)