Skip to content

Commit 847911b

Browse files
authored
Merge branch 'master' into root_block_device_object
2 parents 976ad60 + 6f851d8 commit 847911b

File tree

14 files changed

+98
-31
lines changed

14 files changed

+98
-31
lines changed

.github/workflows/pr-title.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
# Please look up the latest version from
1616
# https://github.com/amannn/action-semantic-pull-request/releases
17-
- uses: amannn/action-semantic-pull-request@v5.4.0
17+
- uses: amannn/action-semantic-pull-request@v5.5.3
1818
env:
1919
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2020
with:

.github/workflows/pre-commit.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
- master
88

99
env:
10-
TERRAFORM_DOCS_VERSION: v0.16.0
11-
TFLINT_VERSION: v0.50.3
10+
TERRAFORM_DOCS_VERSION: v0.19.0
11+
TFLINT_VERSION: v0.53.0
1212

1313
jobs:
1414
collectInputs:
@@ -45,14 +45,14 @@ jobs:
4545

4646
- name: Terraform min/max versions
4747
id: minMax
48-
uses: clowdhaus/terraform-min-max@v1.3.0
48+
uses: clowdhaus/terraform-min-max@v1.3.1
4949
with:
5050
directory: ${{ matrix.directory }}
5151

5252
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
5353
# Run only validate pre-commit check on min version supported
5454
if: ${{ matrix.directory != '.' }}
55-
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.9.0
55+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.11.1
5656
with:
5757
terraform-version: ${{ steps.minMax.outputs.minVersion }}
5858
tflint-version: ${{ env.TFLINT_VERSION }}
@@ -61,7 +61,7 @@ jobs:
6161
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
6262
# Run only validate pre-commit check on min version supported
6363
if: ${{ matrix.directory == '.' }}
64-
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.9.0
64+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.11.1
6565
with:
6666
terraform-version: ${{ steps.minMax.outputs.minVersion }}
6767
tflint-version: ${{ env.TFLINT_VERSION }}
@@ -88,10 +88,10 @@ jobs:
8888

8989
- name: Terraform min/max versions
9090
id: minMax
91-
uses: clowdhaus/terraform-min-max@v1.3.0
91+
uses: clowdhaus/terraform-min-max@v1.3.1
9292

9393
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
94-
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.9.0
94+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.11.1
9595
with:
9696
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
9797
tflint-version: ${{ env.TFLINT_VERSION }}

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.88.0
3+
rev: v1.96.1
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each
@@ -22,10 +22,9 @@ repos:
2222
- '--args=--only=terraform_required_providers'
2323
- '--args=--only=terraform_standard_module_structure'
2424
- '--args=--only=terraform_workspace_remote'
25-
- '--args=--only=terraform_unused_required_providers'
2625
- id: terraform_validate
2726
- repo: https://github.com/pre-commit/pre-commit-hooks
28-
rev: v4.5.0
27+
rev: v5.0.0
2928
hooks:
3029
- id: check-merge-conflict
3130
- id: end-of-file-fixer

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [5.7.1](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v5.7.0...v5.7.1) (2024-10-11)
6+
7+
8+
### Bug Fixes
9+
10+
* Update CI workflow versions to latest ([#409](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/409)) ([e48d67f](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/commit/e48d67f339c72bb44a544729fa685e347ea6256e))
11+
12+
## [5.7.0](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v5.6.1...v5.7.0) (2024-08-26)
13+
14+
15+
### Features
16+
17+
* Added parameter to attach aws_eip ([#391](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/391)) ([57cdd5d](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/commit/57cdd5d376939ec8a177c4622d3fe8c6f12c68c7))
18+
519
## [5.6.1](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/compare/v5.6.0...v5.6.1) (2024-03-07)
620

721

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ The following combinations are supported to conditionally create resources:
157157
- Changes in `ebs_block_device` argument will be ignored. Use [aws_volume_attachment](https://www.terraform.io/docs/providers/aws/r/volume_attachment.html) resource to attach and detach volumes from AWS EC2 instances. See [this example](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/volume-attachment).
158158
- In regards to spot instances, you must grant the `AWSServiceRoleForEC2Spot` service-linked role access to any custom KMS keys, otherwise your spot request and instances will fail with `bad parameters`. You can see more details about why the request failed by using the awscli and `aws ec2 describe-spot-instance-requests`
159159

160-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
160+
<!-- BEGIN_TF_DOCS -->
161161
## Requirements
162162

163163
| Name | Version |
@@ -179,6 +179,7 @@ No modules.
179179

180180
| Name | Type |
181181
|------|------|
182+
| [aws_eip.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eip) | resource |
182183
| [aws_iam_instance_profile.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource |
183184
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
184185
| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
@@ -203,12 +204,15 @@ No modules.
203204
| <a name="input_cpu_options"></a> [cpu\_options](#input\_cpu\_options) | Defines CPU options to apply to the instance at launch time. | `any` | `{}` | no |
204205
| <a name="input_cpu_threads_per_core"></a> [cpu\_threads\_per\_core](#input\_cpu\_threads\_per\_core) | Sets the number of CPU threads per core for an instance (has no effect unless cpu\_core\_count is also set) | `number` | `null` | no |
205206
| <a name="input_create"></a> [create](#input\_create) | Whether to create an instance | `bool` | `true` | no |
207+
| <a name="input_create_eip"></a> [create\_eip](#input\_create\_eip) | Determines whether a public EIP will be created and associated with the instance. | `bool` | `false` | no |
206208
| <a name="input_create_iam_instance_profile"></a> [create\_iam\_instance\_profile](#input\_create\_iam\_instance\_profile) | Determines whether an IAM instance profile is created or to use an existing IAM instance profile | `bool` | `false` | no |
207209
| <a name="input_create_spot_instance"></a> [create\_spot\_instance](#input\_create\_spot\_instance) | Depicts if the instance is a spot instance | `bool` | `false` | no |
208210
| <a name="input_disable_api_stop"></a> [disable\_api\_stop](#input\_disable\_api\_stop) | If true, enables EC2 Instance Stop Protection | `bool` | `null` | no |
209211
| <a name="input_disable_api_termination"></a> [disable\_api\_termination](#input\_disable\_api\_termination) | If true, enables EC2 Instance Termination Protection | `bool` | `null` | no |
210212
| <a name="input_ebs_block_device"></a> [ebs\_block\_device](#input\_ebs\_block\_device) | Additional EBS block devices to attach to the instance | `list(any)` | `[]` | no |
211213
| <a name="input_ebs_optimized"></a> [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `null` | no |
214+
| <a name="input_eip_domain"></a> [eip\_domain](#input\_eip\_domain) | Indicates if this EIP is for use in VPC | `string` | `"vpc"` | no |
215+
| <a name="input_eip_tags"></a> [eip\_tags](#input\_eip\_tags) | A map of additional tags to add to the eip | `map(string)` | `{}` | no |
212216
| <a name="input_enable_volume_tags"></a> [enable\_volume\_tags](#input\_enable\_volume\_tags) | Whether to enable volume tags (if enabled it conflicts with root\_block\_device tags) | `bool` | `true` | no |
213217
| <a name="input_enclave_options_enabled"></a> [enclave\_options\_enabled](#input\_enclave\_options\_enabled) | Whether Nitro Enclaves will be enabled on the instance. Defaults to `false` | `bool` | `null` | no |
214218
| <a name="input_ephemeral_block_device"></a> [ephemeral\_block\_device](#input\_ephemeral\_block\_device) | Customize Ephemeral (also known as Instance Store) volumes on the instance | `list(map(string))` | `[]` | no |
@@ -232,7 +236,7 @@ No modules.
232236
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | Key name of the Key Pair to use for the instance; which can be managed using the `aws_key_pair` resource | `string` | `null` | no |
233237
| <a name="input_launch_template"></a> [launch\_template](#input\_launch\_template) | Specifies a Launch Template to configure the instance. Parameters configured on this resource will override the corresponding parameters in the Launch Template | `map(string)` | `{}` | no |
234238
| <a name="input_maintenance_options"></a> [maintenance\_options](#input\_maintenance\_options) | The maintenance options for the instance | `any` | `{}` | no |
235-
| <a name="input_metadata_options"></a> [metadata\_options](#input\_metadata\_options) | Customize the metadata options of the instance | `map(string)` | <pre>{<br> "http_endpoint": "enabled",<br> "http_put_response_hop_limit": 1,<br> "http_tokens": "optional"<br>}</pre> | no |
239+
| <a name="input_metadata_options"></a> [metadata\_options](#input\_metadata\_options) | Customize the metadata options of the instance | `map(string)` | <pre>{<br/> "http_endpoint": "enabled",<br/> "http_put_response_hop_limit": 1,<br/> "http_tokens": "optional"<br/>}</pre> | no |
236240
| <a name="input_monitoring"></a> [monitoring](#input\_monitoring) | If true, the launched EC2 instance will have detailed monitoring enabled | `bool` | `null` | no |
237241
| <a name="input_name"></a> [name](#input\_name) | Name to be used on EC2 instance created | `string` | `""` | no |
238242
| <a name="input_network_interface"></a> [network\_interface](#input\_network\_interface) | Customize network interfaces to be attached at instance boot time | `list(map(string))` | `[]` | no |
@@ -286,13 +290,13 @@ No modules.
286290
| <a name="output_private_dns"></a> [private\_dns](#output\_private\_dns) | The private DNS name assigned to the instance. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC |
287291
| <a name="output_private_ip"></a> [private\_ip](#output\_private\_ip) | The private IP address assigned to the instance |
288292
| <a name="output_public_dns"></a> [public\_dns](#output\_public\_dns) | The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC |
289-
| <a name="output_public_ip"></a> [public\_ip](#output\_public\_ip) | The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
293+
| <a name="output_public_ip"></a> [public\_ip](#output\_public\_ip) | The public IP address assigned to the instance, if applicable. |
290294
| <a name="output_root_block_device"></a> [root\_block\_device](#output\_root\_block\_device) | Root block device information |
291295
| <a name="output_spot_bid_status"></a> [spot\_bid\_status](#output\_spot\_bid\_status) | The current bid status of the Spot Instance Request |
292296
| <a name="output_spot_instance_id"></a> [spot\_instance\_id](#output\_spot\_instance\_id) | The Instance ID (if any) that is currently fulfilling the Spot Instance request |
293297
| <a name="output_spot_request_state"></a> [spot\_request\_state](#output\_spot\_request\_state) | The current request state of the Spot Instance Request |
294298
| <a name="output_tags_all"></a> [tags\_all](#output\_tags\_all) | A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
295-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
299+
<!-- END_TF_DOCS -->
296300

297301
## Authors
298302

examples/complete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $ terraform apply
1414

1515
Note that this example may create resources which can cost money. Run `terraform destroy` when you don't need these resources.
1616

17-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
17+
<!-- BEGIN_TF_DOCS -->
1818
## Requirements
1919

2020
| Name | Version |
@@ -122,4 +122,4 @@ No inputs.
122122
| <a name="output_spot_instance_availability_zone"></a> [spot\_instance\_availability\_zone](#output\_spot\_instance\_availability\_zone) | The availability zone of the created spot instance |
123123
| <a name="output_spot_instance_id"></a> [spot\_instance\_id](#output\_spot\_instance\_id) | The Instance ID (if any) that is currently fulfilling the Spot Instance request |
124124
| <a name="output_spot_request_state"></a> [spot\_request\_state](#output\_spot\_request\_state) | The current request state of the Spot Instance Request |
125-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
125+
<!-- END_TF_DOCS -->

examples/complete/main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ module "ec2_complete" {
3232

3333
name = local.name
3434

35-
ami = data.aws_ami.amazon_linux.id
36-
instance_type = "c5.xlarge" # used to set core count below
37-
availability_zone = element(module.vpc.azs, 0)
38-
subnet_id = element(module.vpc.private_subnets, 0)
39-
vpc_security_group_ids = [module.security_group.security_group_id]
40-
placement_group = aws_placement_group.web.id
41-
associate_public_ip_address = true
42-
disable_api_stop = false
35+
ami = data.aws_ami.amazon_linux.id
36+
instance_type = "c5.xlarge" # used to set core count below
37+
availability_zone = element(module.vpc.azs, 0)
38+
subnet_id = element(module.vpc.private_subnets, 0)
39+
vpc_security_group_ids = [module.security_group.security_group_id]
40+
placement_group = aws_placement_group.web.id
41+
create_eip = true
42+
disable_api_stop = false
4343

4444
create_iam_instance_profile = true
4545
iam_role_description = "IAM role for EC2 instance"

examples/session-manager/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ You will need to have the Session Manager plugin for the AWS CLI installed to ex
2424

2525
Note that this example may create resources which can cost money. Run `terraform destroy` when you don't need these resources.
2626

27-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
27+
<!-- BEGIN_TF_DOCS -->
2828
## Requirements
2929

3030
| Name | Version |
@@ -80,4 +80,4 @@ No inputs.
8080
| <a name="output_ec2_root_block_device"></a> [ec2\_root\_block\_device](#output\_ec2\_root\_block\_device) | Root block device information |
8181
| <a name="output_ec2_tags_all"></a> [ec2\_tags\_all](#output\_ec2\_tags\_all) | A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
8282
| <a name="output_ssm_connect_command"></a> [ssm\_connect\_command](#output\_ssm\_connect\_command) | The AWS CLI command to connect to the instance using Session Manager |
83-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
83+
<!-- END_TF_DOCS -->

examples/volume-attachment/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $ terraform apply
1616

1717
Note that this example may create resources which can cost money. Run `terraform destroy` when you don't need these resources.
1818

19-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
19+
<!-- BEGIN_TF_DOCS -->
2020
## Requirements
2121

2222
| Name | Version |
@@ -65,4 +65,4 @@ No inputs.
6565
| <a name="output_ec2_public_dns"></a> [ec2\_public\_dns](#output\_ec2\_public\_dns) | The public DNS name assigned to the instance. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC |
6666
| <a name="output_ec2_public_ip"></a> [ec2\_public\_ip](#output\_ec2\_public\_ip) | The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
6767
| <a name="output_ec2_tags_all"></a> [ec2\_tags\_all](#output\_ec2\_tags\_all) | A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
68-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
68+
<!-- END_TF_DOCS -->

main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,20 @@ resource "aws_iam_instance_profile" "this" {
603603
create_before_destroy = true
604604
}
605605
}
606+
607+
################################################################################
608+
# Elastic IP
609+
################################################################################
610+
611+
resource "aws_eip" "this" {
612+
count = local.create && var.create_eip && !var.create_spot_instance ? 1 : 0
613+
614+
instance = try(
615+
aws_instance.this[0].id,
616+
aws_instance.ignore_ami[0].id,
617+
)
618+
619+
domain = var.eip_domain
620+
621+
tags = merge(var.tags, var.eip_tags)
622+
}

0 commit comments

Comments
 (0)