opentofu/internal/configs/testdata/error-files/precondition-postcondition-selfref.tf
Alisdair McDiarmid 7ded73f266 configs: Validate pre/postcondition self-refs
Preconditions and postconditions for resources and data sources may not
refer to the address of the containing resource or data source. This
commit adds a parse-time validation for this rule.
2022-02-03 09:37:22 -05:00

56 lines
1.5 KiB
HCL

resource "test" "test" {
lifecycle {
precondition {
condition = test.test.foo # ERROR: Invalid reference in precondition
error_message = "Cannot refer to self."
}
postcondition {
condition = test.test.foo # ERROR: Invalid reference in postcondition
error_message = "Cannot refer to self."
}
}
}
data "test" "test" {
lifecycle {
precondition {
condition = data.test.test.foo # ERROR: Invalid reference in precondition
error_message = "Cannot refer to self."
}
postcondition {
condition = data.test.test.foo # ERROR: Invalid reference in postcondition
error_message = "Cannot refer to self."
}
}
}
resource "test" "test_counted" {
count = 1
lifecycle {
precondition {
condition = test.test_counted[0].foo # ERROR: Invalid reference in precondition
error_message = "Cannot refer to self."
}
postcondition {
condition = test.test_counted[0].foo # ERROR: Invalid reference in postcondition
error_message = "Cannot refer to self."
}
}
}
data "test" "test_counted" {
count = 1
lifecycle {
precondition {
condition = data.test.test_counted[0].foo # ERROR: Invalid reference in precondition
error_message = "Cannot refer to self."
}
postcondition {
condition = data.test.test_counted[0].foo # ERROR: Invalid reference in postcondition
error_message = "Cannot refer to self."
}
}
}