Skip to content

Commit

Permalink
SSH optional + no default CIDR
Browse files Browse the repository at this point in the history
  • Loading branch information
RaJiska committed Jun 17, 2024
1 parent d08c8e6 commit 2bcd121
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,17 @@ module "fck-nat" {
| <a name="input_name"></a> [name](#input\_name) | Name used for resources created within the module | `string` | n/a | yes |
| <a name="input_route_table_id"></a> [route\_table\_id](#input\_route\_table\_id) | Deprecated. Use route\_tables\_ids instead | `string` | `null` | no |
| <a name="input_route_tables_ids"></a> [route\_tables\_ids](#input\_route\_tables\_ids) | Route tables to update. Only valid if update\_route\_tables is true | `map(string)` | `{}` | no |
| <a name="input_ssh_cidr_blocks"></a> [ssh\_cidr\_blocks](#input\_ssh\_cidr\_blocks) | CIDR blocks to allow SSH access to the NAT instance from | `list(string)` | `[]` | no |
| <a name="input_ssh_key_name"></a> [ssh\_key\_name](#input\_ssh\_key\_name) | Name of the SSH key to use for the NAT instance. SSH access will be enabled only if a key name is provided | `string` | `null` | no |
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id) | Subnet ID to deploy the NAT instance into | `string` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to resources created within the module | `map(string)` | `{}` | no |
| <a name="input_update_route_table"></a> [update\_route\_table](#input\_update\_route\_table) | Deprecated. Use update\_route\_tables instead | `bool` | `false` | no |
| <a name="input_update_route_tables"></a> [update\_route\_tables](#input\_update\_route\_tables) | Whether or not to update the route tables with the NAT instance | `bool` | `false` | no |
| <a name="input_use_cloudwatch_agent"></a> [use\_cloudwatch\_agent](#input\_use\_cloudwatch\_agent) | Whether or not to enable CloudWatch agent for the NAT instance | `bool` | `false` | no |
| <a name="input_use_default_security_group"></a> [use\_default\_security\_group](#input\_use\_default\_security\_group) | Whether or not to use the default security group for the NAT instance | `bool` | `true` | no |
| <a name="input_use_spot_instances"></a> [use\_spot\_instances](#input\_use\_spot\_instances) | Whether or not to use spot instances for running the NAT instance | `bool` | `false` | no |
| <a name="input_use_ssh"></a> [use\_ssh](#input\_use\_ssh) | Whether or not to enable SSH access to the NAT instance | `bool` | `false` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID to deploy the NAT instance into | `string` | n/a | yes |
| <a name="input_ssh_key_name"></a> [ssh\_key\_name](#input\_ssh\_key\_name) | Name of the SSH key to use for the NAT instance. SSH access will be enabled only if a key name is provided | `string` | `null` | no |
| <a name="input_ssh_cidr_blocks"></a> [ssh\_cidr\_blocks](#input\_ssh\_cidr\_blocks) | CIDR blocks to allow SSH access to the NAT instance | `list(string)` | `["0.0.0.0/0"]` | no |

## Outputs

Expand All @@ -106,8 +107,8 @@ module "fck-nat" {
| <a name="output_eni_id"></a> [eni\_id](#output\_eni\_id) | The ID of the static ENI used by the fck-nat instance |
| <a name="output_ha_mode"></a> [ha\_mode](#output\_ha\_mode) | Whether or not high-availability mode is enabled via autoscaling group |
| <a name="output_instance_arn"></a> [instance\_arn](#output\_instance\_arn) | The ARN of the fck-nat instance if running in non-HA mode |
| <a name="output_instance_public_ip"></a> [instance\_public\_ip](#output\_instance\_public\_ip) | The public IP address of the fck-nat instance if running in non-HA mode |
| <a name="output_instance_profile_arn"></a> [instance\_profile\_arn](#output\_instance\_profile\_arn) | The ARN of the instance profile used by the fck-nat instance |
| <a name="output_instance_public_ip"></a> [instance\_public\_ip](#output\_instance\_public\_ip) | The public IP address of the fck-nat instance if running in non-HA mode |
| <a name="output_instance_type"></a> [instance\_type](#output\_instance\_type) | Instance type used for the fck-nat instance |
| <a name="output_kms_key_id"></a> [kms\_key\_id](#output\_kms\_key\_id) | KMS key ID to use for encrypting fck-nat instance EBS volumes |
| <a name="output_launch_template_id"></a> [launch\_template\_id](#output\_launch\_template\_id) | The ID of the launch template used to spawn fck-nat instances |
Expand Down
1 change: 0 additions & 1 deletion ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ resource "aws_launch_template" "main" {
name = var.name
image_id = local.ami_id
instance_type = var.instance_type

key_name = var.ssh_key_name

block_device_mappings {
Expand Down
5 changes: 3 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ resource "aws_security_group" "main" {
}

dynamic "ingress" {
for_each = var.ssh_key_name != null ? [1] : []
for_each = var.use_ssh && length(var.ssh_cidr_blocks) > 0 ? [1] : []

content {
description = "SSH ingress from anywhere"
description = "SSH access"
from_port = 22
to_port = 22
protocol = "tcp"
Expand Down
18 changes: 12 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ variable "additional_security_group_ids" {
default = []
}

variable "tags" {
description = "Tags to apply to resources created within the module"
type = map(string)
default = {}
variable "use_ssh" {
description = "Whether or not to enable SSH access to the NAT instance"
type = bool
default = false
}

variable "ssh_key_name" {
Expand All @@ -136,7 +136,13 @@ variable "ssh_key_name" {
}

variable "ssh_cidr_blocks" {
description = "CIDR blocks to allow SSH access to the NAT instance"
description = "CIDR blocks to allow SSH access to the NAT instance from"
type = list(string)
default = ["0.0.0.0/0"]
default = []
}

variable "tags" {
description = "Tags to apply to resources created within the module"
type = map(string)
default = {}
}

0 comments on commit 2bcd121

Please sign in to comment.