How to use the @pulumi/pulumi/errors.RunError function in @pulumi/pulumi

To help you get started, we’ve selected a few @pulumi/pulumi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulumi / pulumi-cloud / aws / docker.ts View on Github external
let loginResult: CommandResult;
    if (!dockerPasswordStdin) {
        loginResult = await runCLICommand(
            "docker", ["login", "-u", username, "-p", password, registryName]);
    } else {
        loginResult = await runCLICommand(
            "docker", ["login", "-u", username, "--password-stdin", registryName], false, password);
    }
    if (loginResult.code) {
        throw new RunError(`Failed to login to Docker registry ${registryName}`);
    }

    // Tag and push the image to the remote repository.
    if (!repositoryUrl) {
        throw new RunError("Expected repository URL to be defined during push");
    }
    const tagResult = await runCLICommand("docker", ["tag", imageName, repositoryUrl]);
    if (tagResult.code) {
        throw new RunError(`Failed to tag Docker image with remote registry URL ${repositoryUrl}`);
    }
    const pushResult = await runCLICommand("docker", ["push", repositoryUrl]);
    if (pushResult.code) {
        throw new RunError(`Docker push of image '${imageName}' failed with exit code: ${pushResult.code}`);
    }
}
github pulumi / pulumi-cloud / azure / service.ts View on Github external
constructor(name: string, container: cloud.Container, opts?: pulumi.ResourceOptions) {
        super("cloud:task:Task", name, { }, opts);

        if (container.ports && container.ports.length > 0) {
            throw new RunError("Tasks should not be given any [ports] in their Container definition.");
        }

        const { imageOptions, registry } = computeImageOptionsAndRegistry(this, container);

        const globalResourceGroupName = shared.globalResourceGroupName;
        const memory = pulumi.output(container.memoryReservation);

        // Require the client credentials at deployment time so we can fail up-front if they are not
        // provided.
        const config = new pulumi.Config("cloud-azure");
        const subscriptionId = config.require("subscriptionId");
        const clientId = config.require("clientId");
        const clientSecret = config.require("clientSecret");
        const tenantId = config.require("tenantId");

        this.run = async (options) => {
github pulumi / pulumi-cloud / aws / shared.ts View on Github external
export function createNameWithStackInfo(requiredInfo: string) {
    const maxLength = 24;

    if (requiredInfo.length > maxLength) {
        throw new RunError(`'${requiredInfo}' cannot be longer then ${maxLength} characters.`);
    }

    // No required portion.  Just return the stack name.
    if (requiredInfo.length === 0) {
        return nameWithStackInfo.substr(0, maxLength);
    }

    // Only enough room for required portion, don't add the stack.
    // Also don't add the stack if there wouldn't be room to add it and a dash.
    if (requiredInfo.length >= maxLength - "-".length) {
        return requiredInfo;
    }

    // Attempt to keep some portion of the stack, then - then the required part.
    const suffix = "-" + requiredInfo;
    const result = nameWithStackInfo.substr(0, maxLength - suffix.length) + suffix;
github pulumi / pulumi-cloud / aws / service.ts View on Github external
// See what kind of load balancer to create (application L7 for HTTP(S) traffic, or network L4 otherwise).
    // Also ensure that we have an SSL certificate for termination at the LB, if that was requested.
    let protocol: string;
    let targetProtocol: string;
    let useAppLoadBalancer: boolean;
    let useCertificateARN: string | undefined;
    switch (portMappingProtocol) {
        case "https":
            protocol = "HTTPS";
            // Set the target protocol to HTTP, so that the ELB terminates the SSL traffic.
            // IDEA: eventually we should let users choose where the SSL termination occurs.
            targetProtocol = "HTTP";
            useAppLoadBalancer = true;
            useCertificateARN = config.acmCertificateARN;
            if (!useCertificateARN) {
                throw new RunError("Cannot create Service for HTTPS trafic. No ACM certificate ARN configured.");
            }
            break;
        case "http":
            protocol = "HTTP";
            targetProtocol = "HTTP";
            useAppLoadBalancer = true;
            break;
        case "udp":
            throw new RunError("UDP protocol unsupported for Services");
        case "tcp":
            protocol = "TCP";
            targetProtocol = "TCP";
            useAppLoadBalancer = false;
            break;
        default:
            throw new RunError(`Unrecognized Service protocol: ${portMapping.protocol}`);
github pulumi / pulumi-cloud / aws / config / index.ts View on Github external
export let externalPublicSubnets: string[] | undefined = undefined;
if (externalPublicSubnetsString) {
    externalPublicSubnets = externalPublicSubnetsString.split(",");
}

const externalSecurityGroupsString = config.get("externalSecurityGroups");
/**
 * Provide securityGroup ids for the VPC as a comma-seperated string.  Required if using an existing VPC.
 */
export let externalSecurityGroups: string[] | undefined = undefined;
if (externalSecurityGroupsString) {
    externalSecurityGroups = externalSecurityGroupsString.split(",");
}

if (externalVpcId && (!externalSubnets || !externalSecurityGroups)) {
    throw new RunError(
        "Must configure 'cloud-aws:externalSubnets' and 'cloud-aws:externalSecurityGroups' " +
        "when setting 'cloud-asws:externalVpcId'",
    );
}

/**
 * Optionally use Fargate-based container compute. All tasks must be Fargate-compatible.
 */
export let useFargate = config.getBoolean("useFargate") || false;

/**
 * Optionally auto-provision an ECS Cluster.  If set to true, parameters for the cluster can be provided via
 * the other "ecsAutoCluster*" configuration variables.
 */
export let ecsAutoCluster = config.getBoolean("ecsAutoCluster") || false;
/**
github pulumi / pulumi-cloud / aws / service.ts View on Github external
}
                firstPort = false;

                const fullHost = hostname.apply(h => `${hostproto}://${h}:${hostport}`);
                preEnv[`${serviceEnv}_PORT`] = fullHost;
                preEnv[`${serviceEnv}_PORT_${port}_TCP`] = fullHost;
                preEnv[`${serviceEnv}_PORT_${port}_TCP_PROTO`]= hostproto;
                preEnv[`${serviceEnv}_PORT_${port}_TCP_PORT`] = hostport;
                preEnv[`${serviceEnv}_PORT_${port}_TCP_ADDR`] = hostname;
            }
        }
    }

    if (container.build) {
        if (!repository) {
            throw new RunError("Expected a container repository for build image");
        }

        return computeImageFromBuild(preEnv, container.build, imageName, repository);
    }
    else if (container.image) {
        return computeImageFromImage(preEnv, imageName);
    }
    else if (container.function) {
        return computeImageFromFunction(container.function, preEnv, imageName);
    }
    else {
        throw new RunError("Invalid container definition: `image`, `build`, or `function` must be provided");
    }
}
github pulumi / pulumi-cloud / aws / service.ts View on Github external
function getEndpointHelper(
    endpoints: Endpoints, containerName: string | undefined, containerPort: number | undefined): Endpoint {


    containerName = containerName || Object.keys(endpoints)[0];
    if (!containerName)  {
        throw new RunError(`No containers available in this service`);
    }

    const containerPorts = endpoints[containerName] || {};
    containerPort = containerPort || +Object.keys(containerPorts)[0];
    if (!containerPort) {
        throw new RunError(`No ports available in service container ${containerName}`);
    }

    const endpoint = containerPorts[containerPort];
    if (!endpoint) {
        throw new RunError(`No exposed port for ${containerName} port ${containerPort}`);
    }

    return endpoint;
}
github pulumi / pulumi-cloud / azure / timer.ts View on Github external
export function hourly(name: string,
                       scheduleOrHandler: timer.HourlySchedule | timer.Action,
                       handlerOrOptions?: timer.Action | pulumi.ResourceOptions,
                       opts?: pulumi.ResourceOptions): void {
    let minute: number;
    let handler: timer.Action;
    if (typeof scheduleOrHandler === "function") {
        minute = 0;
        handler = scheduleOrHandler as timer.Action;
        opts = handlerOrOptions as pulumi.ResourceOptions | undefined;
    }
    else if (!scheduleOrHandler) {
        throw new RunError("Missing required timer handler function");
    }
    else {
        minute = scheduleOrHandler.minuteUTC || 0;
        handler = handlerOrOptions as timer.Action;
    }
    cron(name, `${minute} * * * ? *`, handler, opts);
}
github pulumi / pulumi-cloud / azure / timer.ts View on Github external
export function daily(name: string,
                      scheduleOrHandler: timer.DailySchedule | timer.Action,
                      handlerOrOptions?: timer.Action | pulumi.ResourceOptions,
                      opts?: pulumi.ResourceOptions): void {
    let hour: number;
    let minute: number;
    let handler: timer.Action;
    if (typeof scheduleOrHandler === "function") {
        hour = 0;
        minute = 0;
        handler = scheduleOrHandler as timer.Action;
        opts = handlerOrOptions as pulumi.ResourceOptions | undefined;
    }
    else if (!scheduleOrHandler) {
        throw new RunError("Missing required timer handler function");
    }
    else {
        hour = scheduleOrHandler.hourUTC || 0;
        minute = scheduleOrHandler.minuteUTC || 0;
        handler = handlerOrOptions as timer.Action;
    }
    cron(name, `${minute} ${hour} * * ? *`, handler, opts);
}