---
policy: /ce/ca/google/vpc/gce-ip-address-unused
logic: /ce/ca/google/vpc/gce-ip-address-unused/prod.logic.yaml
executionTime: 2025-10-01T12:51:23.293150649Z
generationMs: 62
executionMs: 644
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: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__status__c') != 'RESERVED'
      actual: extract('CA10__status__c') != 'RESERVED'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__addressType__c') == 'EXTERNAL'
      actual: extract('CA10__addressType__c') == 'EXTERNAL'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__addressType__c') == 'INTERNAL'
      actual: extract('CA10__addressType__c') == 'INTERNAL'
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: extract('CA10__addressType__c').isEmpty()
      actual: extract('CA10__addressType__c').isEmpty()
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/vpc/gce-ip-address-unused/policy.yaml
    md5Hash: 7E780A31350C1290A4636B72F04F7976
    content: "---\nnames:\n  full: \"Google GCE IP Address is unused\"\n  contextual:\
      \ \"GCE IP Address is unused\"\ndescription: >\n  Ensure that all static IP\
      \ addresses in your Google Cloud Platform project are \n  associated with a\
      \ running resource. Unused external static IP addresses can incur unnecessary\
      \ costs \n  and may pose a security risk if they are inadvertently attached\
      \ to a resource in the future.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n \
      \ - \"COST\"\n  - \"SECURITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/cost-efficiency-and-optimization/waste-reduction\"\
      \n  - \"/frameworks/cloudaware/resource-security/public-and-anonymous-access\""
  - path: /ce/ca/google/vpc/gce-ip-address-unused/prod.logic.yaml
    md5Hash: EABA6DD16C6A723BB5BAC78F8ED005F5
    content: |-
      ---
      inputType: "CA10__CaGoogleGceStaticAddress__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaGoogleGceStaticAddress__c/object.extracts.yaml
      conditions:
        - status: "COMPLIANT"
          currentStateMessage: "The GCE IP Address is not in Reserved status."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__status__c"
              right:
                TEXT: "RESERVED"
        - status: "INCOMPLIANT"
          currentStateMessage: "The External GCE IP Address is reserved but not in use."
          remediationMessage: "Consider deleting the unused IP address to reduce costs,\
            \ environment clutter, and security exposure."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__addressType__c"
              right:
                TEXT: "EXTERNAL"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Internal GCE IP Address is reserved but not in use."
          remediationMessage: "Consider deleting the unused IP address to reduce costs,\
            \ environment clutter, and security exposure."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__addressType__c"
              right:
                TEXT: "INTERNAL"
        - status: "INCOMPLIANT"
          currentStateMessage: "The External GCE IP Address is reserved but not in use."
          remediationMessage: "Consider deleting the unused IP address to reduce costs,\
            \ environment clutter, and security exposure."
          check:
            IS_EMPTY:
              arg:
                EXTRACT: "CA10__addressType__c"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the fields."
  - path: /ce/ca/google/vpc/gce-ip-address-unused/test-data.json
    md5Hash: EBDB711EE89297EE9C970D2FD522FD59
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-18T22:43:50Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-09-18T10:21:07Z",
              "CA10__status__c": "IN_USE",
              "CA10__addressType__c": "EXTERNAL"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__status__c') != 'RESERVED'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-18T22:43:50Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "IN_USE",
              "CA10__addressType__c": "EXTERNAL"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__addressType__c') == 'EXTERNAL'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-18T22:43:50Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "RESERVED",
              "CA10__addressType__c": "EXTERNAL"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10__addressType__c') == 'INTERNAL'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-18T22:43:50Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "RESERVED",
              "CA10__addressType__c": "INTERNAL"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "extract('CA10__addressType__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-18T22:43:50Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "RESERVED",
              "CA10__addressType__c": null
          }
      ]
  - path: /types/CA10__CaGoogleGceStaticAddress__c/object.extracts.yaml
    md5Hash: E8EB0D6F504436FA35D7861DF7744D9B
    content: "---\nextracts:\n# Values: RESERVING | RESERVED | IN_USE. Not nullable.\
      \ Can't have no access, retrieved via compute.addresses.list\n  - name: \"CA10__status__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__status__c\"\n# Values: EXTERNAL\
      \ | INTERNAL. Nullable (which is equal to EXTERNAL). Can't have no access, retrieved\
      \ via compute.addresses.list\n  - name: \"CA10__addressType__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__addressType__c\"\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" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__status__c') != 'RESERVED'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__addressType__c') == 'EXTERNAL'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__addressType__c') == 'INTERNAL'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "extract('CA10__addressType__c').isEmpty()",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceStaticAddress__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__addressType__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-18T22:43:50Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-09-18T10:21:07Z"),
    "CA10__status__c" : "IN_USE",
    "CA10__addressType__c" : "EXTERNAL"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-18T22:43:50Z")
    },
    "Id" : "test2",
    "CA10__status__c" : "IN_USE",
    "CA10__addressType__c" : "EXTERNAL"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-18T22:43:50Z")
    },
    "Id" : "test3",
    "CA10__status__c" : "RESERVED",
    "CA10__addressType__c" : "EXTERNAL"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-18T22:43:50Z")
    },
    "Id" : "test4",
    "CA10__status__c" : "RESERVED",
    "CA10__addressType__c" : "INTERNAL"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-18T22:43:50Z")
    },
    "Id" : "test5",
    "CA10__status__c" : "RESERVED",
    "CA10__addressType__c" : null
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleGceStaticAddress__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__addressType__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));
          };
          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 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 extract3() { if (!this.out) { this.out = obj.CA10__status__c; } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      if (TextLib.notEqual(extract3.call(extract3), 'RESERVED')) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'RESERVED'", currentStateMessage: "The GCE IP Address is not in Reserved status.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__addressType__c; } return this.out; };
      references1.push('Address Type [obj.CA10__addressType__c]: ' + obj.CA10__addressType__c);
      if (TextLib.equal(extract6.call(extract6), 'EXTERNAL')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__addressType__c') == 'EXTERNAL'", currentStateMessage: "The External GCE IP Address is reserved but not in use.", currentStateReferences: references1.join('\n'), remediation: "Consider deleting the unused IP address to reduce costs, environment clutter, and security exposure.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__addressType__c; } return this.out; };
      if (TextLib.equal(extract9.call(extract9), 'INTERNAL')) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__addressType__c') == 'INTERNAL'", currentStateMessage: "The Internal GCE IP Address is reserved but not in use.", currentStateReferences: references1.join('\n'), remediation: "Consider deleting the unused IP address to reduce costs, environment clutter, and security exposure.", runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract12() { if (!this.out) { this.out = obj.CA10__addressType__c; } return this.out; };
      if (TextLib.isEmpty(extract12.call(extract12))) {
          return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10__addressType__c').isEmpty()", currentStateMessage: "The External GCE IP Address is reserved but not in use.", currentStateReferences: references1.join('\n'), remediation: "Consider deleting the unused IP address to reduce costs, environment clutter, and security exposure.", runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", 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__status__c AS CA10__status__c,
          sObject.CA10__addressType__c AS CA10__addressType__c,
          process_CA10__CaGoogleGceStaticAddress__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__addressType__c AS CA10__addressType__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleGceStaticAddress__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
