--- policy: /ce/ca/azure/devtest-labs/virtual-machine-auto-shutdown-disabled logic: /ce/ca/azure/devtest-labs/virtual-machine-auto-shutdown-disabled/prod.logic.yaml executionTime: 2026-09-22T15:06:35.02943099Z generationMs: 58 executionMs: 881 rows: - id: gone match: true status: expected: DISAPPEARED actual: DISAPPEARED conditionIndex: expected: 99 actual: 99 conditionText: expected: isDisappeared(CA10Z1__disappearanceTime__c) actual: isDisappeared(CA10Z1__disappearanceTime__c) runtimeError: {} - id: invalid match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 101 actual: 101 conditionText: expected: extract('CA10Z1__applicableScheduleJson__c').asJson().isInvalid() actual: extract('CA10Z1__applicableScheduleJson__c').asJson().isInvalid() runtimeError: expected: "Unexpected token 'o', \"not-json\" is not valid JSON" actual: "Unexpected token 'o', \"not-json\" is not valid JSON" - id: disabled match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 199 actual: 199 conditionText: expected: extract('caJsonText__autoShutdownStatus__c') != 'Enabled' actual: extract('caJsonText__autoShutdownStatus__c') != 'Enabled' runtimeError: {} - id: schedule-absent match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 199 actual: 199 conditionText: expected: extract('caJsonText__autoShutdownStatus__c') != 'Enabled' actual: extract('caJsonText__autoShutdownStatus__c') != 'Enabled' runtimeError: {} - id: enabled match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 200 actual: 200 conditionText: expected: otherwise actual: otherwise runtimeError: {} usedFiles: - path: /ce/ca/azure/devtest-labs/virtual-machine-auto-shutdown-disabled/policy.yaml md5Hash: 47B9985B132C4DE4FBE5FC4FB3B614C3 content: | --- names: full: "Azure DevTest Lab Virtual Machine auto-shutdown is disabled" contextual: "DevTest Lab VM auto-shutdown is disabled" description: "Identify Azure DevTest Lab virtual machines whose applicable auto-shutdown schedule is disabled or absent to reduce unnecessary compute charges." categories: - "COST" type: "BEST_PRACTICE" frameworkMappings: - "/frameworks/cloudaware/cost-efficiency-and-optimization/resource-optimization" - path: /ce/ca/azure/devtest-labs/virtual-machine-auto-shutdown-disabled/prod.logic.yaml md5Hash: 0AC92DFBCBBFDA7E3BB4B13EFD5C4285 content: | --- inputType: "CA10Z1__CaAzureDevTestVirtualMachine__c" testData: - file: test-data.json importExtracts: - file: /types/CA10Z1__CaAzureDevTestVirtualMachine__c/object.extracts.yaml conditions: - status: "INCOMPLIANT" currentStateMessage: "The applicable auto-shutdown schedule is disabled or absent." remediationMessage: "Review and enable an appropriate auto-shutdown schedule." check: NOT_EQUAL: left: EXTRACT: "caJsonText__autoShutdownStatus__c" right: TEXT: "Enabled" otherwise: status: "COMPLIANT" currentStateMessage: "Auto-shutdown is enabled." - path: /ce/ca/azure/devtest-labs/virtual-machine-auto-shutdown-disabled/test-data.json md5Hash: 59667D473A9E2C0DC871927501510C33 content: |- [ { "expectedResult": { "status": "DISAPPEARED", "conditionIndex": "99", "conditionText": "isDisappeared(CA10Z1__disappearanceTime__c)", "runtimeError": null }, "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "Id": "gone", "CA10Z1__disappearanceTime__c": "2026-09-09T00:00:00Z", "CA10Z1__applicableScheduleJson__c": "{\"properties\":{\"labVmsShutdown\":{\"properties\":{\"status\":\"Enabled\"}}}}" }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "101", "conditionText": "extract('CA10Z1__applicableScheduleJson__c').asJson().isInvalid()", "runtimeError": "Unexpected token 'o', \"not-json\" is not valid JSON" }, "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "Id": "invalid", "CA10Z1__disappearanceTime__c": null, "CA10Z1__applicableScheduleJson__c": "not-json" }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "199", "conditionText": "extract('caJsonText__autoShutdownStatus__c') != 'Enabled'", "runtimeError": null }, "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "Id": "disabled", "CA10Z1__disappearanceTime__c": null, "CA10Z1__applicableScheduleJson__c": "{\"properties\":{\"labVmsShutdown\":{\"properties\":{\"status\":\"Disabled\"}}}}" }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "199", "conditionText": "extract('caJsonText__autoShutdownStatus__c') != 'Enabled'", "runtimeError": null }, "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "Id": "schedule-absent", "CA10Z1__disappearanceTime__c": null, "CA10Z1__applicableScheduleJson__c": "{\"properties\":{}}" }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "200", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "Id": "enabled", "CA10Z1__disappearanceTime__c": null, "CA10Z1__applicableScheduleJson__c": "{\"properties\":{\"labVmsShutdown\":{\"properties\":{\"status\":\"Enabled\"}}}}" } ] - path: /types/CA10Z1__CaAzureDevTestVirtualMachine__c/object.extracts.yaml md5Hash: 13877468A5EF2B142261B625EE26E8CE content: "---\nextracts:\n - name: \"CA10Z1__applicableScheduleJson__c\"\n \ \ value:\n FIELD:\n path: \"CA10Z1__applicableScheduleJson__c\"\ \n returnType: BYTES\n - name: \"caJsonFrom__applicableScheduleJson__c\"\ \n value:\n JSON_FROM:\n arg:\n EXTRACT: \"CA10Z1__applicableScheduleJson__c\"\ \ \n undeterminedIf:\n isInvalid: \"The applicable schedule\ \ JSON is invalid.\" \n - name: \"caJsonText__autoShutdownStatus__c\"\n \ \ value:\n JSON_QUERY_TEXT:\n arg:\n EXTRACT: \"caJsonFrom__applicableScheduleJson__c\"\ \n expression: \"properties.labVmsShutdown.properties.status\"\n \ \ undeterminedIf:\n evaluationError: \"The auto-shutdown schedule\ \ cannot be read.\"\n resultTypeMismatch: \"The auto-shutdown status\ \ is not text.\"\n \n" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "gone", "expectedResult" : { "status" : "DISAPPEARED", "conditionIndex" : "99", "conditionText" : "isDisappeared(CA10Z1__disappearanceTime__c)", "runtimeError" : null } }, { "Id" : "invalid", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "101", "conditionText" : "extract('CA10Z1__applicableScheduleJson__c').asJson().isInvalid()", "runtimeError" : "Unexpected token 'o', \"not-json\" is not valid JSON" } }, { "Id" : "disabled", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "199", "conditionText" : "extract('caJsonText__autoShutdownStatus__c') != 'Enabled'", "runtimeError" : null } }, { "Id" : "schedule-absent", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "199", "conditionText" : "extract('caJsonText__autoShutdownStatus__c') != 'Enabled'", "runtimeError" : null } }, { "Id" : "enabled", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "200", "conditionText" : "otherwise", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10Z1__CaAzureDevTestVirtualMachine__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__disappearanceTime__c" : new Date("2026-09-09T00:00:00Z"), "CA10Z1__applicableScheduleJson__c" : "{\"properties\":{\"labVmsShutdown\":{\"properties\":{\"status\":\"Enabled\"}}}}", "Id" : "gone" }, { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__applicableScheduleJson__c" : "not-json", "Id" : "invalid" }, { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__applicableScheduleJson__c" : "{\"properties\":{\"labVmsShutdown\":{\"properties\":{\"status\":\"Disabled\"}}}}", "Id" : "disabled" }, { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__applicableScheduleJson__c" : "{\"properties\":{}}", "Id" : "schedule-absent" }, { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__applicableScheduleJson__c" : "{\"properties\":{\"labVmsShutdown\":{\"properties\":{\"status\":\"Enabled\"}}}}", "Id" : "enabled" } ]; """; CREATE TEMP FUNCTION process_CA10Z1__CaAzureDevTestVirtualMachine__c( obj STRUCT< CA10Z1__disappearanceTime__c TIMESTAMP, CA10Z1__applicableScheduleJson__c STRING, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js OPTIONS (library=['gs://compliance-platform-public/jmespath.min.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 Azure [CA10Z1__disappearanceTime__c]: ' + obj.CA10Z1__disappearanceTime__c); if (obj.CA10Z1__disappearanceTime__c != null) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10Z1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[1], conditionIndex:[100..199] function jsonQueryChecked4() { var input = extract6.call(extract6); var out; try { out = jmespath.search(input, 'properties.labVmsShutdown.properties.status'); if (out != null && typeof out != 'string') { throw new Error("UNDETERMINED condition:102", {cause: {status: 'UNDETERMINED', conditionIndex: 102, conditionText: "extract('caJsonFrom__applicableScheduleJson__c').jsonQueryText('properties.labVmsShutdown.properties.status').isResultTypeMismatch()", currentStateMessage: "The auto-shutdown status is not text.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } } catch (e) { throw new Error("UNDETERMINED condition:103", {cause: {status: 'UNDETERMINED', conditionIndex: 103, conditionText: "extract('caJsonFrom__applicableScheduleJson__c').jsonQueryText('properties.labVmsShutdown.properties.status').isEvaluationFailed()", currentStateMessage: "The auto-shutdown schedule cannot be read.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function jsonChecked7() { var input = extract9.call(extract9); input = TextLib.isEmpty(input) ? null : input; var out; try { out = JSON.parse(input); } catch (e) { throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "extract('CA10Z1__applicableScheduleJson__c').asJson().isInvalid()", currentStateMessage: "The applicable schedule JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function extract9() { if (!this.out) { this.out = obj.CA10Z1__applicableScheduleJson__c; } return this.out; }; function extract6() { if (!this.out) { this.out = jsonChecked7(); } return this.out; }; function extract3() { if (!this.out) { this.out = jsonQueryChecked4(); } return this.out; }; references1.push('Applicable Schedule JSON [obj.CA10Z1__applicableScheduleJson__c]: ' + obj.CA10Z1__applicableScheduleJson__c); try { if (TextLib.notEqual(extract3.call(extract3), 'Enabled')) { return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('caJsonText__autoShutdownStatus__c') != 'Enabled'", currentStateMessage: "The applicable auto-shutdown schedule is disabled or absent.", currentStateReferences: references1.join('\n'), remediation: "Review and enable an appropriate auto-shutdown schedule.", runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Auto-shutdown 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.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__applicableScheduleJson__c AS CA10Z1__applicableScheduleJson__c, sObject.Id AS Id, process_CA10Z1__CaAzureDevTestVirtualMachine__c( STRUCT( sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__applicableScheduleJson__c AS CA10Z1__applicableScheduleJson__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10Z1__CaAzureDevTestVirtualMachine__c()) AS sObject ) sObject ON sObject.Id = expectedResult.Id;