--- policy: /ce/ca/azure/savings-plan/expired-in-last-30-days logic: /ce/ca/azure/savings-plan/expired-in-last-30-days/prod.logic.yaml executionTime: 2026-09-22T15:06:45.143782177Z generationMs: 55 executionMs: 889 rows: - id: '001' match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 299 actual: 299 conditionText: expected: extract('CA10Z1__provisioningState__c') != 'Succeeded' actual: extract('CA10Z1__provisioningState__c') != 'Succeeded' runtimeError: {} - id: disappeared 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: missing match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 199 actual: 199 conditionText: expected: extract('CA10Z1__provisioningState__c').isEmpty() || extract('CA10Z1__expiryDateTime__c').isEmpty() actual: extract('CA10Z1__provisioningState__c').isEmpty() || extract('CA10Z1__expiryDateTime__c').isEmpty() runtimeError: {} - id: recent match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 399 actual: 399 conditionText: expected: extract('CA10Z1__expiryDateTime__c').beforeToday() && extract('CA10Z1__expiryDateTime__c').withinLastDays(30) actual: extract('CA10Z1__expiryDateTime__c').beforeToday() && extract('CA10Z1__expiryDateTime__c').withinLastDays(30) runtimeError: {} - id: old match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 400 actual: 400 conditionText: expected: otherwise actual: otherwise runtimeError: {} usedFiles: - path: /ce/ca/azure/savings-plan/expired-in-last-30-days/policy.yaml md5Hash: 886563BC2EAB4615510A82F9B8D43FC7 content: | --- names: full: "Azure Savings Plan expired in the last 30 days" contextual: "Savings Plan expired in the last 30 days" description: "Identify successfully provisioned Azure Savings Plans that expired within the last 30 days so their renewal intent and replacement coverage can be reviewed." categories: - "COST" type: "COMPLIANCE_POLICY" frameworkMappings: - "/frameworks/cloudaware/cost-efficiency-and-optimization/resource-optimization" - path: /ce/ca/azure/savings-plan/expired-in-last-30-days/prod.logic.yaml md5Hash: 81C3E69688B1C87869A274A98757CBC0 content: | --- inputType: "CA10Z1__CaAzureSavingsPlan__c" testData: - file: "test-data.json" importExtracts: - file: "/types/CA10Z1__CaAzureSavingsPlan__c/object.extracts.yaml" conditions: - status: "UNDETERMINED" currentStateMessage: "Provisioning state or expiry date is unavailable." check: OR: args: - IS_EMPTY: arg: EXTRACT: "CA10Z1__provisioningState__c" - IS_EMPTY: arg: EXTRACT: "CA10Z1__expiryDateTime__c" - status: "INAPPLICABLE" currentStateMessage: "The Savings Plan is not successfully provisioned." check: NOT_EQUAL: left: EXTRACT: "CA10Z1__provisioningState__c" right: TEXT: "Succeeded" - status: "INCOMPLIANT" currentStateMessage: "The Savings Plan expired in the last 30 days." remediationMessage: "Review whether replacement Savings Plan coverage is needed." check: AND: args: - IS_BEFORE_TODAY: arg: EXTRACT: "CA10Z1__expiryDateTime__c" - IS_WITHIN_LAST_DAYS: offsetDays: 30 arg: EXTRACT: "CA10Z1__expiryDateTime__c" otherwise: status: "COMPLIANT" currentStateMessage: "The Savings Plan did not expire in the last 30 days." - path: /ce/ca/azure/savings-plan/expired-in-last-30-days/test-data.json md5Hash: 73A8E467B65FB62EB6BBC1457A69463E content: |- [ { "CA10Z1__disappearanceTime__c": null, "RecordType": { "Id": "RecordType1" }, "expectedResult": { "runtimeError": null, "conditionText": "extract('CA10Z1__provisioningState__c') != 'Succeeded'", "conditionIndex": 299, "status": "INAPPLICABLE" }, "CA10Z1__expiryDateTime__c": "2025-11-02T09:33:28Z", "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "RecordTypeId": "RecordType1", "Id": "001", "CA10Z1__provisioningState__c": "Expired" }, { "CA10Z1__disappearanceTime__c": "2026-09-09T00:00:00Z", "RecordType": { "Id": "RecordType1" }, "expectedResult": { "runtimeError": null, "conditionText": "isDisappeared(CA10Z1__disappearanceTime__c)", "conditionIndex": 99, "status": "DISAPPEARED" }, "CA10Z1__expiryDateTime__c": "2026-09-01T00:00:00Z", "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "RecordTypeId": "RecordType1", "Id": "disappeared", "CA10Z1__provisioningState__c": "Succeeded" }, { "CA10Z1__disappearanceTime__c": null, "RecordType": { "Id": "RecordType1" }, "expectedResult": { "runtimeError": null, "conditionText": "extract('CA10Z1__provisioningState__c').isEmpty() || extract('CA10Z1__expiryDateTime__c').isEmpty()", "conditionIndex": 199, "status": "UNDETERMINED" }, "CA10Z1__expiryDateTime__c": null, "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "RecordTypeId": "RecordType1", "Id": "missing", "CA10Z1__provisioningState__c": "Succeeded" }, { "CA10Z1__disappearanceTime__c": null, "RecordType": { "Id": "RecordType1" }, "expectedResult": { "runtimeError": null, "conditionText": "extract('CA10Z1__expiryDateTime__c').beforeToday() && extract('CA10Z1__expiryDateTime__c').withinLastDays(30)", "conditionIndex": 399, "status": "INCOMPLIANT" }, "CA10Z1__expiryDateTime__c": "2026-09-01T00:00:00Z", "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "RecordTypeId": "RecordType1", "Id": "recent", "CA10Z1__provisioningState__c": "Succeeded" }, { "CA10Z1__disappearanceTime__c": null, "RecordType": { "Id": "RecordType1" }, "expectedResult": { "runtimeError": null, "conditionText": "otherwise", "conditionIndex": 400, "status": "COMPLIANT" }, "CA10Z1__expiryDateTime__c": "2026-08-01T00:00:00Z", "context": { "snapshotTime": "2026-09-10T13:03:37Z" }, "RecordTypeId": "RecordType1", "Id": "old", "CA10Z1__provisioningState__c": "Succeeded" } ] - path: /types/CA10Z1__CaAzureSavingsPlan__c/object.extracts.yaml md5Hash: A48C2F3CC67C2B1D21FA44A52C30DEC9 content: | --- extracts: - name: "CA10Z1__provisioningState__c" value: FIELD: path: "CA10Z1__provisioningState__c" - name: "CA10Z1__expiryDateTime__c" value: FIELD: path: "CA10Z1__expiryDateTime__c" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "001", "expectedResult" : { "runtimeError" : null, "conditionText" : "extract('CA10Z1__provisioningState__c') != 'Succeeded'", "conditionIndex" : 299, "status" : "INAPPLICABLE" } }, { "Id" : "disappeared", "expectedResult" : { "runtimeError" : null, "conditionText" : "isDisappeared(CA10Z1__disappearanceTime__c)", "conditionIndex" : 99, "status" : "DISAPPEARED" } }, { "Id" : "missing", "expectedResult" : { "runtimeError" : null, "conditionText" : "extract('CA10Z1__provisioningState__c').isEmpty() || extract('CA10Z1__expiryDateTime__c').isEmpty()", "conditionIndex" : 199, "status" : "UNDETERMINED" } }, { "Id" : "recent", "expectedResult" : { "runtimeError" : null, "conditionText" : "extract('CA10Z1__expiryDateTime__c').beforeToday() && extract('CA10Z1__expiryDateTime__c').withinLastDays(30)", "conditionIndex" : 399, "status" : "INCOMPLIANT" } }, { "Id" : "old", "expectedResult" : { "runtimeError" : null, "conditionText" : "otherwise", "conditionIndex" : 400, "status" : "COMPLIANT" } } ]; """; CREATE TEMP FUNCTION mock_CA10Z1__CaAzureSavingsPlan__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__provisioningState__c" : "Expired", "CA10Z1__expiryDateTime__c" : new Date("2025-11-02T09:33:28Z"), "Id" : "001", "RecordTypeId" : "RecordType1" }, { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__disappearanceTime__c" : new Date("2026-09-09T00:00:00Z"), "CA10Z1__provisioningState__c" : "Succeeded", "CA10Z1__expiryDateTime__c" : new Date("2026-09-01T00:00:00Z"), "Id" : "disappeared", "RecordTypeId" : "RecordType1" }, { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__provisioningState__c" : "Succeeded", "Id" : "missing", "RecordTypeId" : "RecordType1" }, { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__provisioningState__c" : "Succeeded", "CA10Z1__expiryDateTime__c" : new Date("2026-09-01T00:00:00Z"), "Id" : "recent", "RecordTypeId" : "RecordType1" }, { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "CA10Z1__provisioningState__c" : "Succeeded", "CA10Z1__expiryDateTime__c" : new Date("2026-08-01T00:00:00Z"), "Id" : "old", "RecordTypeId" : "RecordType1" } ]; """; CREATE TEMP FUNCTION mock_RecordType() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2026-09-10T13:03:37Z") }, "Id" : "RecordType1" } ]; """; CREATE TEMP FUNCTION process_CA10Z1__CaAzureSavingsPlan__c( obj STRUCT< CA10Z1__disappearanceTime__c TIMESTAMP, CA10Z1__provisioningState__c STRING, CA10Z1__expiryDateTime__c TIMESTAMP, Id STRING, RecordTypeId STRING, RecordType STRUCT< Id STRING > >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var IsEmptyLib = new function () { this.simpleIsEmpty = function(arg) { return arg == null; }; this.simpleIsNotEmpty = function(arg) { return arg != null; }; }(); 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 today = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime(); var todayMinus30Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (-30 * 86400000); var todayPlus1Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (1 * 86400000); 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 extract3() { if (!this.out) { this.out = obj.CA10Z1__provisioningState__c; } return this.out; }; function extract6() { if (!this.out) { this.out = obj.CA10Z1__expiryDateTime__c; } return this.out; }; references1.push('Provisioning State [obj.CA10Z1__provisioningState__c]: ' + obj.CA10Z1__provisioningState__c); references1.push('Expiry DateTime [obj.CA10Z1__expiryDateTime__c]: ' + obj.CA10Z1__expiryDateTime__c); if (TextLib.isEmpty(extract3.call(extract3)) || IsEmptyLib.simpleIsEmpty(extract6.call(extract6))) { return {status: 'UNDETERMINED', conditionIndex: 199, conditionText: "extract('CA10Z1__provisioningState__c').isEmpty() || extract('CA10Z1__expiryDateTime__c').isEmpty()", currentStateMessage: "Provisioning state or expiry date is unavailable.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[2], conditionIndex:[200..299] function extract9() { if (!this.out) { this.out = obj.CA10Z1__provisioningState__c; } return this.out; }; if (TextLib.notEqual(extract9.call(extract9), 'Succeeded')) { return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10Z1__provisioningState__c') != 'Succeeded'", currentStateMessage: "The Savings Plan is not successfully provisioned.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[3], conditionIndex:[300..399] function extract12() { if (!this.out) { this.out = obj.CA10Z1__expiryDateTime__c; } return this.out; }; if ((extract12.call(extract12) != null && extract12.call(extract12).getTime() < today) && (extract12.call(extract12) != null && extract12.call(extract12).getTime() >= todayMinus30Day && extract12.call(extract12).getTime() < todayPlus1Day)) { return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10Z1__expiryDateTime__c').beforeToday() && extract('CA10Z1__expiryDateTime__c').withinLastDays(30)", currentStateMessage: "The Savings Plan expired in the last 30 days.", currentStateReferences: references1.join('\n'), remediation: "Review whether replacement Savings Plan coverage is needed.", runtimeError: null}; } return {status: 'COMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "The Savings Plan did not expire in 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.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__provisioningState__c AS CA10Z1__provisioningState__c, sObject.CA10Z1__expiryDateTime__c AS CA10Z1__expiryDateTime__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.Id AS Id ) AS RecordType, process_CA10Z1__CaAzureSavingsPlan__c( STRUCT( sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__provisioningState__c AS CA10Z1__provisioningState__c, sObject.CA10Z1__expiryDateTime__c AS CA10Z1__expiryDateTime__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.Id AS Id ) AS RecordType ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10Z1__CaAzureSavingsPlan__c()) AS sObject LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType` ON sObject.RecordTypeId = `RecordType`.Id ) sObject ON sObject.Id = expectedResult.Id;