Skip to content

Cannot import template-instantiated custom policies (isDefault=false, templateId!=0) #736

Description

@ArdzivBullish

Summary

The provider has no first-class way to bring a Sysdig policy that was instantiated from a Sysdig-provided template (isDefault: false, templateId != 0) under Terraform management. Both candidate resource types reject the import:

  • sysdig_secure_custom_policy.Import errors with "unable to import policy that is not a custom policy" because of:

    if policy.IsDefault || policy.TemplateID != 0 {
        return nil, errors.New("unable to import policy that is not a custom policy")
    }
  • sysdig_secure_managed_policy exposes no Importer, and terraform import errors with "resource sysdig_secure_managed_policy doesn't support import". The Create handler is also strict — it requires IsDefault: true, so it cannot adopt a template-instantiated customer-owned policy either.

This leaves a gap: a real category of customer-owned policies (instantiated from a Sysdig template but customer-managed thereafter) cannot be brought under Terraform management via either resource type.

Reproduction

  1. In the Sysdig UI, create a new policy by clicking "Add Policy" → choose one of the Sysdig-provided templates (e.g. "Sysdig Runtime Notable Events").

  2. Confirm via API that the resulting policy has isDefault: false, templateId: <non-zero>.

  3. In Terraform, declare the resource and an import { ... } block:

    resource "sysdig_secure_custom_policy" "example" {
      name = "Notable Events Customised"
      type = "falco"
      # ...
    }
    
    import {
      to = sysdig_secure_custom_policy.example
      id = "<policy_id>"
    }
  4. Run terraform planError: unable to import policy that is not a custom policy.

  5. Switch to sysdig_secure_managed_policyError: resource sysdig_secure_managed_policy doesn't support import.

Suggested fix (either approach unblocks the gap)

  1. Add an Importer to sysdig_secure_managed_policy that adopts any policy with templateId != 0 (regardless of isDefault). Update the Create handler to also accept isDefault: false policies when templateId != 0.
  2. OR relax sysdig_secure_custom_policy.Import so it accepts templateId != 0 policies as long as isDefault: false. The CRUD handlers already treat them as customer-owned (they're not Sysdig defaults; the customer can edit them), so this is a relatively small change.

Versions affected

  • Provider 3.8.1 (latest at time of writing). Confirmed by reading provider source at master.

Workaround

The affected policies can currently only be managed via the Sysdig UI. Terraform imports must skip them, leaving the only meaningful operator interactions (disabling individual rules, adjusting enabled / scope / notification_channels) outside GitOps coverage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions