---
policy: /ce/ca/aws/autoscaling/group-uses-launch-configuration
logic: /ce/ca/aws/autoscaling/group-uses-launch-configuration/prod.logic.yaml
executionTime: 2025-06-25T13:41:06.928263144Z
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: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__launchConfigurationName__c').isNotEmpty()
      actual: extract('CA10__launchConfigurationName__c').isNotEmpty()
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/autoscaling/group-uses-launch-configuration/policy.yaml
    md5Hash: 29DE74907E8D083F2D294D7572C077F3
    content: "---\nnames:\n  full: AWS EC2 Auto Scaling Group uses Launch Configuration\
      \ instead of Launch Template\n  contextual: Auto Scaling Group uses Launch Configuration\
      \ instead of Launch Template\ndescription: >\n  Ensure Auto Scaling groups use\
      \ Launch Templates instead of Launch Configurations. \n  Launch Configurations\
      \ are no longer fully supported by AWS and do not receive updates for new EC2\
      \ features.\ncategories:\n  - \"RELIABILITY\"\ntype: \"COMPLIANCE_POLICY\"\n\
      frameworkMappings:\n  - \"/frameworks/cloudaware/resource-reliability/infrastructure-modernization\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/auto-scaling/09\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[AutoScaling.9] Amazon EC2 Auto Scaling groups should use Amazon\
      \ EC2 launch templates\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/autoscaling-controls.html#autoscaling-9\"\
      \n  internal:\n    - \"dec-x-b49c2465\""
  - path: /ce/ca/aws/autoscaling/group-uses-launch-configuration/prod.logic.yaml
    md5Hash: F7B140F93B5E441D44112DF1C148CB73
    content: "---\ninputType: \"CA10__CaAwsAutoScalingGroup__c\"\nimportExtracts:\n\
      \  - file: \"/types/CA10__CaAwsAutoScalingGroup__c/object.extracts.yaml\"\n\
      testData:\n  - file: \"test-data.json\"  \nconditions:\n  - status: \"INCOMPLIANT\"\
      \n    currentStateMessage: \"The Auto Scaling group uses a launch configuration.\"\
      \n    remediationMessage: \"Consider migrating the Auto Scaling group to launch\
      \ template.\"\n    check:\n      NOT_EMPTY:\n        arg:\n          EXTRACT:\
      \ \"CA10__launchConfigurationName__c\"\notherwise:\n  status: \"COMPLIANT\"\n\
      \  currentStateMessage: \"The AGS does not use a launch configuration.\"\n"
  - path: /ce/ca/aws/autoscaling/group-uses-launch-configuration/test-data.json
    md5Hash: 9C3596812DD96D636EDE7F08E90CBF6D
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-06-22T18:49:05Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-06-17T15:05:27Z",
              "CA10__launchConfigurationName__c": "launchConfigurationName"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__launchConfigurationName__c').isNotEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-06-22T18:49:05Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__launchConfigurationName__c": "launchConfigurationName"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-06-22T18:49:05Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__launchConfigurationName__c": ""
          }
      ]
  - path: /types/CA10__CaAwsAutoScalingGroup__c/object.extracts.yaml
    md5Hash: 134069A12987447E64F62153975AC9A7
    content: "---\nextracts:\n  # AvailabilityZones.member.N\n  # One or more Availability\
      \ Zones for the group.\n  # Type: Array of strings\n  # Length Constraints:\
      \ Minimum length of 1. Maximum length of 255.\n  # Pattern: [\\u0020-\\uD7FF\\\
      uE000-\\uFFFD\\uD800\\uDC00-\\uDBFF\\uDFFF\\r\\n\\t]*\n  # Required: Yes\n \
      \ - name: CA10__availabilityZones__c\n    value: \n      FIELD:\n        path:\
      \ CA10__availabilityZones__c\n        undeterminedIf:\n          isEmpty: Corrupted\
      \ data. Availability zones should always present\n  - name: caExtract_availabilityZones_asCollection__c\n\
      \    value: \n      COLLECTION_FROM:\n        separator: \"\\n\"\n        emptyValues:\
      \ SKIP\n        duplicateValues: SKIP\n        ordering: SORTED\n        arg:\n\
      \          EXTRACT: CA10__availabilityZones__c\n# A comma-separated value string\
      \ of one or more health check types.\n# Values: EC2, EBS, ELB, VPC_LATTICE.\
      \  Not nullable. Can't have no access, retrieved via autoscaling:DescribeAutoScalingGroups\n\
      \  - name: CA10__healthCheckType__c\n    value: \n      FIELD:\n        path:\
      \ CA10__healthCheckType__c     \n# Nullable. Can't have no access, retrieved\
      \ via autoscaling:DescribeAutoScalingGroups     \n  - name: CA10__launchConfigurationName__c\n\
      \    value: \n      FIELD:\n        path: CA10__launchConfigurationName__c \
      \         \n# Nullable. Can't have no access, retrieved via autoscaling:DescribeAutoScalingGroups\
      \     \n  - name: CA10A1__launchTemplateId__c\n    value: \n      FIELD:\n \
      \       path: CA10A1__launchTemplateId__c          \n# Nullable. Can't have\
      \ no access, retrieved via autoscaling:DescribeAutoScalingGroups     \n  - name:\
      \ CA10A1__mixedInstancesLaunchTemplateId__c\n    value: \n      FIELD:\n   \
      \     path: CA10A1__mixedInstancesLaunchTemplateId__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" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__launchConfigurationName__c').isNotEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAutoScalingGroup__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__launchConfigurationName__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-06-22T18:49:05Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-06-17T15:05:27Z"),
    "CA10__launchConfigurationName__c" : "launchConfigurationName"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-06-22T18:49:05Z")
    },
    "Id" : "test2",
    "CA10__launchConfigurationName__c" : "launchConfigurationName"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-06-22T18:49:05Z")
    },
    "Id" : "test3",
    "CA10__launchConfigurationName__c" : ""
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsAutoScalingGroup__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__launchConfigurationName__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 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 extract3() { if (!this.out) { this.out = obj.CA10__launchConfigurationName__c; } return this.out; };
      references1.push('Launch Configuration Name [obj.CA10__launchConfigurationName__c]: ' + obj.CA10__launchConfigurationName__c);
      if (TextLib.isNotEmpty(extract3.call(extract3))) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__launchConfigurationName__c').isNotEmpty()", currentStateMessage: "The Auto Scaling group uses a launch configuration.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the Auto Scaling group to launch template.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The AGS does not use a launch configuration.", 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__launchConfigurationName__c AS CA10__launchConfigurationName__c,
          process_CA10__CaAwsAutoScalingGroup__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__launchConfigurationName__c AS CA10__launchConfigurationName__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsAutoScalingGroup__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
