@pulumi/awsx
Version:
[](https://github.com/pulumi/pulumi-awsx/actions) [](https://slack.pulumi.com) [;
// 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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TargetGroup = void 0;
// tslint:disable:max-line-length
const aws = require("@pulumi/aws");
const pulumi = require("@pulumi/pulumi");
const targetGroupAttachment_1 = require("./targetGroupAttachment");
const utils = require("../utils");
class TargetGroup extends pulumi.ComponentResource {
constructor(type, name, loadBalancer, args, opts) {
// We want our parent to the be the ALB by default if nothing else is specified.
// Create an alias from our old name where we didn't parent by default to keep
// resources from being created/destroyed.
super(type, name, {}, Object.assign({ parent: loadBalancer }, pulumi.mergeOptions(opts, { aliases: [{ parent: opts.parent }] })));
this.listeners = [];
this.vpc = args.vpc;
// We used to hash the name of an TG to keep the name short. This was necessary back when
// people didn't have direct control over creating the TG. In awsx though creating the TG
// 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.targetGroup = args.targetGroup || new aws.lb.TargetGroup(name, Object.assign(Object.assign({}, args), { vpcId: this.vpc.id, protocol: utils.ifUndefined(args.protocol, "HTTP"), deregistrationDelay: utils.ifUndefined(args.deregistrationDelay, 300), targetType: utils.ifUndefined(args.targetType, "ip"), tags: utils.mergeTags(args.tags, { Name: name }) }), {
parent: this,
aliases: [{ name: args.name || utils.sha1hash(name) }],
});
this.loadBalancer = loadBalancer;
}
dependencies() {
// Return an output that depends on our listeners. That way anything that depends on us
// will only proceed once our load balancer connections have been created.
return pulumi.output(this.listeners.map(r => r.listener.urn));
}
/** @internal */
getListenersAsync() {
return __awaiter(this, void 0, void 0, function* () {
return this.listeners;
});
}
containerPortMapping() {
return pulumi.output([this.targetGroup.port, this.dependencies()]).apply(([port]) => ({
containerPort: +port,
}));
}
containerLoadBalancer() {
return this.dependencies().apply(_ => ({
containerPort: this.targetGroup.port.apply(p => p),
targetGroupArn: this.targetGroup.arn,
}));
}
listenerDefaultAction() {
return this.dependencies().apply(_ => ({
targetGroupArn: this.targetGroup.arn,
type: "forward",
}));
}
actions() {
return [this.listenerDefaultAction()];
}
/** Do not call directly. Intended for use by [Listener] and [ListenerRule] */
registerListener(listener) {
this.listeners.push(listener);
}
/**
* Attaches a target to this target group. See
* [Register-Targets](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-register-targets.html)
* for more details.
*/
attachTarget(name, args, opts = {}) {
return new targetGroupAttachment_1.TargetGroupAttachment(name, this, args, opts);
}
}
exports.TargetGroup = TargetGroup;
//# sourceMappingURL=targetGroup.js.map