diff --git a/README.md b/README.md index 4ccb2f4..d5f2fda 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,14 @@ Move "module.nat.aws_eip.this" to "aws_eip.nat" Successfully moved 1 object(s). ``` +## Changes for latest version 3.0.0 + +Default is on-demand and not a spot instance. Also instance type is default t4g.nano to change this you need to add + + +instance_types = ["t3.nano"] + +architecture = ["x86_64"] ## Contributions @@ -163,22 +171,22 @@ No requirements. ## Inputs -| Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| -| [enabled](#input\_enabled) | Enable or not costly resources | `bool` | `true` | no | -| [image\_id](#input\_image\_id) | AMI of the NAT instance. Default to the latest Amazon Linux 2 | `string` | `""` | no | -| [instance\_types](#input\_instance\_types) | Candidates of spot instance type for the NAT instance. This is used in the mixed instances policy | `list(string)` |
[| no | -| [key\_name](#input\_key\_name) | Name of the key pair for the NAT instance. You can set this to assign the key pair to the NAT instance | `string` | `""` | no | -| [name](#input\_name) | Name for all the resources as identifier | `string` | n/a | yes | -| [private\_route\_table\_ids](#input\_private\_route\_table\_ids) | List of ID of the route tables for the private subnets. You can set this to assign the each default route to the NAT instance | `list(string)` | `[]` | no | -| [private\_subnets\_cidr\_blocks](#input\_private\_subnets\_cidr\_blocks) | List of CIDR blocks of the private subnets. The NAT instance accepts connections from this subnets | `list(string)` | n/a | yes | -| [public\_subnet](#input\_public\_subnet) | ID of the public subnet to place the NAT instance | `string` | n/a | yes | -| [ssm\_policy\_arn](#input\_ssm\_policy\_arn) | SSM Policy to be attached to instance profile | `string` | `"arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"` | no | -| [tags](#input\_tags) | Tags applied to resources created with this module | `map(string)` | `{}` | no | -| [use\_spot\_instance](#input\_use\_spot\_instance) | Whether to use spot or on-demand EC2 instance | `bool` | `true` | no | -| [user\_data\_runcmd](#input\_user\_data\_runcmd) | Additional runcmd section of cloud-init | `list(list(string))` | `[]` | no | -| [user\_data\_write\_files](#input\_user\_data\_write\_files) | Additional write\_files section of cloud-init | `list(any)` | `[]` | no | -| [vpc\_id](#input\_vpc\_id) | ID of the VPC | `string` | n/a | yes | +| Name | Description | Type | Default | Required | +|------|-------------------------------------------------------------------------------------------------------------------------------|------|----------------------------------------------------------|:--------:| +| [enabled](#input\_enabled) | This variable is for enabling auto scaling desired capacity and minimum size in the auto scaling group. | `bool` | `true` | no | +| [image\_id](#input\_image\_id) | AMI of the NAT instance. Default to the latest Amazon Linux 2 | `string` | `""` | no | +| [instance\_types](#input\_instance\_types) | Candidates of spot instance type for the NAT instance. This is used in the mixed instances policy | `list(string)` |
"t3.nano",
"t3a.nano"
]
[| no | +| [key\_name](#input\_key\_name) | Name of the key pair for the NAT instance. You can set this to assign the key pair to the NAT instance | `string` | `""` | no | +| [name](#input\_name) | Name for all the resources as identifier | `string` | n/a | yes | +| [private\_route\_table\_ids](#input\_private\_route\_table\_ids) | List of ID of the route tables for the private subnets. You can set this to assign the each default route to the NAT instance | `list(string)` | `[]` | no | +| [private\_subnets\_cidr\_blocks](#input\_private\_subnets\_cidr\_blocks) | List of CIDR blocks of the private subnets. The NAT instance accepts connections from this subnets | `list(string)` | n/a | yes | +| [public\_subnet](#input\_public\_subnet) | ID of the public subnet to place the NAT instance | `string` | n/a | yes | +| [ssm\_policy\_arn](#input\_ssm\_policy\_arn) | SSM Policy to be attached to instance profile | `string` | `"arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"` | no | +| [tags](#input\_tags) | Tags applied to resources created with this module | `map(string)` | `{}` | no | +| [use\_spot\_instance](#input\_use\_spot\_instance) | Whether to use spot or on-demand EC2 instance | `bool` | `false` | no | +| [user\_data\_runcmd](#input\_user\_data\_runcmd) | Additional runcmd section of cloud-init | `list(list(string))` | `[]` | no | +| [user\_data\_write\_files](#input\_user\_data\_write\_files) | Additional write\_files section of cloud-init | `list(any)` | `[]` | no | +| [vpc\_id](#input\_vpc\_id) | ID of the VPC | `string` | n/a | yes | ## Outputs diff --git a/main.tf b/main.tf index 5d9beb7..f4b0bc1 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,7 @@ +data "aws_network_interface" "this" { + id = aws_network_interface.this.id +} + resource "aws_security_group" "this" { name_prefix = var.name vpc_id = var.vpc_id @@ -10,8 +14,8 @@ resource "aws_security_group_rule" "egress" { type = "egress" cidr_blocks = ["0.0.0.0/0"] from_port = 0 - to_port = 65535 - protocol = "tcp" + to_port = 0 + protocol = "-1" } resource "aws_security_group_rule" "ingress_any" { @@ -19,8 +23,8 @@ resource "aws_security_group_rule" "ingress_any" { type = "ingress" cidr_blocks = var.private_subnets_cidr_blocks from_port = 0 - to_port = 65535 - protocol = "all" + to_port = 0 + protocol = "-1" } resource "aws_network_interface" "this" { @@ -44,7 +48,7 @@ data "aws_ami" "this" { owners = ["amazon"] filter { name = "architecture" - values = ["x86_64"] + values = var.architecture } filter { name = "root-device-type" @@ -52,7 +56,7 @@ data "aws_ami" "this" { } filter { name = "name" - values = ["amzn2-ami-hvm-*"] + values = ["al2023-ami-minimal*"] } filter { name = "virtualization-type" @@ -60,7 +64,7 @@ data "aws_ami" "this" { } filter { name = "block-device-mapping.volume-type" - values = ["gp2"] + values = ["gp3"] } } @@ -79,9 +83,8 @@ resource "aws_launch_template" "this" { } network_interfaces { - associate_public_ip_address = true - security_groups = [aws_security_group.this.id] - delete_on_termination = true + device_index = 0 + network_interface_id = aws_network_interface.this.id } tag_specifications { @@ -124,7 +127,7 @@ resource "aws_autoscaling_group" "this" { desired_capacity = var.enabled ? 1 : 0 min_size = var.enabled ? 1 : 0 max_size = 1 - vpc_zone_identifier = [var.public_subnet] + availability_zones = [data.aws_network_interface.this.availability_zone] mixed_instances_policy { instances_distribution { @@ -191,21 +194,3 @@ resource "aws_iam_role_policy_attachment" "ssm" { role = aws_iam_role.this.name } -resource "aws_iam_role_policy" "eni" { - role = aws_iam_role.this.name - name_prefix = var.name - policy = <
"t3.nano",
"t3a.nano"
]