This Terraform configuration sets up an Auto Scaling Group (ASG) that runs a PowerShell script to repair unhealthy EC2 instances across all Availability Zones in the current AWS region.
- Launches instances across all available Availability Zones in an ASG, with a single instance per AZ.
- Each instance runs a custom PowerShell repair script, that iterates over all unhealthy instance form the current AZ:
- detaches the root volume from the current unhealthy instance.
- attaches it to the current instance.
- attempts to delete the broken CrowdStrike update file.
- detaches and re-attaches the volume to the initial instance.
- restarts the initial instance.
- Terraform installed (version 0.12 or later)
-
Clone this repository
-
Initialize the Terraform working directory:
terraform init
-
Review the planned changes:
terraform plan
-
Apply the Terraform configuration:
terraform apply
-
Confirm the changes by typing
yes
when prompted.
- To use a different Windows Server version, modify the
name
parameter in theaws_ssm_parameter
data source. - Adjust the
instance_type
in the launch template if you need more powerful instances. - Modify the
min_size
,max_size
, anddesired_capacity
in the ASG resource if you want a different scaling behavior.
To remove all created resources:
terraform destroy
Feel free to submit issues or pull requests if you have suggestions for improvements or bug fixes.
This code is (C) 2024 Cristian Magherusan-Stanciu, and released under the MIT license.
Check out more of our OSS repos at LeanerCloud.com.