--- policy: /ce/ca/aws/workspaces/workspace-unused logic: /ce/ca/aws/workspaces/workspace-unused/prod.logic.yaml executionTime: 2026-02-10T22:33:23.288513525Z generationMs: 53 executionMs: 649 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__state__c') != 'AVAILABLE' && extract('CA10__state__c') != 'STOPPED' actual: extract('CA10__state__c') != 'AVAILABLE' && extract('CA10__state__c') != 'STOPPED' runtimeError: {} - id: test3 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 299 actual: 299 conditionText: expected: extract('CA10__lastKnownUserConnectionTimestamp__c').isEmpty() actual: extract('CA10__lastKnownUserConnectionTimestamp__c').isEmpty() runtimeError: {} - id: test4 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 399 actual: 399 conditionText: expected: extract('CA10__lastKnownUserConnectionTimestamp__c').beyondLastDays(30) actual: extract('CA10__lastKnownUserConnectionTimestamp__c').beyondLastDays(30) runtimeError: {} - id: test5 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 400 actual: 400 conditionText: expected: otherwise actual: otherwise runtimeError: {} usedFiles: - path: /ce/ca/aws/workspaces/workspace-unused/policy.yaml md5Hash: D04FBBA061DB0A01179EE0D04F75D76D content: "---\nnames:\n full: \"AWS WorkSpace is unused\"\n contextual: \"WorkSpace\ \ is unused\"\ndescription: >\n This policy identifies AWS WorkSpaces that\ \ have not been used for an extended \n period. A WorkSpace is considered unused\ \ if it is running and there has been \n no user connections for the last 30\ \ days.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n - \"COST\"\nframeworkMappings:\n\ \ - \"/frameworks/cloudaware/cost-efficiency-and-optimization/waste-reduction\"" - path: /ce/ca/aws/workspaces/workspace-unused/prod.logic.yaml md5Hash: D3854921B10D1922603282CFBCF5ED9E content: | --- inputType: "CA10__CaAwsWorkspace__c" testData: - file: "test-data.json" importExtracts: - file: "/types/CA10__CaAwsWorkspace__c/object.extracts.yaml" conditions: - status: "INAPPLICABLE" currentStateMessage: "The WorkSpace is in a transient state." check: AND: args: - NOT_EQUAL: left: EXTRACT: "CA10__state__c" right: TEXT: "AVAILABLE" - NOT_EQUAL: left: EXTRACT: "CA10__state__c" right: TEXT: "STOPPED" - status: "INCOMPLIANT" currentStateMessage: "The last user connection time for the WorkSpace is unknown." remediationMessage: "Terminate the unused WorkSpace." check: IS_EMPTY: arg: EXTRACT: "CA10__lastKnownUserConnectionTimestamp__c" - status: "INCOMPLIANT" currentStateMessage: "The WorkSpace has not been used in the last 30 days." remediationMessage: "Terminate the unused WorkSpace." check: IS_BEYOND_LAST_DAYS: offsetDays: 30 arg: EXTRACT: "CA10__lastKnownUserConnectionTimestamp__c" otherwise: status: "COMPLIANT" currentStateMessage: "The WorkSpace has been used within the last 30 days." - path: /ce/ca/aws/workspaces/workspace-unused/test-data.json md5Hash: 5D59FA365188C2CECFF9D5602189E3D5 content: |- [ { "expectedResult": { "status": "DISAPPEARED", "conditionIndex": "99", "conditionText": "isDisappeared(CA10__disappearanceTime__c)", "runtimeError": null }, "context": { "snapshotTime": "2025-09-30T23:23:21Z" }, "Id": "test1", "CA10__disappearanceTime__c": "2025-09-30T23:23:21Z", "CA10__state__c": "ERROR", "CA10__lastKnownUserConnectionTimestamp__c": null }, { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "199", "conditionText": "extract('CA10__state__c') != 'AVAILABLE' && extract('CA10__state__c') != 'STOPPED'", "runtimeError": null }, "context": { "snapshotTime": "2025-09-30T23:23:21Z" }, "Id": "test2", "CA10__disappearanceTime__c": null, "CA10__state__c": "ERROR", "CA10__lastKnownUserConnectionTimestamp__c": null }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "299", "conditionText": "extract('CA10__lastKnownUserConnectionTimestamp__c').isEmpty()", "runtimeError": null }, "context": { "snapshotTime": "2025-09-30T23:23:21Z" }, "Id": "test3", "CA10__disappearanceTime__c": null, "CA10__state__c": "STOPPED", "CA10__lastKnownUserConnectionTimestamp__c": null }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "399", "conditionText": "extract('CA10__lastKnownUserConnectionTimestamp__c').beyondLastDays(30)", "runtimeError": null }, "context": { "snapshotTime": "2025-09-30T23:23:21Z" }, "Id": "test4", "CA10__disappearanceTime__c": null, "CA10__state__c": "AVAILABLE", "CA10__lastKnownUserConnectionTimestamp__c": "2025-07-17T19:03:50Z" }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "400", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2025-09-30T23:23:21Z" }, "Id": "test5", "CA10__disappearanceTime__c": null, "CA10__state__c": "STOPPED", "CA10__lastKnownUserConnectionTimestamp__c": "2025-09-22T14:07:34Z" } ] - path: /types/CA10__CaAwsWorkspace__c/object.extracts.yaml md5Hash: 653A7214D9FA947DB5A00F602EFFCB5C content: "---\nextracts:\n# Nullable.\n - name: CA10__lastKnownUserConnectionTimestamp__c\n\ \ value:\n FIELD: \n path: CA10__lastKnownUserConnectionTimestamp__c\n\ # Not nullable. Can't have no access, retrieved via workspaces:DescribeWorkspaces\n\ \ - name: CA10__state__c\n value:\n FIELD: \n path: CA10__state__c\n\ \ undeterminedIf:\n isEmpty: \"Corrupted data. Workspace state\ \ cannot be empty.\"\n# Values: AUTO_STOP | ALWAYS_ON | MANUAL. Not nullable.\ \ Can't have no access, retrieved via workspaces:DescribeWorkspaces\n - name:\ \ CA10__runningMode__c\n value:\n FIELD: \n path: CA10__runningMode__c\n\ \ undeterminedIf:\n isEmpty: \"Corrupted data. Workspace Running\ \ Mode cannot be empty.\"\n# Nullable.\n - name: CA10__rootVolumeEncryptionEnabled__c\n\ \ value:\n FIELD: \n path: CA10__rootVolumeEncryptionEnabled__c\n\ # Nullable.\n - name: CA10__userVolumeEncryptionEnabled__c\n value:\n \ \ FIELD: \n path: CA10__userVolumeEncryptionEnabled__c" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> 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__state__c') != 'AVAILABLE' && extract('CA10__state__c') != 'STOPPED'", "runtimeError" : null } }, { "Id" : "test3", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "299", "conditionText" : "extract('CA10__lastKnownUserConnectionTimestamp__c').isEmpty()", "runtimeError" : null } }, { "Id" : "test4", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "399", "conditionText" : "extract('CA10__lastKnownUserConnectionTimestamp__c').beyondLastDays(30)", "runtimeError" : null } }, { "Id" : "test5", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "400", "conditionText" : "otherwise", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsWorkspace__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-09-30T23:23:21Z") }, "CA10__disappearanceTime__c" : new Date("2025-09-30T23:23:21Z"), "CA10__state__c" : "ERROR", "Id" : "test1" }, { "context" : { "snapshotTime" : new Date("2025-09-30T23:23:21Z") }, "CA10__state__c" : "ERROR", "Id" : "test2" }, { "context" : { "snapshotTime" : new Date("2025-09-30T23:23:21Z") }, "CA10__state__c" : "STOPPED", "Id" : "test3" }, { "context" : { "snapshotTime" : new Date("2025-09-30T23:23:21Z") }, "CA10__state__c" : "AVAILABLE", "CA10__lastKnownUserConnectionTimestamp__c" : new Date("2025-07-17T19:03:50Z"), "Id" : "test4" }, { "context" : { "snapshotTime" : new Date("2025-09-30T23:23:21Z") }, "CA10__state__c" : "STOPPED", "CA10__lastKnownUserConnectionTimestamp__c" : new Date("2025-09-22T14:07:34Z"), "Id" : "test5" } ]; """; CREATE TEMP FUNCTION process_CA10__CaAwsWorkspace__c( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__state__c STRING, CA10__lastKnownUserConnectionTimestamp__c TIMESTAMP, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT 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 IsEmptyLib = new function () { this.simpleIsEmpty = function(arg) { return arg == null; }; this.simpleIsNotEmpty = function(arg) { return arg != null; }; }(); var todayMinus30Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (-30 * 86400000); 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 fieldChecked4() { if (TextLib.isEmpty(obj.CA10__state__c)) { throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__state__c.isEmpty()", currentStateMessage: "Corrupted data. Workspace state cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__state__c; } function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; }; references1.push('State [obj.CA10__state__c]: ' + obj.CA10__state__c); try { if (TextLib.notEqual(extract3.call(extract3), 'AVAILABLE') && TextLib.notEqual(extract3.call(extract3), 'STOPPED')) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__state__c') != 'AVAILABLE' && extract('CA10__state__c') != 'STOPPED'", currentStateMessage: "The WorkSpace is in a transient state.", 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 extract7() { if (!this.out) { this.out = obj.CA10__lastKnownUserConnectionTimestamp__c; } return this.out; }; references1.push('Last Known User Connection Timestamp [obj.CA10__lastKnownUserConnectionTimestamp__c]: ' + obj.CA10__lastKnownUserConnectionTimestamp__c); if (IsEmptyLib.simpleIsEmpty(extract7.call(extract7))) { return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__lastKnownUserConnectionTimestamp__c').isEmpty()", currentStateMessage: "The last user connection time for the WorkSpace is unknown.", currentStateReferences: references1.join('\n'), remediation: "Terminate the unused WorkSpace.", runtimeError: null}; } // condition[3], conditionIndex:[300..399] function extract10() { if (!this.out) { this.out = obj.CA10__lastKnownUserConnectionTimestamp__c; } return this.out; }; if (extract10.call(extract10) != null && extract10.call(extract10).getTime() < todayMinus30Day) { return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__lastKnownUserConnectionTimestamp__c').beyondLastDays(30)", currentStateMessage: "The WorkSpace has not been used in the last 30 days.", currentStateReferences: references1.join('\n'), remediation: "Terminate the unused WorkSpace.", runtimeError: null}; } return {status: 'COMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "The WorkSpace has been used within the last 30 days.", 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__state__c AS CA10__state__c, sObject.CA10__lastKnownUserConnectionTimestamp__c AS CA10__lastKnownUserConnectionTimestamp__c, sObject.Id AS Id, process_CA10__CaAwsWorkspace__c( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__state__c AS CA10__state__c, sObject.CA10__lastKnownUserConnectionTimestamp__c AS CA10__lastKnownUserConnectionTimestamp__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10__CaAwsWorkspace__c()) AS sObject ) sObject ON sObject.Id = expectedResult.Id;