---
policy: /ce/ca/aws/network-firewall/firewall-delete-protection
logic: /ce/ca/aws/network-firewall/firewall-delete-protection/prod.logic.yaml
executionTime: 2026-01-17T12:02:55.245063829Z
generationMs: 112
executionMs: 1230
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10A2__disappearanceTime__c)
      actual: isDisappeared(CA10A2__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10A2__status__c') != 'READY'
      actual: extract('CA10A2__status__c') != 'READY'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10A2__deleteProtection__c') == 'false'
      actual: extract('CA10A2__deleteProtection__c') == 'false'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10A2__deleteProtection__c') == 'true'
      actual: extract('CA10A2__deleteProtection__c') == 'true'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/network-firewall/firewall-delete-protection/policy.yaml
    md5Hash: 7A919F3A0353C64FCDE5D297BFC02D5A
    content: "---\nnames:\n  full: \"AWS Network Firewall Delete Protection is not\
      \ enabled\"\n  contextual: \"Firewall Delete Protection is not enabled\"\ndescription:\
      \ >\n  Ensure that AWS Network Firewall has delete protection enabled. Delete\
      \ protection \n  prevents the firewall from being deleted accidentally or via\
      \ unauthorized requests. \n  This is a critical setting for maintaining continuous\
      \ network security and availability.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n\
      \  - \"RELIABILITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-reliability/system-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/network-firewall/09\"\nsimilarPolicies:\n\
      \  awsSecurityHub:\n    - name: \"[NetworkFirewall.9] Network Firewall firewalls\
      \ should have deletion protection enabled\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/networkfirewall-controls.html#networkfirewall-9\"\
      \n"
  - path: /ce/ca/aws/network-firewall/firewall-delete-protection/prod.logic.yaml
    md5Hash: A4B3E1319E0ADEC622F7F14C7C6EB933
    content: |
      ---
      inputType: "CA10A2__CaAwsNetworkFirewallFirewall__c"
      importExtracts:
        - file: "/types/CA10A2__CaAwsNetworkFirewallFirewall__c/object.extracts.yaml"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The Firewall is not ready."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10A2__status__c"
              right:
                TEXT: "READY"
        - status: "INCOMPLIANT"
          currentStateMessage: "Delete protection is disabled for the Network Firewall."
          remediationMessage: "Enable delete protection in the firewall settings to prevent accidental deletion."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10A2__deleteProtection__c"
              right:
                TEXT: "false"
        - status: "COMPLIANT"
          currentStateMessage: "Delete protection is enabled."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10A2__deleteProtection__c"
              right:
                TEXT: "true"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /ce/ca/aws/network-firewall/firewall-delete-protection/test-data.json
    md5Hash: 5F6F70D7726D7B7241DCF96CE9FCC069
    content: |-
      [
          {
              "CA10A2__disappearanceTime__c": "2026-01-15T10:42:39Z",
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "isDisappeared(CA10A2__disappearanceTime__c)",
                  "conditionIndex": 99,
                  "status": "DISAPPEARED"
              },
              "CA10A2__status__c": "READY",
              "context": {
                  "snapshotTime": "2026-01-15T10:42:39Z"
              },
              "CA10A2__deleteProtection__c": "false",
              "Id": "test1"
          },
          {
              "CA10A2__disappearanceTime__c": null,
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "extract('CA10A2__status__c') != 'READY'",
                  "conditionIndex": 199,
                  "status": "INAPPLICABLE"
              },
              "CA10A2__status__c": "PROVISIONING",
              "context": {
                  "snapshotTime": "2026-01-15T10:42:39Z"
              },
              "CA10A2__deleteProtection__c": "false",
              "Id": "test2"
          },
          {
              "CA10A2__disappearanceTime__c": null,
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "extract('CA10A2__deleteProtection__c') == 'false'",
                  "conditionIndex": 299,
                  "status": "INCOMPLIANT"
              },
              "CA10A2__status__c": "READY",
              "context": {
                  "snapshotTime": "2026-01-15T10:42:39Z"
              },
              "CA10A2__deleteProtection__c": "false",
              "Id": "test3"
          },
          {
              "CA10A2__disappearanceTime__c": null,
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "extract('CA10A2__deleteProtection__c') == 'true'",
                  "conditionIndex": 399,
                  "status": "COMPLIANT"
              },
              "CA10A2__status__c": "READY",
              "context": {
                  "snapshotTime": "2026-01-15T10:42:39Z"
              },
              "CA10A2__deleteProtection__c": "true",
              "Id": "test4"
          }
      ]
  - path: /types/CA10A2__CaAwsNetworkFirewallFirewall__c/object.extracts.yaml
    md5Hash: 1C8CC5F51CDBC5E9DDA99B7A78B23B7A
    content: "---\nextracts:\n# Values: PROVISIONING | DELETING | READY. Not nullable.\
      \ \n  - name: CA10A2__status__c\n    value:\n      FIELD: \n        path: CA10A2__status__c\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10A2__status__c\"\n            currentStateMessage: \"Firewall Status cannot\
      \ be empty. Possible permissions issue with networkfirewall:DescribeFirewall.\"\
      \n# Values: true | false\n# Not nullable\n  - name: CA10A2__deleteProtection__c\n\
      \    value:\n      FIELD: \n        path: CA10A2__deleteProtection__c\n    \
      \    undeterminedIf:\n          noAccessDelegate:\n            path: \"CA10A2__deleteProtection__c\"\
      \n            currentStateMessage: \"Firewall Delete Protection cannot be empty.\
      \ Possible permissions issue with networkfirewall:DescribeFirewall.\"\n# Values:\
      \ true | false\n# Not nullable\n  - name: CA10A2__subnetChangeProtection__c\n\
      \    value:\n      FIELD: \n        path: CA10A2__subnetChangeProtection__c\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10A2__subnetChangeProtection__c\"\n            currentStateMessage: \"Firewall\
      \ Subnet Change Protection cannot be empty. Possible permissions issue with\
      \ networkfirewall:DescribeFirewall.\"\n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "test1",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "isDisappeared(CA10A2__disappearanceTime__c)",
      "conditionIndex" : 99,
      "status" : "DISAPPEARED"
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "extract('CA10A2__status__c') != 'READY'",
      "conditionIndex" : 199,
      "status" : "INAPPLICABLE"
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "extract('CA10A2__deleteProtection__c') == 'false'",
      "conditionIndex" : 299,
      "status" : "INCOMPLIANT"
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "extract('CA10A2__deleteProtection__c') == 'true'",
      "conditionIndex" : 399,
      "status" : "COMPLIANT"
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A2__CaAwsNetworkFirewallFirewall__c()
  RETURNS ARRAY<STRUCT<
      CA10A2__disappearanceTime__c TIMESTAMP,
      CA10A2__status__c STRING,
      CA10A2__deleteProtection__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-15T10:42:39Z")
    },
    "CA10A2__disappearanceTime__c" : new Date("2026-01-15T10:42:39Z"),
    "CA10A2__status__c" : "READY",
    "CA10A2__deleteProtection__c" : "false",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-15T10:42:39Z")
    },
    "CA10A2__status__c" : "PROVISIONING",
    "CA10A2__deleteProtection__c" : "false",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-15T10:42:39Z")
    },
    "CA10A2__status__c" : "READY",
    "CA10A2__deleteProtection__c" : "false",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-15T10:42:39Z")
    },
    "CA10A2__status__c" : "READY",
    "CA10A2__deleteProtection__c" : "true",
    "Id" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10A2__CaAwsNetworkFirewallFirewall__c(
      obj STRUCT<
          CA10A2__disappearanceTime__c TIMESTAMP,
          CA10A2__status__c STRING,
          CA10A2__deleteProtection__c STRING,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10A2__disappearanceTime__c]: ' + obj.CA10A2__disappearanceTime__c);
      if (obj.CA10A2__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10A2__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10A2__status__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10A2__status__c.delegatedTo(CA10A2__status__c).isEmpty()", currentStateMessage: "Firewall Status cannot be empty. Possible permissions issue with networkfirewall:DescribeFirewall.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A2__status__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Status [obj.CA10A2__status__c]: ' + obj.CA10A2__status__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'READY')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10A2__status__c') != 'READY'", currentStateMessage: "The Firewall is not ready.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function fieldChecked7() {
          if (TextLib.isEmpty(obj.CA10A2__deleteProtection__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10A2__deleteProtection__c.delegatedTo(CA10A2__deleteProtection__c).isEmpty()", currentStateMessage: "Firewall Delete Protection cannot be empty. Possible permissions issue with networkfirewall:DescribeFirewall.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A2__deleteProtection__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      references1.push('Delete Protection [obj.CA10A2__deleteProtection__c]: ' + obj.CA10A2__deleteProtection__c);
      try {
          if (TextLib.equal(extract6.call(extract6), 'false')) {
              return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10A2__deleteProtection__c') == 'false'", currentStateMessage: "Delete protection is disabled for the Network Firewall.", currentStateReferences: references1.join('\n'), remediation: "Enable delete protection in the firewall settings to prevent accidental deletion.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[3], conditionIndex:[300..399]
      function fieldChecked10() {
          if (TextLib.isEmpty(obj.CA10A2__deleteProtection__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10A2__deleteProtection__c.delegatedTo(CA10A2__deleteProtection__c).isEmpty()", currentStateMessage: "Firewall Delete Protection cannot be empty. Possible permissions issue with networkfirewall:DescribeFirewall.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A2__deleteProtection__c;
      }
      function extract9() { if (!this.out) { this.out = fieldChecked10(); } return this.out; };
      try {
          if (TextLib.equal(extract9.call(extract9), 'true')) {
              return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10A2__deleteProtection__c') == 'true'", currentStateMessage: "Delete protection is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unexpected values in the field.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.CA10A2__disappearanceTime__c AS CA10A2__disappearanceTime__c,
          sObject.CA10A2__status__c AS CA10A2__status__c,
          sObject.CA10A2__deleteProtection__c AS CA10A2__deleteProtection__c,
          sObject.Id AS Id,
          process_CA10A2__CaAwsNetworkFirewallFirewall__c(
              STRUCT(
                  sObject.CA10A2__disappearanceTime__c AS CA10A2__disappearanceTime__c,
                  sObject.CA10A2__status__c AS CA10A2__status__c,
                  sObject.CA10A2__deleteProtection__c AS CA10A2__deleteProtection__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10A2__CaAwsNetworkFirewallFirewall__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
