UNPKG

@pulumi/awsx

Version:

[![Actions Status](https://github.com/pulumi/pulumi-awsx/workflows/master/badge.svg)](https://github.com/pulumi/pulumi-awsx/actions) [![Slack](http://www.pulumi.com/images/docs/badges/slack.svg)](https://slack.pulumi.com) [![NPM version](https://badge.fur

141 lines 6.4 kB
"use strict"; // Copyright 2016-2018, Pulumi Corporation. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Service = void 0; exports.isServiceLoadBalancerProvider = isServiceLoadBalancerProvider; const aws = __importStar(require("@pulumi/aws")); const pulumi = __importStar(require("@pulumi/pulumi")); const cluster_1 = require("./cluster"); const container_1 = require("./container"); const utils = __importStar(require("../utils")); class Service extends pulumi.ComponentResource { service; cluster; taskDefinition; /** * Mapping from container in this service to the ELB listener exposing it through a load * balancer. Only present if a listener was provided in [Container.portMappings] or in * [Container.applicationListener] or [Container.networkListener]. */ listeners = {}; applicationListeners = {}; networkListeners = {}; constructor(type, name, args, opts) { super(type, name, {}, opts); this.cluster = args.cluster || cluster_1.Cluster.getDefault(); this.listeners = args.taskDefinition.listeners; this.applicationListeners = args.taskDefinition.applicationListeners; this.networkListeners = args.taskDefinition.networkListeners; // Determine which load balancers we're attached to based on the information supplied to the // containers for this service. const loadBalancers = getLoadBalancers(this, name, args); this.service = new aws.ecs.Service(name, { ...args, loadBalancers, cluster: this.cluster.cluster.arn, taskDefinition: args.taskDefinition.taskDefinition.arn, desiredCount: utils.ifUndefined(args.desiredCount, 1), waitForSteadyState: utils.ifUndefined(args.waitForSteadyState, true), }, pulumi.mergeOptions(opts, { parent: this, dependsOn: this.cluster.autoScalingGroups.map(g => g.stack), })); this.taskDefinition = args.taskDefinition; } } exports.Service = Service; function getLoadBalancers(service, name, args) { const result = []; // Get the initial set of load balancers if specified directly in our args. if (args.loadBalancers) { for (const obj of args.loadBalancers) { const loadBalancer = isServiceLoadBalancerProvider(obj) ? obj.serviceLoadBalancer(name, service) : obj; result.push(pulumi.output(loadBalancer)); } } const containerLoadBalancerProviders = []; // Now walk each container and see if it wants to add load balancer information as well. for (const containerName of Object.keys(args.taskDefinition.containers)) { const container = args.taskDefinition.containers[containerName]; if (!container.portMappings) { continue; } for (const obj of container.portMappings) { if ((0, container_1.isContainerLoadBalancerProvider)(obj)) { containerLoadBalancerProviders.push([containerName, obj]); } } } // Finally see if we were directly given load balancing listeners to associate our containers // with. If so, use their information to populate our LB information. for (const containerName of Object.keys(service.listeners)) { const provider = service.listeners[containerName]; if (!containerLoadBalancerProviders.some(p => p[0] === containerName && p[1] === provider)) { containerLoadBalancerProviders.push([containerName, provider]); } } for (const [containerName, provider] of containerLoadBalancerProviders) { processContainerLoadBalancerProvider(containerName, provider); } return pulumi.output(result); function processContainerLoadBalancerProvider(containerName, prov) { // Containers don't know their own name. So we add the name in here on their behalf. const containerLoadBalancer = prov.containerLoadBalancer(name, service); const serviceLoadBalancer = pulumi.output(containerLoadBalancer).apply(lb => ({ ...lb, containerName })); result.push(serviceLoadBalancer); } } /** @internal */ function isServiceLoadBalancerProvider(obj) { return obj && obj.serviceLoadBalancer instanceof Function; } // Make sure our exported args shape is compatible with the overwrite shape we're trying to provide. utils.checkCompat(); //# sourceMappingURL=service.js.map