@@ -10,6 +10,8 @@ import com.intellij.psi.util.PsiTreeUtil
1010import com.intellij.psi.util.parentOfType
1111import com.intellij.psi.util.siblings
1212import org.intellij.terraform.config.Constants.HCL_CONNECTION_IDENTIFIER
13+ import org.intellij.terraform.config.Constants.HCL_LIFECYCLE_IDENTIFIER
14+ import org.intellij.terraform.config.Constants.HCL_POSTCONDITION_BLOCK_IDENTIFIER
1315import org.intellij.terraform.config.Constants.HCL_PROVISIONER_IDENTIFIER
1416import org.intellij.terraform.config.model.Module
1517import org.intellij.terraform.config.model.Variable
@@ -232,7 +234,7 @@ internal fun getDefinedLocalsInModule(element: BaseExpression): List<String> {
232234
233235internal fun getHclBlockForSelfContext (position : BaseExpression ): HCLBlock ? {
234236 val host = position.getHCLHost() ? : return null
235- return getProvisionerOfResource(host) ? : getConnectionOfResource(host)
237+ return getProvisionerOfResource(host) ? : getConnectionOfResource(host) ? : getPostConditionOfBlock(host)
236238}
237239
238240internal fun getProvisionerOfResource (host : HCLElement ): HCLBlock ? {
@@ -254,6 +256,22 @@ internal fun getConnectionOfResource(host: HCLElement): HCLBlock? {
254256 }
255257}
256258
259+ internal fun getPostConditionOfBlock (host : HCLElement ): HCLBlock ? {
260+ val postCondition = host.parentOfType<HCLBlock >() ? : return null
261+ if (postCondition.getNameElementUnquoted(0 ) != HCL_POSTCONDITION_BLOCK_IDENTIFIER )
262+ return null
263+
264+ val lifecycle = postCondition.parentOfType<HCLBlock >()
265+ if (lifecycle?.getNameElementUnquoted(0 ) != HCL_LIFECYCLE_IDENTIFIER ) {
266+ return null
267+ }
268+
269+ val resourceOrData = lifecycle.parentOfType<HCLBlock >()
270+ return if (TfPsiPatterns .ResourceRootBlock .accepts(resourceOrData) || TfPsiPatterns .DataSourceRootBlock .accepts(resourceOrData))
271+ resourceOrData
272+ else null
273+ }
274+
257275internal fun getParentResourceBlock (element : HCLElement ): HCLBlock ? {
258276 val resource = element.parentOfType<HCLBlock >()
259277 return if (TfPsiPatterns .ResourceRootBlock .accepts(resource)) resource else null
0 commit comments