---
policy: /ce/ca/google/project/project-with-legacy-network
logic: /ce/ca/google/project/project-with-legacy-network/prod.logic.yaml
executionTime: 2025-04-24T23:47:20.372869228Z
rows:
  - id: a4p361
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__Google_GCE_Networks__r.has(INCOMPLIANT)
      actual: CA10__Google_GCE_Networks__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: a4p02
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: a4p0e3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/project/project-with-legacy-network/policy.yaml
    md5Hash: 4865B4D75173AC2944FD896B102F3A19
    content: "---\nnames: \n  full: \"Google Project has a legacy network\"\n  contextual:\
      \ \"Project has a legacy network\"\ndescription: \"In order to prevent use of\
      \ legacy networks, a project should not have a legacy \\\n network configured.\
      \ As of now, Legacy Networks are gradually being phased out, and you can \\\n\
      \ no longer create projects with them. This recommendation is to check older\
      \ projects to ensure \\\n that they are not using Legacy Networks.\"\ntype:\
      \ COMPLIANCE_POLICY\ncategories:\n  - \"RELIABILITY\"\nframeworkMappings:\n\
      \  - /frameworks/cis-gcp-v3.0.0/03/02\n  - /frameworks/cloudaware/resource-reliability/infrastructure-modernization\n\
      similarPolicies:\n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity/knowledge-base/gcp/CloudVPC/legacy-vpc-in-use.html\"\
      \n      name: \"Check for Legacy Networks\"\n"
  - path: /ce/ca/google/project/project-with-legacy-network/prod.logic.yaml
    md5Hash: 4C1B1B0702938232BBB0E8A28CA67B3C
    content: "---\ninputType: \"CA10__CaGoogleProject__c\"\ntestData:\n  - file: test-data.json\n\
      conditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"The Project\
      \ has networks in the legacy mode.\"\n    remediationMessage: \"Delete the networks\
      \ in the legacy mode.\"\n    check:\n      RELATED_LIST_HAS:\n        status:\
      \ \"INCOMPLIANT\"\n        relationshipName: \"CA10__Google_GCE_Networks__r\"\
      \ \notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage: \"The Project\
      \ doesn't have networks in the legacy mode.\"\nrelatedLists:\n  - relationshipName:\
      \ \"CA10__Google_GCE_Networks__r\"\n    importExtracts:\n      - file: /types/CA10__CaGoogleGceNetwork__c/object.extracts.yaml\n\
      \    conditions:\n      - status: \"INCOMPLIANT\"\n        currentStateMessage:\
      \ \"This is a legacy network.\"\n        check:\n          IS_EQUAL:\n     \
      \       left:\n              EXTRACT: \"CA10__autoCreationSubnetworksMode__c\"\
      \n            right:\n              TEXT: 'legacy'\n    otherwise:\n      status:\
      \ \"COMPLIANT\"\n      currentStateMessage: \"This is not a legacy network.\""
  - path: /types/CA10__CaGoogleGceNetwork__c/object.extracts.yaml
    md5Hash: 8F9138803D14A08C803D065164BFC0CC
    content: "---\nextracts:\n  - name: \"networkName\"\n    value: \n      FIELD:\n\
      \        path: \"Name\"\n        undeterminedIf:\n          isEmpty:  \"Name\
      \ should not be empty\"\n  - name: \"CA10__autoCreationSubnetworksMode__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10__autoCreationSubnetworksMode__c\"\
      \n        undeterminedIf:\n          isEmpty:  \"Auto creation subnetworks mode\
      \ should not be empty\""
  - path: /ce/ca/google/project/project-with-legacy-network/test-data.json
    md5Hash: A73EDFCFCAEA002EB1477ADC173E0CC5
    content: |
      [
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "CA10__Google_GCE_Networks__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T19:20:52Z" },
          "Id": "a4p361",
          "CA10__Google_GCE_Networks__r": [
            {
              "Id": "a4b0e11",
              "CA10__disappearanceTime__c": null,
              "CA10__autoCreationSubnetworksMode__c": "custom",
              "CA10__project__c": "a4p361"
            },
            {
              "Id": "a4b3612",
              "CA10__disappearanceTime__c": null,
              "CA10__autoCreationSubnetworksMode__c": "legacy",
              "CA10__project__c": "a4p361"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T19:20:52Z" },
          "Id": "a4p02",
          "CA10__Google_GCE_Networks__r": []
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T19:20:52Z" },
          "Id": "a4p0e3",
          "CA10__Google_GCE_Networks__r": [
              {
                  "Id": "a4b0e15",
                  "CA10__disappearanceTime__c": null,
                  "CA10__autoCreationSubnetworksMode__c": "custom",
                  "CA10__project__c": "a4p0e3"
                }
          ]
        }
      ]
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" : "a4p361",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Google_GCE_Networks__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4p02",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "a4p0e3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleProject__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a4p361"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a4p02"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a4p0e3"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceNetwork__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__autoCreationSubnetworksMode__c STRING,
      CA10__project__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a4b0e11",
    "CA10__autoCreationSubnetworksMode__c" : "custom",
    "CA10__project__c" : "a4p361"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a4b3612",
    "CA10__autoCreationSubnetworksMode__c" : "legacy",
    "CA10__project__c" : "a4p361"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a4b0e15",
    "CA10__autoCreationSubnetworksMode__c" : "custom",
    "CA10__project__c" : "a4p0e3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleProject__c(
      obj STRUCT<
          Id STRING,
          CA10__Google_GCE_Networks__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__autoCreationSubnetworksMode__c STRING,
              CA10__project__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]
      if (false) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__Google_GCE_Networks__r_INCOMPLIANT2 = 0;
      if (obj.CA10__Google_GCE_Networks__r != null) {
          for (var i3 = 0; i3 < obj.CA10__Google_GCE_Networks__r.length; i3++) {
              if (obj.CA10__Google_GCE_Networks__r[i3].result.status == 'INCOMPLIANT') {
                  count_CA10__Google_GCE_Networks__r_INCOMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__Google_GCE_Networks__r] ' + (count_CA10__Google_GCE_Networks__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__Google_GCE_Networks__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__Google_GCE_Networks__r.has(INCOMPLIANT)", currentStateMessage: "The Project has networks in the legacy mode.", currentStateReferences: references1.join('\n'), remediation: "Delete the networks in the legacy mode.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The Project doesn't have networks in the legacy mode.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Google_GCE_Networks__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__autoCreationSubnetworksMode__c STRING,
          CA10__project__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 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));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Google [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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__autoCreationSubnetworksMode__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__autoCreationSubnetworksMode__c.isEmpty()", currentStateMessage: "Auto creation subnetworks mode should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__autoCreationSubnetworksMode__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Auto Create Subnetworks Mode [obj.CA10__autoCreationSubnetworksMode__c]: ' + obj.CA10__autoCreationSubnetworksMode__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'legacy')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__autoCreationSubnetworksMode__c') == 'legacy'", currentStateMessage: "This is a legacy network.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This is not a legacy network.", 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,
          `CA10__Google_GCE_Networks__r`.arr AS CA10__Google_GCE_Networks__r,
          process_CA10__CaGoogleProject__c(
              STRUCT(
                  sObject.Id AS Id,
                  `CA10__Google_GCE_Networks__r`.arr AS CA10__Google_GCE_Networks__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleProject__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__project__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__autoCreationSubnetworksMode__c AS CA10__autoCreationSubnetworksMode__c,
                      sObject.CA10__project__c AS CA10__project__c,
                      process_CA10__Google_GCE_Networks__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__autoCreationSubnetworksMode__c AS CA10__autoCreationSubnetworksMode__c,
                              sObject.CA10__project__c AS CA10__project__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaGoogleGceNetwork__c()) AS sObject
          GROUP BY sObject.CA10__project__c
      ) AS `CA10__Google_GCE_Networks__r`
          ON sObject.Id = `CA10__Google_GCE_Networks__r`.CA10__project__c
  ) sObject ON sObject.Id = expectedResult.Id;
