export TF_VAR_trusted_ip="$(dig +short myip.opendns.com @resolver1.opendns.com.)/32"
Last active
February 25, 2022 03:17
-
-
Save mjmenger/aa89490b418db22dadc41fad1ced67ff to your computer and use it in GitHub Desktop.
terraform cli stunts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # create a .env file for use by the VS Code Rest Client extension | |
| # | |
| # extract the BIG-IP addresses from the Terraform output | |
| export BIGIP_IPS=`terraform output --json | jq -cr '.bigip_mgmt_ips.value[]'` | |
| export BIGIP_USER=admin | |
| # extract the BIG-IP password from the Terraform state | |
| export BIGIP_PASSWORD=`terraform show -json | jq .values.root_module.resources[] | jq -r 'select(.address | contains("random_password")).values.result'` | |
| ((i=0)) | |
| echo "#.env" > .env | |
| for ip in $BIGIP_IPS; do | |
| ((i++)) | |
| echo bigip$i=$ip >> .env | |
| done | |
| echo user=admin >> .env | |
| echo password=$BIGIP_PASSWORD >> .env | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "local_file" "dotenv" { | |
| content = <<EOF | |
| bigip1=${module.bigip.mgmt_public_ips[0]} | |
| bigip2=${module.bigip.mgmt_public_ips[1]} | |
| user=admin | |
| password=${random_password.password.result} | |
| EOF | |
| filename = "${path.module}/.env" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource null_resource "webhook" { | |
| provisioner "local-exec" { | |
| command = <<-EOT | |
| curl -s -k -X POST https://maker.ifttt.com/trigger/EVENT/with/key/iftttkey \ | |
| -H 'Content-Type: application/json' \ | |
| --max-time 600 \ | |
| --retry 50 \ | |
| --retry-delay 15 \ | |
| --retry-max-time 600 \ | |
| -d '{ "value1" : "${var.someterraformvar}", "value2" : "${var.anothervar}", "value3" : "" }' | |
| EOT | |
| } | |
| } |
If you've deleted everything with terragrunt or terraform and you want to save disk space on terraform providers and modules, you can try the following. YOU MAY LOSE STUFF THAT'S PRECIOUS TO YOU. IF YOU'RE NOT CERTAIN THEN DON'T DO THIS.
# remove the providers and modules you've downloaded
find . -type d -name ".terraform" -exec rm -rf "{}" \;
# remove the configuration lock file unless you don't want to
find . -type f -name ".terraform.lock.hcl" -delete
# remove the state file because there's nothing to track the state of ... you hope
find . -type f -name "terraform.tfstate*" -deleteopenssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment