Skip to content

Support the self object in lifecycle.precondition for advanced input validation #34626

@tiwood

Description

@tiwood

Terraform Version

1.7.2

Use Cases

The self object is currently only available for postcondition checks.

We currently have use cases, where we create configurations based on input YAML files. Our goal is to inform the maintainers during terraform plan if the YAML file contains invalid inputs/configurations. This could be done using lifecycle.precondition if the self object was available.

This is really similar then using input validation for variables, but this is not usable for our use case, as the input data comes from various sources (APIs, data stores..).

Attempted Solutions

N/A

Proposal

Allow the use of the self object in lifecycle.precondition.

resource "terraform_data" "this" {
  input = {
    foo = "bar"
  }

  lifecycle {
    precondition {
      condition     = self.input.foo != "foo"
      error_message = "Snap! foo should be 'foo'."
    }
  }
}

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementnewnew issue not yet triagedwaiting-responseAn issue/pull request is waiting for a response from the community

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions