mirror of
https://github.com/hakluke/how-to-exit-vim.git
synced 2025-06-18 10:31:56 +02:00
make it funnier
This commit is contained in:
parent
f3c242d960
commit
f2adc791c0
1 changed files with 49 additions and 15 deletions
64
README.md
64
README.md
|
@ -851,28 +851,62 @@ ENTER
|
||||||
## The DevOps way
|
## The DevOps way
|
||||||
|
|
||||||
Credit: @frank-bee
|
Credit: @frank-bee
|
||||||
```
|
|
||||||
provider "local" {
|
|
||||||
version = "~> 2.0"
|
```yaml
|
||||||
|
provider "aws" {
|
||||||
|
region = "us-gov-west-1" # AWS GovCloud (US) region
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "local_file" "exit_vim_script" {
|
data "aws_ami" "ubuntu" {
|
||||||
content = <<-EOF
|
most_recent = true
|
||||||
#!/bin/bash
|
owners = ["099720109477"] # Canonical's AWS account ID
|
||||||
ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9
|
|
||||||
EOF
|
filter {
|
||||||
filename = "${path.module}/exit_vim.sh"
|
name = "name"
|
||||||
file_permission = "0755"
|
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "null_resource" "run_exit_vim_script" {
|
resource "aws_instance" "example" {
|
||||||
|
ami = data.aws_ami.ubuntu.id
|
||||||
|
instance_type = "t2.micro"
|
||||||
|
tags = {
|
||||||
|
Name = "VimChecker"
|
||||||
|
}
|
||||||
|
|
||||||
provisioner "local-exec" {
|
provisioner "local-exec" {
|
||||||
command = "${path.module}/exit_vim.sh"
|
command = <<-EOF
|
||||||
}
|
#!/bin/bash
|
||||||
|
# Start Vim in the background
|
||||||
|
vim &
|
||||||
|
|
||||||
triggers = {
|
# Check if Vim is running
|
||||||
always_run = "${timestamp()}"
|
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
Add a link
Reference in a new issue