text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.createEsDomainRole = exports.createEsDomain = void 0;
  const aws_ec2_1 = require("@aws-cdk/aws-ec2");
  const aws_elasticsearch_1 = require("@aws-cdk/aws-elasticsearch");
  const aws_iam_1 = require("@aws-cdk/aws-iam");
  const core_1 = require("@aws-cdk/core");
  const graphql_transformer_common_1 = require("graphql-transformer-common");
  const createEsDomain = (stack, parameterMap, apiId) => {
      var _a, _b, _c;
      const { ElasticsearchEBSVolumeGB, ElasticsearchInstanceType, ElasticsearchInstanceCount } = graphql_transformer_common_1.ResourceConstants.PARAMETERS;
      const { ElasticsearchDomainLogicalID } = graphql_transformer_common_1.ResourceConstants.RESOURCES;
      const { HasEnvironmentParameter } = graphql_transformer_common_1.ResourceConstants.CONDITIONS;
      const domain = new aws_elasticsearch_1.Domain(stack, ElasticsearchDomainLogicalID, {
          version: aws_elasticsearch_1.ElasticsearchVersion.V6_2,
          ebs: {
              enabled: true,
              volumeType: aws_ec2_1.EbsDeviceVolumeType.GP2,
              volumeSize: (_a = parameterMap.get(ElasticsearchEBSVolumeGB)) === null || _a === void 0 ? void 0 : _a.valueAsNumber,
          },
          zoneAwareness: {
              enabled: false,
          },
          domainName: core_1.Fn.conditionIf(HasEnvironmentParameter, core_1.Fn.ref('AWS::NoValue'), 'd' + apiId).toString(),
      });
      domain.node.defaultChild.elasticsearchClusterConfig = {
          instanceCount: (_b = parameterMap.get(ElasticsearchInstanceCount)) === null || _b === void 0 ? void 0 : _b.valueAsNumber,
          instanceType: (_c = parameterMap.get(ElasticsearchInstanceType)) === null || _c === void 0 ? void 0 : _c.valueAsString,
      };
      return domain;
  };
  exports.createEsDomain = createEsDomain;
  const createEsDomainRole = (stack, parameterMap, apiId, envParam) => {
      const { ElasticsearchAccessIAMRoleLogicalID } = graphql_transformer_common_1.ResourceConstants.RESOURCES;
      const { ElasticsearchAccessIAMRoleName } = graphql_transformer_common_1.ResourceConstants.PARAMETERS;
      const { HasEnvironmentParameter } = graphql_transformer_common_1.ResourceConstants.CONDITIONS;
      return new aws_iam_1.Role(stack, ElasticsearchAccessIAMRoleLogicalID, {
          assumedBy: new aws_iam_1.ServicePrincipal('appsync.amazonaws.com'),
          roleName: core_1.Fn.conditionIf(HasEnvironmentParameter, core_1.Fn.join('-', [parameterMap.get(ElasticsearchAccessIAMRoleName).valueAsString, apiId, envParam.valueAsString]), core_1.Fn.join('-', [parameterMap.get(ElasticsearchAccessIAMRoleName).valueAsString, apiId, envParam.valueAsString])).toString(),
      });
  };
  exports.createEsDomainRole = createEsDomainRole;
  //# sourceMappingURL=create-es-domain.js.map