Skip to content

Instantly share code, notes, and snippets.

@ChristophShyper
Last active July 19, 2020 21:12
Show Gist options
  • Save ChristophShyper/d291258dcf9afe64c517f1f68b4e437c to your computer and use it in GitHub Desktop.
Save ChristophShyper/d291258dcf9afe64c517f1f68b4e437c to your computer and use it in GitHub Desktop.
Terraform timeouts

Terraform timeouts

Resource

Will be executed only on trigger change

resource "null_resource" "first" {
}

resource "null_resource" "sleep" {
  provisioner "local-exec" {
    command = "sleep 10"
  }
  triggers = {
    res_id = null_resource.first.id
  }
}

resource "null_resource" "second" {
  id = null_resource.sleep.triggers.res_id
}

Data source

Will be executed each time

resource "null_resource" "first" {
}

data "external" "echo_sleep" {
  program = ["python3", "./echo-sleep.py"]

  query = {
    echo  = null_resource.first.id
    sleep = 30
  }
}

resource "null_resource" "second" {
  id = data.external.echo_sleep.result.echo
}
import json
import sys
import time


def handler(arg):
    echo = arg['echo']
    ret = {
        'echo' : echo
    }
    time.sleep(int(arg['sleep']))
    print("{}".format(json.dumps(ret)))


if __name__ == '__main__':
    data = json.load(sys.stdin)
    handler(data)
    exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment