Skip to content

Instantly share code, notes, and snippets.

@wesley-dean
Last active July 17, 2020 16:43
Show Gist options
  • Save wesley-dean/9e9f6f9f64fed7b2c5a1ee50cbf3a6c8 to your computer and use it in GitHub Desktop.
Save wesley-dean/9e9f6f9f64fed7b2c5a1ee50cbf3a6c8 to your computer and use it in GitHub Desktop.
This is a shell script that may be used to acquire the time from now using Terraform's External provider
#!/bin/sh
# Terraform's External provider:
# https://www.terraform.io/docs/providers/external/data_source.html
#
# Sample usage (Terraform):
# data "external" "nextmonth" {
# program = ["sh", "${path.module}date_from_now_terraform.sh"]
#
# query = {
# date = "next month"
# }
# }
#
# ... "${data.nextmonth.result.date}" ...
#
# Sample usage (shell):
#
# jq -n "{\"query\":{\"date\":\"next month\"}}" | sh ./date_from_now_terraform.sh
#
# Sample output:
# {
# "result": {
# "date": "2020-12-07"
# }
# }
jq -n "{\"result\":{\"date\":\"$(date -d "$(jq -r ".query.date")" +%Y-%m-%d)\"}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment