Skip to content

lifecycle.action_trigger executes actions before resource creation/update is completed #37930

@jeremmfr

Description

@jeremmfr

Terraform Version

Terraform v1.14.0
on darwin_arm64
+ provider registry.terraform.io/hashicorp/local v2.6.1

Terraform Configuration Files

resource "local_file" "foo" {
  content  = "foo!bar"
  filename = "/tmp/foo.bar"

  lifecycle {
    action_trigger {
      events  = [after_create, after_update]
      actions = [action.local_command.bar]
    }
  }
}

action "local_command" "bar" {
  config {
    command   = "cat"
    arguments = ["/tmp/foo.bar"]
  }
}

Debug Output

https://gist.github.com/jeremmfr/87c348af5c77d22e5e10c8133d99e821

Expected Behavior

When using lifecycle.action_trigger with after_create or after_update events, the triggered action should execute after the resource has been fully created/updated and its side effects (like file creation) are completed.

In the example above, the local_command action should run after the file /tmp/foo.bar has been successfully written to disk, allowing the cat command to read its contents.

Actual Behavior

The action is triggered before the resource creation is completed. The local_command action fails because the file /tmp/foo.bar does not exist yet when the action attempts to read it.

This suggests that after_create and after_update events are firing before the resource's side effects are finalized, despite the "after_" prefix implying completion.

Steps to Reproduce

  1. Create a Terraform configuration with the above code
  2. terraform init
  3. terraform apply
  4. Observe that the action fails with an error indicating the file does not exist

Additional Context

This timing issue affects the reliability of action_trigger when actions depend on the actual completion of resource operations, not just the API call completion.

References

None

Generative AI / LLM assisted development?

No

Metadata

Metadata

Labels

bugnewnew issue not yet triaged

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions