@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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.EC2Service = exports.EC2TaskDefinition = void 0;
const ec2 = require("../ec2");
const cluster_1 = require("./cluster");
const service_1 = require("./service");
const taskDefinition_1 = require("./taskDefinition");
const utils = require("../utils");
class EC2TaskDefinition extends taskDefinition_1.TaskDefinition {
constructor(name, args, opts = {}) {
if (!args.container && !args.containers) {
throw new Error("Either [container] or [containers] must be provided");
}
const containers = args.containers || { container: args.container };
const argsCopy = {
...args,
containers,
requiresCompatibilities: ["EC2"],
networkMode: utils.ifUndefined(args.networkMode, "awsvpc"),
};
delete argsCopy.container;
super("awsx:x:ecs:EC2TaskDefinition", name, /*isFargate:*/ false, argsCopy, opts);
this.registerOutputs();
}
/**
* Creates a service with this as its task definition.
*/
createService(name, args, opts = {}) {
if (args.taskDefinition) {
throw new Error("[args.taskDefinition] should not be provided.");
}
if (args.taskDefinitionArgs) {
throw new Error("[args.taskDefinitionArgs] should not be provided.");
}
return new EC2Service(name, {
...args,
taskDefinition: this,
}, { parent: this, ...opts });
}
}
exports.EC2TaskDefinition = EC2TaskDefinition;
class EC2Service extends service_1.Service {
constructor(name, args, opts = {}) {
if (!args.taskDefinition && !args.taskDefinitionArgs) {
throw new Error("Either [taskDefinition] or [taskDefinitionArgs] must be provided");
}
const cluster = args.cluster || cluster_1.Cluster.getDefault();
const taskDefinition = args.taskDefinition ||
new EC2TaskDefinition(name, {
...args.taskDefinitionArgs,
vpc: cluster.vpc,
}, opts);
const securityGroups = ec2.getSecurityGroups(cluster.vpc, name, args.securityGroups || cluster.securityGroups, opts) || [];
const subnets = args.subnets || cluster.vpc.publicSubnetIds;
super("awsx:x:ecs:EC2Service", name, {
...args,
taskDefinition,
securityGroups,
launchType: "EC2",
networkConfiguration: taskDefinition.taskDefinition.networkMode.apply(n => {
// The network configuration for the service. This parameter is required for task
// definitions that use the `awsvpc` network mode to receive their own Elastic
// Network Interface, and it is not supported for other network modes.
if (n !== "awsvpc") {
return undefined;
}
return {
subnets,
assignPublicIp: false,
securityGroups: securityGroups.map(g => g.id),
};
}),
}, opts);
this.taskDefinition = taskDefinition;
this.registerOutputs();
}
}
exports.EC2Service = EC2Service;
// Make sure our exported args shape is compatible with the overwrite shape we're trying to provide.
const test1 = utils.checkCompat();
const test2 = utils.checkCompat();
//# sourceMappingURL=ec2Service.js.map