> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/application-security/terraform-workflows/manage-resources/manage-terraform-run-tasks-enforcement.md).

# Manage Terraform Run Tasks enforcement

Declaratively dictate which infrastructure misconfigurations or exposed secrets will trigger a Run Task failure during the `terraform plan` phase, blocking insecure infrastructure from being deployed.

### Prerequisites

* **Establish integration**: The HCP Terraform Run Task integration must already be configured. Refer to [Terraform Cloud (Run Tasks)](/application-security/application-security/onboard-data-sources/integrate-ci-tools/terraform-cloud-run-tasks.md) or [Terraform Enterprise (Run Tasks)](/application-security/application-security/onboard-data-sources/integrate-ci-tools/terraform-enterprise-run-tasks.md).
* **Asset Groups**: Target Asset Groups must be established. Refer to [Manage Asset Groups](/application-security/terraform-workflows/manage-resources/manage-asset-groups.md).

### Configuration

Use the `cortexcloud_appsec_policy` resource to define the finding types and conditions When HCP Terraform triggers the Run Task, Cortex Cloud evaluates the plan against the `cicd_trigger` actions defined in this policy to determine if the plan should be blocked.

```terraform
# Example: Enforce a Run Task block for Critical IaC misconfigurations
resource "cortexcloud_appsec_policy" "run_task_iac_guardrails" {
  name        = "HCP Run Task IaC Guardrails"
  description = "Blocks Terraform Run Tasks if critical IaC misconfigurations are detected in the plan."
  status      = "enabled"

  # SCOPE: Target the asset group representing your Terraform workspaces
  asset_group_ids = [1]

  # Conditions: Evaluate severity (Requires uppercase keys per provider schema)
  conditions = jsonencode({
    AND = [
      {
        SEARCH_FIELD = "Severity"
        SEARCH_TYPE  = "EQ"
        SEARCH_VALUE = "CRITICAL"
      }
    ]
  })

  # Actions: The Run Task integration evaluates this block to determine block/pass status
  cicd_trigger = {
    enabled = true
    actions = {
      report_issue = true
      block_cicd   = true  # Fails the HCP Terraform Run Task
      report_cicd  = true
    }
  }

  # Unused triggers required by schema validation
  pr_trigger = {
    enabled = false
    actions = { report_issue = false, report_pr_comment = false, block_pr = false }
  }
  periodic_trigger = {
    enabled = false
    actions = { report_issue = false }
  }
  ci_image_trigger = {
    enabled = false
    actions = { report_issue = false, report_cicd = false, block_cicd = false }
  }
  image_registry_trigger = {
    enabled = false
    actions = { report_issue = false }
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/application-security/terraform-workflows/manage-resources/manage-terraform-run-tasks-enforcement.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
