Skip to content

Commit d4045d9

Browse files
kris-Nabiscloudpossebotjoe-nilanddotCipher
authored
feature/disable-alarm-action (#145)
* feature/disable-alarm-action * Auto Format * Update main.tf --------- Co-authored-by: cloudpossebot <[email protected]> Co-authored-by: Joe Niland <[email protected]> Co-authored-by: Cody Moore <[email protected]>
1 parent 0df4270 commit d4045d9

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ Available targets:
257257
| <a name="input_delete_on_termination"></a> [delete\_on\_termination](#input\_delete\_on\_termination) | Whether the volume should be destroyed on instance termination | `bool` | `true` | no |
258258
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
259259
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
260+
| <a name="input_disable_alarm_action"></a> [disable\_alarm\_action](#input\_disable\_alarm\_action) | Disable the creation of Alarm Action | `bool` | `false` | no |
260261
| <a name="input_disable_api_termination"></a> [disable\_api\_termination](#input\_disable\_api\_termination) | Enable EC2 Instance Termination Protection | `bool` | `false` | no |
261262
| <a name="input_ebs_device_name"></a> [ebs\_device\_name](#input\_ebs\_device\_name) | Name of the EBS device to mount | `list(string)` | <pre>[<br> "/dev/xvdb",<br> "/dev/xvdc",<br> "/dev/xvdd",<br> "/dev/xvde",<br> "/dev/xvdf",<br> "/dev/xvdg",<br> "/dev/xvdh",<br> "/dev/xvdi",<br> "/dev/xvdj",<br> "/dev/xvdk",<br> "/dev/xvdl",<br> "/dev/xvdm",<br> "/dev/xvdn",<br> "/dev/xvdo",<br> "/dev/xvdp",<br> "/dev/xvdq",<br> "/dev/xvdr",<br> "/dev/xvds",<br> "/dev/xvdt",<br> "/dev/xvdu",<br> "/dev/xvdv",<br> "/dev/xvdw",<br> "/dev/xvdx",<br> "/dev/xvdy",<br> "/dev/xvdz"<br>]</pre> | no |
262263
| <a name="input_ebs_iops"></a> [ebs\_iops](#input\_ebs\_iops) | Amount of provisioned IOPS. This must be set with a volume\_type of `io1`, `io2` or `gp3` | `number` | `0` | no |

cloudwatch-alarm.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Restart dead or hung instance
22

33
resource "null_resource" "check_alarm_action" {
4-
count = local.instance_count
4+
count = var.disable_alarm_action ? 0 : local.instance_count
55

66
triggers = {
77
action = "arn:${data.aws_partition.default.partition}:swf:${local.region}:${data.aws_caller_identity.default.account_id}:${var.default_alarm_action}"
88
}
99
}
1010

1111
resource "aws_cloudwatch_metric_alarm" "default" {
12-
count = local.instance_count
12+
count = var.disable_alarm_action ? 0 : local.instance_count
13+
1314
alarm_name = module.this.id
1415
comparison_operator = var.comparison_operator
1516
evaluation_periods = var.evaluation_periods

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
| <a name="input_delete_on_termination"></a> [delete\_on\_termination](#input\_delete\_on\_termination) | Whether the volume should be destroyed on instance termination | `bool` | `true` | no |
7171
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
7272
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
73+
| <a name="input_disable_alarm_action"></a> [disable\_alarm\_action](#input\_disable\_alarm\_action) | Disable the creation of Alarm Action | `bool` | `false` | no |
7374
| <a name="input_disable_api_termination"></a> [disable\_api\_termination](#input\_disable\_api\_termination) | Enable EC2 Instance Termination Protection | `bool` | `false` | no |
7475
| <a name="input_ebs_device_name"></a> [ebs\_device\_name](#input\_ebs\_device\_name) | Name of the EBS device to mount | `list(string)` | <pre>[<br> "/dev/xvdb",<br> "/dev/xvdc",<br> "/dev/xvdd",<br> "/dev/xvde",<br> "/dev/xvdf",<br> "/dev/xvdg",<br> "/dev/xvdh",<br> "/dev/xvdi",<br> "/dev/xvdj",<br> "/dev/xvdk",<br> "/dev/xvdl",<br> "/dev/xvdm",<br> "/dev/xvdn",<br> "/dev/xvdo",<br> "/dev/xvdp",<br> "/dev/xvdq",<br> "/dev/xvdr",<br> "/dev/xvds",<br> "/dev/xvdt",<br> "/dev/xvdu",<br> "/dev/xvdv",<br> "/dev/xvdw",<br> "/dev/xvdx",<br> "/dev/xvdy",<br> "/dev/xvdz"<br>]</pre> | no |
7576
| <a name="input_ebs_iops"></a> [ebs\_iops](#input\_ebs\_iops) | Amount of provisioned IOPS. This must be set with a volume\_type of `io1`, `io2` or `gp3` | `number` | `0` | no |

main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ resource "aws_instance" "default" {
163163
cpu_credits = var.burstable_mode
164164
}
165165

166+
lifecycle {
167+
ignore_changes = [
168+
ami
169+
]
170+
}
171+
166172
tags = module.this.tags
167173

168174
volume_tags = var.volume_tags_enabled ? module.this.tags : {}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ variable "metric_threshold" {
279279
default = 1
280280
}
281281

282+
variable "disable_alarm_action" {
283+
type = bool
284+
default = false
285+
description = "Disable the creation of Alarm Action"
286+
}
287+
282288
variable "default_alarm_action" {
283289
type = string
284290
default = "action/actions/AWS_EC2.InstanceId.Reboot/1.0"

0 commit comments

Comments
 (0)