Skip to content

Commit 63afbd3

Browse files
Nurullokhon Gulomkodirovintellij-monorepo-bot
authored andcommitted
[terraform] IJPL-185785 Added post condition block to self context of resource and data source
GitOrigin-RevId: 8339b597037f833a4af790b358e5cf9f7ec75b46
1 parent 150f756 commit 63afbd3

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

terraform/src/org/intellij/terraform/hcl/psi/HCLPsiUtil.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import com.intellij.psi.util.PsiTreeUtil
1010
import com.intellij.psi.util.parentOfType
1111
import com.intellij.psi.util.siblings
1212
import 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
1315
import org.intellij.terraform.config.Constants.HCL_PROVISIONER_IDENTIFIER
1416
import org.intellij.terraform.config.model.Module
1517
import org.intellij.terraform.config.model.Variable
@@ -232,7 +234,7 @@ internal fun getDefinedLocalsInModule(element: BaseExpression): List<String> {
232234

233235
internal 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

238240
internal 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+
257275
internal fun getParentResourceBlock(element: HCLElement): HCLBlock? {
258276
val resource = element.parentOfType<HCLBlock>()
259277
return if (TfPsiPatterns.ResourceRootBlock.accepts(resource)) resource else null

0 commit comments

Comments
 (0)