mirror of
https://github.com/hakluke/how-to-exit-vim.git
synced 2025-05-02 11:46:16 +02:00
Merge f2adc791c0
into bc9395e0e2
This commit is contained in:
commit
162716f865
1 changed files with 64 additions and 1 deletions
63
README.md
63
README.md
|
@ -847,3 +847,66 @@ STRING :q!
|
||||||
DELAY 500
|
DELAY 500
|
||||||
ENTER
|
ENTER
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## The DevOps way
|
||||||
|
|
||||||
|
Credit: @frank-bee
|
||||||
|
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
provider "aws" {
|
||||||
|
region = "us-gov-west-1" # AWS GovCloud (US) region
|
||||||
|
}
|
||||||
|
|
||||||
|
data "aws_ami" "ubuntu" {
|
||||||
|
most_recent = true
|
||||||
|
owners = ["099720109477"] # Canonical's AWS account ID
|
||||||
|
|
||||||
|
filter {
|
||||||
|
name = "name"
|
||||||
|
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "example" {
|
||||||
|
ami = data.aws_ami.ubuntu.id
|
||||||
|
instance_type = "t2.micro"
|
||||||
|
tags = {
|
||||||
|
Name = "VimChecker"
|
||||||
|
}
|
||||||
|
|
||||||
|
provisioner "local-exec" {
|
||||||
|
command = <<-EOF
|
||||||
|
#!/bin/bash
|
||||||
|
# Start Vim in the background
|
||||||
|
vim &
|
||||||
|
|
||||||
|
# Check if Vim is running
|
||||||
|
if ps aux | grep '[v]im'; then
|
||||||
|
echo "vim_running" > vim_status.txt
|
||||||
|
else
|
||||||
|
echo "vim_not_running" > vim_status.txt
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output "vim_status" {
|
||||||
|
value = file("${path.module}/vim_status.txt")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
terraform init
|
||||||
|
terraform apply -auto-approve
|
||||||
|
VIM_STATUS=$(terraform output -raw vim_status)
|
||||||
|
if [ "$VIM_STATUS" == "vim_running" ]; then
|
||||||
|
echo "Vim is running. Triggering Terraform destroy."
|
||||||
|
terraform destroy -auto-approve
|
||||||
|
else
|
||||||
|
echo "No Vim process found. Instance will not be terminated."
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue