Skip to content

Commit

Permalink
Self-destructing EC2 instances (#151)
Browse files Browse the repository at this point in the history
* Set InstanceInitiatedShutdownBehavior

* Added power_state directive to userdata
  • Loading branch information
abyrne55 authored Oct 24, 2022
1 parent 94a9287 commit 8f1b16d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/helpers/config/userdata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ runcmd:
- sudo service docker start 2>1 > /dev/null || echo "docker not started by systemctl"
- /run-container.sh
- cat /var/log/userdata-output >/dev/console
power_state:
delay: 5
mode: poweroff
message: Auto-terminating instance due to timeout
timeout: 300
2 changes: 2 additions & 0 deletions pkg/verifier/aws/aws_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func (a *AwsVerifier) createEC2Instance(input createEC2InstanceInput) (string, e
MaxCount: awsTools.Int32(input.instanceCount),
MinCount: awsTools.Int32(input.instanceCount),
InstanceType: ec2Types.InstanceType(input.instanceType),
// Tell EC2 to delete this instance if it shuts itself down, in case explicit instance deletion fails
InstanceInitiatedShutdownBehavior: ec2Types.ShutdownBehaviorTerminate,
// Because we're making this VPC aware, we also have to include a network interface specification
NetworkInterfaces: []ec2Types.InstanceNetworkInterfaceSpecification{eniSpecification},
// We specify block devices mainly to enable EBS encryption
Expand Down

0 comments on commit 8f1b16d

Please sign in to comment.