Create custom condition rules

更新时间:
复制 MD 格式

Create a custom rule to evaluate target resources when the predefined rule templates in Cloud Config do not meet your requirements. You visually configure the rule's three core elements: resource feature, operator, and desired value.

Background

For more information about the concepts, use cases, and key features of custom condition rules, see Definition and working principles of custom condition rules.

Procedure

  1. Log on to the Cloud Config console.

  2. Optional. In the upper-left corner, select an account group.

    This operation is required only if you are using a management account of a resource directory. Otherwise, you do not need to perform the operation.

  3. In the left-side navigation pane, choose Compliance & Audit > Rules.

  4. On the Rules page, click Create Rule.

  5. On the Select Create Method page, select Based on Condition, select a Resource Type, set the conditions for the resource type, and then click Next.

    To set the conditions:

    1. Set the rule conditions.

      Note
      • Single-condition evaluation

        Example: Check if an ECS instance has deletion protection enabled. An instance is compliant if protection is enabled; otherwise, it is non-compliant.

        1. From the Select Resource Type drop-down list, select Elastic Compute Service (ECS) > ECS instance.

        2. Click Show dry run panel.

        3. On the Visual editor tab, keep the default conditional operator and. In the Resource Type field, select Resource Property > DeletionProtection. For the Operator, select StringEquals. In the desired value field, enter false.

      • Multi-condition evaluation

        Example: A resource is compliant if it meets either of the following two conditions; otherwise, it is non-compliant.

        Condition 1: An enabled trail exists in ActionTrail.

        Condition 2: The ActionTrail trail is configured for all regions.

        1. From the Select Resource Type drop-down list, select ActionTrail > ActionTrail trail.

        2. Click Show dry run panel.

        3. On the Visual editor tab, select the or conditional operator. In the Resource Type field, select Resource Property > Status. For the Operator, select StringEquals. In the desired value field, enter Enable.

        4. Click Add Condition. In the new Resource Type field, select Resource Property > TrailRegion. For the Operator, select StringEquals. In the desired value field, enter All.

      Note

      To write the condition logic directly in code, click the Script editor tab in the upper-right corner of the dry run panel.

    2. In the upper-left corner of the dry run panel, click Dry run.

      The validation result is displayed as Compliant or Non-compliant, indicating whether the sample resource configuration meets your defined conditions.

      • Result is Compliant

        This usually means your rule conditions are correctly configured. Proceed to the next step.

      • Result is Non-compliant

        • A desired value for a condition may be incorrect. Review and correct the failed conditions, then run the dry run again.

        • The resource configuration is Non-compliant. If this result is expected, you can proceed to the next step.

  6. On the Set Basic Properties page, set the rule name, risk level, trigger, and description, and then click Next.

  7. On the Set Effective Scope page, set the effective scope for the resources, and then click Next.

  8. On the Set Correction page, click Submit.

    You can enable the Set Correction switch to configure a custom remediation. For more information, see Set a custom remediation.

Related topics