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

121 lines 5.37 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.LoadBalancer = void 0; exports.isLoadBalancerTargetInfoProvider = isLoadBalancerTargetInfoProvider; const aws = __importStar(require("@pulumi/aws")); const pulumi = __importStar(require("@pulumi/pulumi")); const ec2 = __importStar(require("../ec2")); const utils = __importStar(require("../utils")); class LoadBalancer extends pulumi.ComponentResource { loadBalancer; vpc; securityGroups; listeners = []; targetGroups = []; constructor(type, name, args, opts) { super(type, name, {}, opts); if (args.loadBalancer) { this.loadBalancer = args.loadBalancer; this.vpc = ec2.Vpc.fromExistingIds(`${name}-vpc`, { vpcId: this.loadBalancer.vpcId }); this.securityGroups = ec2.getSecurityGroups(this.vpc, name, args.securityGroups, { parent: this }) || []; return; } this.vpc = args.vpc || ec2.Vpc.getDefault({ parent: this }); this.securityGroups = ec2.getSecurityGroups(this.vpc, name, args.securityGroups, { parent: this }) || []; const external = utils.ifUndefined(args.external, true); const lbArgs = { ...args, subnets: getSubnets(args, this.vpc, external), internal: external.apply(ex => !ex), securityGroups: this.securityGroups.map(g => g.id), tags: utils.mergeTags(args.tags, { Name: name }), }; // If we're explicitly provided subnetMappings, then remove the `subnets` property // because they are mutually exclusive. if (lbArgs.subnetMappings) { delete lbArgs.subnets; } // We used to hash the name of an LB to keep the name short. This was necessary back when // people didn't have direct control over creating the LB. In awsx though creating the LB // is easy to do, so we just let the user pass in the name they want. We simply add an // alias from the old name to the new one to keep things from being recreated. this.loadBalancer = new aws.lb.LoadBalancer(name, lbArgs, { parent: this, aliases: [{ name: args.name || utils.sha1hash(name) }], }); } /** * Attaches a target to the first `listener` of this LoadBalancer. If there are multiple * `listeners` you can add a target to specific listener to by calling `.attachTarget` directly * on it. */ attachTarget(name, args, opts = {}) { if (this.listeners.length === 0) { throw new pulumi.ResourceError("Load balancer must have at least one [Listener] in order to attach a target.", this); } return this.listeners[0].attachTarget(name, args, opts); } } exports.LoadBalancer = LoadBalancer; function getSubnets(args, vpc, external) { if (!args.subnets) { // No subnets requested. Determine the subnets automatically from the vpc. return external.apply(e => e ? vpc.publicSubnetIds : vpc.privateSubnetIds); } return isLoadBalancerSubnets(args.subnets) ? args.subnets.subnets() : args.subnets; } function isLoadBalancerSubnets(obj) { return obj && obj.subnets instanceof Function; } function isLoadBalancerTargetInfoProvider(obj) { return obj.loadBalancerTargetInfo instanceof Function; } //# sourceMappingURL=loadBalancer.js.map