---
policy: /ce/ca/aws/vpc/flow-logs
logic: /ce/ca/aws/vpc/flow-logs/prod.logic.yaml
executionTime: 2025-04-24T23:45:13.511155769Z
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: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__AWS_VPC_Flow_Logs__r.hasNo(COMPLIANT)
      actual: CA10__AWS_VPC_Flow_Logs__r.hasNo(COMPLIANT)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__AWS_VPC_Flow_Logs__r.has(COMPLIANT)
      actual: CA10__AWS_VPC_Flow_Logs__r.has(COMPLIANT)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/vpc/flow-logs/policy.yaml
    md5Hash: 98648B19C189638D093C94D96B1BEB29
    content: |
      ---
      names:
        full: AWS VPC Flow Logs are not enabled
        contextual: Flow Logs are not enabled
      description: "VPC Flow Logs is a feature that enables you to capture information about\
        \ the IP traffic going to and from network interfaces in your VPC. After you've\
        \ created a flow log, you can view and retrieve its data in Amazon CloudWatch Logs.\
        \ It is recommended that VPC Flow Logs be enabled for packet 'Rejects' for VPCs."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
        - RELIABILITY
      frameworkMappings:
        - "/frameworks/cis-aws-v5.0.0/03/07"
        - "/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration"
        - "/frameworks/aws-fsbp-v1.0.0/ec2/06"
      similarPolicies:
        internal:
          - dec-x-9c041667
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/VPC/vpc-flow-logs-enabled.html
            name: VPC Flow Logs Enabled
  - path: /ce/ca/aws/vpc/flow-logs/prod.logic.yaml
    md5Hash: ADB091B0EC642C429B6ACCCAE30C32D2
    content: |-
      ---
      inputType: "CA10__CaAwsVpc__c"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "VPC flow logging is disabled."
          remediationMessage: "Consider enabling VPC flow logging."
          check:
            RELATED_LIST_HAS_NO:
              status: "COMPLIANT"
              relationshipName: "CA10__AWS_VPC_Flow_Logs__r"
        - status: "COMPLIANT"
          currentStateMessage: "VPC flow logging is enabled."
          check:
            RELATED_LIST_HAS:
              status: "COMPLIANT"
              relationshipName: "CA10__AWS_VPC_Flow_Logs__r"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the fields."
      relatedLists:
        - relationshipName: "CA10__AWS_VPC_Flow_Logs__r"
          conditions: []
          otherwise:
            status: "COMPLIANT"
            currentStateMessage: "VPC flow logging is enabled."
  - path: /ce/ca/aws/vpc/flow-logs/test-data.json
    md5Hash: 31DE834F1018FB3952D3AE87F3953DEB
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-28T17:35:50Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2024-05-22T17:29:41Z",
              "CA10__AWS_VPC_Flow_Logs__r": []
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "CA10__AWS_VPC_Flow_Logs__r.hasNo(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-28T17:35:50Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__AWS_VPC_Flow_Logs__r": []
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "CA10__AWS_VPC_Flow_Logs__r.has(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-28T17:35:50Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__AWS_VPC_Flow_Logs__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__vpc__c": "test3"
                  }
              ]
          }
      ]
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" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__AWS_VPC_Flow_Logs__r.hasNo(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__AWS_VPC_Flow_Logs__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsVpc__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-05-28T17:35:50Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2024-05-22T17:29:41Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-28T17:35:50Z")
    },
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-28T17:35:50Z")
    },
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsVpcFlowLog__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__vpc__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-05-28T17:35:50Z")
    },
    "Id" : "test3_1",
    "CA10__vpc__c" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsVpc__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__AWS_VPC_Flow_Logs__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__vpc__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};
      }
      var count_CA10__AWS_VPC_Flow_Logs__r_COMPLIANT2 = 0;
      if (obj.CA10__AWS_VPC_Flow_Logs__r != null) {
          for (var i3 = 0; i3 < obj.CA10__AWS_VPC_Flow_Logs__r.length; i3++) {
              if (obj.CA10__AWS_VPC_Flow_Logs__r[i3].result.status == 'COMPLIANT') {
                  count_CA10__AWS_VPC_Flow_Logs__r_COMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__AWS_VPC_Flow_Logs__r] ' + (count_CA10__AWS_VPC_Flow_Logs__r_COMPLIANT2 == 0 ? 'does not have' : 'has') + ' objects in COMPLIANT status');
      if (count_CA10__AWS_VPC_Flow_Logs__r_COMPLIANT2 == 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__AWS_VPC_Flow_Logs__r.hasNo(COMPLIANT)", currentStateMessage: "VPC flow logging is disabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling VPC flow logging.", runtimeError: null};
      }
      var count_CA10__AWS_VPC_Flow_Logs__r_COMPLIANT2 = 0;
      if (obj.CA10__AWS_VPC_Flow_Logs__r != null) {
          for (var i4 = 0; i4 < obj.CA10__AWS_VPC_Flow_Logs__r.length; i4++) {
              if (obj.CA10__AWS_VPC_Flow_Logs__r[i4].result.status == 'COMPLIANT') {
                  count_CA10__AWS_VPC_Flow_Logs__r_COMPLIANT2 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      if (count_CA10__AWS_VPC_Flow_Logs__r_COMPLIANT2 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "CA10__AWS_VPC_Flow_Logs__r.has(COMPLIANT)", currentStateMessage: "VPC flow logging is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_VPC_Flow_Logs__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__vpc__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: "VPC flow logging is enabled.", 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,
          `CA10__AWS_VPC_Flow_Logs__r`.arr AS CA10__AWS_VPC_Flow_Logs__r,
          process_CA10__CaAwsVpc__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  `CA10__AWS_VPC_Flow_Logs__r`.arr AS CA10__AWS_VPC_Flow_Logs__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsVpc__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__vpc__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__vpc__c AS CA10__vpc__c,
                      process_CA10__AWS_VPC_Flow_Logs__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__vpc__c AS CA10__vpc__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsVpcFlowLog__c()) AS sObject
          GROUP BY sObject.CA10__vpc__c
      ) AS `CA10__AWS_VPC_Flow_Logs__r`
          ON sObject.Id = `CA10__AWS_VPC_Flow_Logs__r`.CA10__vpc__c
  ) sObject ON sObject.Id = expectedResult.Id;
