Skip to content
This repository was archived by the owner on Jul 20, 2024. It is now read-only.

Commit 5698aa1

Browse files
Lethgirint128
authored andcommitted
Add enabled var (#11)
1 parent f8edccd commit 5698aa1

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Features:
99
- Saving cost using a spot instance (from $1/month)
1010
- Fixed source IP address by reattaching ENI
1111
- Supporting Systems Manager Session Manager
12+
- Disable costly resources for compatibility with workspaces
1213

1314
Terraform 0.12 is required.
1415

@@ -153,6 +154,7 @@ This is an open source software. Feel free to open issues and pull requests.
153154

154155
| Name | Description | Type | Default | Required |
155156
|------|-------------|:----:|:-----:|:-----:|
157+
| enabled | Enable or disable costly resources| boolean | `true` | no |
156158
| extra\_user\_data | Extra script to run in the NAT instance | string | `""` | no |
157159
| image\_id | AMI of the NAT instance. Default to the latest Amazon Linux 2 | string | `""` | no |
158160
| instance\_types | Candidates of instance type for the NAT instance. This is used in the mixed instances policy | list | `[ "t3.nano", "t3a.nano" ]` | no |
@@ -166,6 +168,8 @@ This is an open source software. Feel free to open issues and pull requests.
166168

167169
## Outputs
168170

171+
Outputs are empty string for disabled costly resources.
172+
169173
| Name | Description |
170174
|------|-------------|
171175
| eip\_id | ID of the Elastic IP |

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ resource "aws_network_interface" "this" {
3636
}
3737

3838
resource "aws_eip" "this" {
39+
count = var.enabled ? 1 : 0
3940
network_interface = aws_network_interface.this.id
4041
tags = {
4142
Name = "nat-instance-${var.name}"
@@ -105,8 +106,8 @@ resource "aws_launch_template" "this" {
105106

106107
resource "aws_autoscaling_group" "this" {
107108
name_prefix = var.name
108-
desired_capacity = 1
109-
min_size = 1
109+
desired_capacity = var.enabled ? 1 : 0
110+
min_size = var.enabled ? 1 : 0
110111
max_size = 1
111112
vpc_zone_identifier = [var.public_subnet]
112113

outputs.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
output "eip_id" {
22
description = "ID of the Elastic IP"
3-
value = "${aws_eip.this.id}"
3+
value = var.enabled ? aws_eip.this[0].id : ""
44
}
55

66
output "eip_public_ip" {
77
description = "Public IP of the Elastic IP for the NAT instance"
8-
value = "${aws_eip.this.public_ip}"
8+
value = var.enabled ? aws_eip.this[0].public_ip : ""
99
}
1010

1111
output "eni_id" {
1212
description = "ID of the ENI for the NAT instance"
13-
value = "${aws_network_interface.this.id}"
13+
value = aws_network_interface.this.id
1414
}
1515

1616
output "eni_private_ip" {
1717
description = "Private IP of the ENI for the NAT instance"
1818
# workaround of https://github.com/terraform-providers/terraform-provider-aws/issues/7522
19-
value = "${tolist(aws_network_interface.this.private_ips)[0]}"
19+
value = tolist(aws_network_interface.this.private_ips)[0]
2020
}
2121

2222
output "sg_id" {
2323
description = "ID of the security group of the NAT instance"
24-
value = "${aws_security_group.this.id}"
24+
value = aws_security_group.this.id
2525
}
2626

2727
output "iam_role_name" {
2828
description = "Name of the IAM role for the NAT instance"
29-
value = "${aws_iam_role.this.name}"
29+
value = aws_iam_role.this.name
3030
}

variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
variable "enabled" {
2+
description = "Enable or not costly resources"
3+
default = true
4+
}
15
variable "name" {
26
description = "Name for all the resources as identifier"
37
}

0 commit comments

Comments
 (0)