---
policy: /ce/ca/aws/vpc/network-acl-unused
logic: /ce/ca/aws/vpc/network-acl-unused/prod.logic.yaml
executionTime: 2025-08-29T17:47:02.473732894Z
generationMs: 55
executionMs: 698
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__isDefault__c') == true
      actual: extract('CA10__isDefault__c') == true
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__networkAclAssociations__r.hasNo(COMPLIANT)
      actual: CA10__networkAclAssociations__r.hasNo(COMPLIANT)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/vpc/network-acl-unused/policy.yaml
    md5Hash: 0977F0CA3F13D3063FAD1DC576F9BDD9
    content: "---\nnames:\n  full: AWS VPC Network ACL is unused\n  contextual: Network\
      \ ACL is unused\ndescription: >\n  Network NACLs that are not associated with\
      \ any subnets are considered unused. \n  While unused NACLs do not incur direct\
      \ costs, they can represent a security \n  risk if they contain misconfigured\
      \ rules and are later associated with a subnet. \ntype: COMPLIANCE_POLICY\n\
      categories:\n  - RELIABILITY\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-reliability/system-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/ec2/16\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[EC2.16] Unused Network Access Control Lists should be removed\"\
      \n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/ec2-controls.html#ec2-16\"\
      \n"
  - path: /ce/ca/aws/vpc/network-acl-unused/prod.logic.yaml
    md5Hash: 1C1836DEE3652858165214316D07A318
    content: |-
      inputType: "CA10__CaAwsNetworkAcl__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsNetworkAcl__c/object.extracts.yaml"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "This is a default Network ACL and cannot be deleted."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__isDefault__c"
              right:
                BOOLEAN: true
        - status: "INCOMPLIANT"
          currentStateMessage: "This Network ACL is not associated with any subnets and is considered unused."
          remediationMessage: "Consider deleting the unused Network ACL."
          check:
            RELATED_LIST_HAS_NO:
              relationshipName: "CA10__networkAclAssociations__r"
              status: "COMPLIANT"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "This Network ACL is associated with at least one subnet."
      relatedLists:
        - relationshipName: "CA10__networkAclAssociations__r"
          conditions: []
          otherwise:
            status: "COMPLIANT"
            currentStateMessage: "This is a subnet association."
  - path: /types/CA10__CaAwsNetworkAcl__c/object.extracts.yaml
    md5Hash: 5AF832994B8F0BBFF37719296CCB0AA0
    content: "---\nextracts:\n# Checkbox. Can't have no access, ec2:DescribeNetworkAcls\n\
      \  - name: CA10__isDefault__c\n    value: \n      FIELD:\n        path: CA10__isDefault__c\n"
  - path: /ce/ca/aws/vpc/network-acl-unused/test-data.json
    md5Hash: 4C568E2DE64A39BFECB5EB24C5CB0B00
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-29T11:12:55Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-08-20T01:28:23Z",
              "CA10__isDefault__c": false,
              "CA10__networkAclAssociations__r": [
                  {
                      "Id": "test1_1",
                      "CA10__disappearanceTime__c": "2025-08-20T01:28:23Z",
                      "CA10__networkAcl__c": "test1"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__isDefault__c') == true",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-29T11:12:55Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__isDefault__c": true,
              "CA10__networkAclAssociations__r": [
                  {
                      "Id": "test2_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__networkAcl__c": "test2"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "CA10__networkAclAssociations__r.hasNo(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-29T11:12:55Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__isDefault__c": false,
              "CA10__networkAclAssociations__r": []
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-29T11:12:55Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__isDefault__c": false,
              "CA10__networkAclAssociations__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__networkAcl__c": "test4"
                  }
              ]
          }
      ]
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" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__isDefault__c') == true",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__networkAclAssociations__r.hasNo(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsNetworkAcl__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__isDefault__c BOOLEAN,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-08-20T01:28:23Z"),
    "CA10__isDefault__c" : false
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test2",
    "CA10__isDefault__c" : true
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test3",
    "CA10__isDefault__c" : false
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test4",
    "CA10__isDefault__c" : false
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsNetworkAclAssociation__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__networkAcl__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test1_1",
    "CA10__disappearanceTime__c" : new Date("2025-08-20T01:28:23Z"),
    "CA10__networkAcl__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test2_1",
    "CA10__networkAcl__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test4_1",
    "CA10__networkAcl__c" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsNetworkAcl__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__isDefault__c BOOLEAN,
          CA10__networkAclAssociations__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__networkAcl__c STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError 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 references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function extract3() { if (!this.out) { this.out = obj.CA10__isDefault__c; } return this.out; };
      references1.push('Is Default [obj.CA10__isDefault__c]: ' + obj.CA10__isDefault__c);
      if (extract3.call(extract3) == true) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__isDefault__c') == true", currentStateMessage: "This is a default Network ACL and cannot be deleted.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__networkAclAssociations__r_COMPLIANT5 = 0;
      if (obj.CA10__networkAclAssociations__r != null) {
          for (var i6 = 0; i6 < obj.CA10__networkAclAssociations__r.length; i6++) {
              if (obj.CA10__networkAclAssociations__r[i6].result.status == 'COMPLIANT') {
                  count_CA10__networkAclAssociations__r_COMPLIANT5 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10__networkAclAssociations__r] ' + (count_CA10__networkAclAssociations__r_COMPLIANT5 == 0 ? 'does not have' : 'has') + ' objects in COMPLIANT status');
      if (count_CA10__networkAclAssociations__r_COMPLIANT5 == 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__networkAclAssociations__r.hasNo(COMPLIANT)", currentStateMessage: "This Network ACL is not associated with any subnets and is considered unused.", currentStateReferences: references1.join('\n'), remediation: "Consider deleting the unused Network ACL.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "This Network ACL is associated with at least one subnet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__networkAclAssociations__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__networkAcl__c 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 references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "This is a subnet association.", 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.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__isDefault__c AS CA10__isDefault__c,
          `CA10__networkAclAssociations__r`.arr AS CA10__networkAclAssociations__r,
          process_CA10__CaAwsNetworkAcl__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__isDefault__c AS CA10__isDefault__c,
                  `CA10__networkAclAssociations__r`.arr AS CA10__networkAclAssociations__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsNetworkAcl__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__networkAcl__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__networkAcl__c AS CA10__networkAcl__c,
                      process_CA10__networkAclAssociations__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__networkAcl__c AS CA10__networkAcl__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsNetworkAclAssociation__c()) AS sObject
          GROUP BY sObject.CA10__networkAcl__c
      ) AS `CA10__networkAclAssociations__r`
          ON sObject.Id = `CA10__networkAclAssociations__r`.CA10__networkAcl__c
  ) sObject ON sObject.Id = expectedResult.Id;
