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

Adding external ENIs #159

Merged
merged 36 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b80b193
Adding external ENIs
jamengual May 30, 2023
7694d19
Adding docs
jamengual May 31, 2023
c76b5f4
Updating examples modules
jamengual May 31, 2023
48e59e4
adding new example and fixing vars
jamengual May 31, 2023
5879ed5
Update examples/external-eni/main.tf
jamengual May 31, 2023
8ee1427
Update examples/external-eni/main.tf
jamengual May 31, 2023
857eea7
Update examples/external-eni/main.tf
jamengual May 31, 2023
8b8510b
Update examples/external-eni/main.tf
jamengual May 31, 2023
3f4f66c
Update examples/external-eni/main.tf
jamengual May 31, 2023
c794194
Update examples/external-eni/main.tf
jamengual May 31, 2023
456fdcc
Update examples/external-eni/main.tf
jamengual May 31, 2023
23b367f
fmt
jamengual May 31, 2023
0ae66a4
reade
jamengual May 31, 2023
189bda6
tflint fixes
jamengual May 31, 2023
73c0210
tflint fixes
jamengual May 31, 2023
95e131b
precommit/terraform
max-lobur May 31, 2023
bec6730
Fixing complete example
jamengual May 31, 2023
ce9a432
Update examples/complete/main.tf
jamengual May 31, 2023
e1b50ff
Fixing complete example
jamengual May 31, 2023
aa2d69a
Merge branch 'add_external_eni' of github.com:cloudposse/terraform-aw…
jamengual May 31, 2023
144ac1e
Update readme
jamengual Jun 2, 2023
dbbf36d
Update to bridcrew rules
jamengual Jun 2, 2023
d28fb05
Update to bridcrew rules
jamengual Jun 2, 2023
25f5e6f
Update to bridcrew rules
jamengual Jun 2, 2023
e4b09fd
Update to bridcrew rules
jamengual Jun 2, 2023
ba91b96
Update to bridgecrew rules
jamengual Jun 2, 2023
6903584
Update outputs.tf
jamengual Jun 6, 2023
d3d1231
Addresing feedback and adding new test to run
jamengual Jun 6, 2023
303eb1c
Addresing feedback and adding new test to run
jamengual Jun 6, 2023
ec9a6a4
Addresing feedback and adding new test to run
jamengual Jun 6, 2023
ea6d3b5
fixing tests
jamengual Jun 6, 2023
9d46c45
fixing tests
jamengual Jun 6, 2023
a60001a
addressing feedback
jamengual Jun 6, 2023
eed46b1
Update outputs.tf
jamengual Jun 6, 2023
09c4f0e
addressing feedback
jamengual Jun 6, 2023
50818e9
Merge branch 'add_external_eni' of github.com:cloudposse/terraform-aw…
jamengual Jun 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -280,6 +280,7 @@ Available targets:
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_evaluation_periods"></a> [evaluation\_periods](#input\_evaluation\_periods) | The number of periods over which data is compared to the specified threshold. | `number` | `5` | no |
| <a name="input_external_network_interface_enabled"></a> [external\_network\_interface\_enabled](#input\_external\_network\_interface\_enabled) | Wheter to attach an external ENI as the eth0 interface for the instance. Any change to the interface will force instance recreation. | `bool` | `false` | no |
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
| <a name="input_instance_initiated_shutdown_behavior"></a> [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Specifies whether an instance stops or terminates when you initiate shutdown from the instance. Can be one of 'stop' or 'terminate'. | `string` | `null` | no |
| <a name="input_instance_profile"></a> [instance\_profile](#input\_instance\_profile) | A pre-defined profile to attach to the instance (default is to build our own) | `string` | `""` | no |
Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Expand Up @@ -83,6 +83,7 @@
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_evaluation_periods"></a> [evaluation\_periods](#input\_evaluation\_periods) | The number of periods over which data is compared to the specified threshold. | `number` | `5` | no |
| <a name="input_external_network_interface_enabled"></a> [external\_network\_interface\_enabled](#input\_external\_network\_interface\_enabled) | Wheter to attach an external ENI as the eth0 interface for the instance. Any change to the interface will force instance recreation. | `bool` | `false` | no |
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
| <a name="input_instance_initiated_shutdown_behavior"></a> [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Specifies whether an instance stops or terminates when you initiate shutdown from the instance. Can be one of 'stop' or 'terminate'. | `string` | `null` | no |
| <a name="input_instance_profile"></a> [instance\_profile](#input\_instance\_profile) | A pre-defined profile to attach to the instance (default is to build our own) | `string` | `""` | no |
Expand Down
16 changes: 13 additions & 3 deletions main.tf
Expand Up @@ -123,9 +123,9 @@ resource "aws_instance" "default" {
user_data_base64 = var.user_data_base64
iam_instance_profile = local.instance_profile
instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
associate_public_ip_address = var.associate_public_ip_address
associate_public_ip_address = var.external_network_interface_enabled ? null : var.associate_public_ip_address
aknysh marked this conversation as resolved.
Show resolved Hide resolved
aknysh marked this conversation as resolved.
Show resolved Hide resolved
jamengual marked this conversation as resolved.
Show resolved Hide resolved
key_name = var.ssh_key_pair
subnet_id = var.subnet
subnet_id = var.external_network_interface_enabled ? null : var.subnet
monitoring = var.monitoring
private_ip = var.private_ip
secondary_private_ips = var.secondary_private_ips
Expand All @@ -134,13 +134,23 @@ resource "aws_instance" "default" {
ipv6_addresses = length(var.ipv6_addresses) == 0 ? null : var.ipv6_addresses
tenancy = var.tenancy

vpc_security_group_ids = compact(
vpc_security_group_ids = var.external_network_interface_enabled ? null : compact(
concat(
formatlist("%s", module.security_group.id),
var.security_groups
)
)

dynamic "network_interface" {
for_each = var.external_network_interface_enabled ? var.external_network_interfaces : []
content {
delete_on_termination = each.key.delete_on_termination ? each.key.delete_on_termination : false
device_index = each.key.device_index != 0 ? each.key.device_index : 0
network_card_index = each.key.network_card_index != 0 ? each.key.network_card_index : 0
network_interface_id = each.key.network_interface_id
}

}
root_block_device {
volume_type = local.root_volume_type
volume_size = var.root_volume_size
Expand Down
17 changes: 17 additions & 0 deletions variables.tf
Expand Up @@ -384,3 +384,20 @@ variable "tenancy" {
error_message = "Tenancy field can only be one of default, dedicated, host."
}
}

variable "external_network_interface_enabled" {
type = bool
default = false
description = "Wheter to attach an external ENI as the eth0 interface for the instance. Any change to the interface will force instance recreation."
}

variable "external_network_interfaces" {
type = object({
delete_on_termination = bool
device_index = number
network_card_index = number
network_interface_id = string
})
description = "The external interface definitions to attach to the instances. This depends on the instance type"
default = null
}