Manages a resource that delays creation and/or destruction, typically for further resources. This prevents cross-platform compatibility and destroy-time issues with using the local-exec
provisioner.
# This resource will destroy (potentially immediately) after null_resource.next
resource "null_resource" "previous" {}
resource "time_sleep" "wait_30_seconds" {
depends_on = [null_resource.previous]
create_duration = "30s"
}
# This resource will create (at least) 30 seconds after null_resource.previous
resource "null_resource" "next" {
depends_on = [time_sleep.wait_30_seconds]
}
# This resource will destroy (at least) 30 seconds after null_resource.next
resource "null_resource" "previous" {}
resource "time_sleep" "wait_30_seconds" {
depends_on = [null_resource.previous]
destroy_duration = "30s"
}
# This resource will create (potentially immediately) after null_resource.previous
resource "null_resource" "next" {
depends_on = [time_sleep.wait_30_seconds]
}
resource "aws_ram_resource_association" "example" {
resource_arn = aws_subnet.example.arn
resource_share_arn = aws_ram_resource_share.example.arn
}
# AWS resources shared via Resource Access Manager can take a few seconds to
# propagate across AWS accounts after RAM returns a successful association.
resource "time_sleep" "ram_resource_propagation" {
create_duration = "60s"
triggers = {
# This sets up a proper dependency on the RAM association
subnet_arn = aws_ram_resource_association.example.resource_arn
subnet_id = aws_subnet.example.id
}
}
resource "aws_db_subnet_group" "example" {
name = "example"
# Read the Subnet identifier "through" the time_sleep resource to ensure a
# proper dependency and that both will change together.
subnet_ids = [time_sleep.ram_resource_propagation.triggers["subnet_id"]]
}
create_duration
(String) Time duration to delay resource creation. For example, 30s
for 30 seconds or 5m
for 5 minutes. Updating this value by itself will not trigger a delay.destroy_duration
(String) Time duration to delay resource destroy. For example, 30s
for 30 seconds or 5m
for 5 minutes. Updating this value by itself will not trigger a delay. This value or any updates to it must be successfully applied into the Terraform state before destroying this resource to take effect.triggers
(Map of String) (Optional) Arbitrary map of values that, when changed, will run any creation or destroy delays again. See the main provider documentation for more information.id
(String) RFC3339 format of the offset timestamp, e.g. 2020-02-12T06:36:13Z
.This resource can be imported with the create_duration
and destroy_duration
, separated by a comma (,
).
e.g. For 30 seconds create duration with no destroy duration:
terraform import time_sleep.example 30s,
e.g. For 30 seconds destroy duration with no create duration:
terraform import time_sleep.example ,30s
The triggers
argument cannot be imported.