How to use the @pulumi/pulumi.getStack 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 / tests / integration / aliases / step2 / index.ts View on Github external
// Copyright 2016-2018, Pulumi Corporation.  All rights reserved.

import * as pulumi from "@pulumi/pulumi";

const stackName = pulumi.getStack();
const projectName = pulumi.getProject();

class Resource extends pulumi.ComponentResource {
    constructor(name: string, opts?: pulumi.ComponentResourceOptions) {
        super("my:module:Resource", name, {}, opts);
    }
}

// Scenario #1 - rename a resource
// This resource was previously named `one`, we'll alias to the old name.
const res1 = new Resource("newres1", {
    aliases: [`urn:pulumi:${stackName}::${projectName}::my:module:Resource::res1`],
});

// Scenario #2 - adopt a resource into a component The component author is the same as the component user, and changes
// the component to be able to adopt the resource that was previously defined separately...
github pulumi / pulumi / tests / integration / stack_project_name / index.ts View on Github external
// Copyright 2016-2018, Pulumi Corporation.  All rights reserved.

import * as pulumi from "@pulumi/pulumi";

const stackName = pulumi.getStack();
if (!stackName) {
    // We can't check for a specific stack name, since it is autogenerated by the test framework.  But
    // we *can* verify that it isn't blank.
    throw new Error("Empty pulumi.getStack() at runtime");
}

const expName = "stack_project_name";
const projName = pulumi.getProject();
if (projName !== expName) {
    throw new Error(`Unexpected pulumi.getProject(); wanted '${expName}', got '${projName}'`);
}
github communitybridge / easycla / infra / index.ts View on Github external
// Copyright The Linux Foundation and each contributor to CommunityBridge.
// SPDX-License-Identifier: MIT

import * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
import {PrivateAcl, PublicReadAcl} from '@pulumi/aws/s3';

const accountID = aws.getCallerIdentity().accountId;
const stackName = pulumi.getStack();
const stage = pulumi.getStack();
const region = aws.getRegion().name;
// Enable point in time recover on the production databases
const pointInTimeRecoveryEnabled = (stage == 'prod');

// Set to true if you want pulumi to import an existing resources in AWS into
// the current stack. This is typically done the first time only and once it is
// part of the stack, we set this value to false since it would then be under
// control of pulumi.
const importResources = false;
const defaultReadCapacity = 10;
const defaultWriteCapacity = 1;

console.log('Pulumi project name is  : ' + pulumi.getProject());
console.log('Pulumi stack name is    : ' + stackName);
console.log('Account ID is           : ' + accountID);
console.log('STAGE is                : ' + stage);
github pulumi / pulumi-cloud / azure / shared.ts View on Github external
export function createNameWithStackInfo(requiredInfo: string, maxLength: number, delim: string) {
    if (requiredInfo.length > maxLength) {
        throw new RunError(`'${requiredInfo}' cannot be longer then ${maxLength} characters.`);
    }

    if (requiredInfo.length === 0) {
        throw new RunError(`[requiredInfo] must be non-empty`);
    }

    const stackName = pulumi.getStack();

    // 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 - delim.length) {
        return requiredInfo;
    }

    // Attempt to keep some portion of the stack, then - then the required part.
    const suffix = delim + requiredInfo;
    const result = stackName.substr(0, maxLength - suffix.length) + suffix;
    return result;
}
github pulumi / pulumi-cloud / azure / shared.ts View on Github external
async function getOrCreateGlobalResourceGroup() {
        const resourceGroupName = azureConfig.get("resourceGroupName");
        if (resourceGroupName) {
            // User specified the resource group they want to use.  Go fetch that.
            const result = await azure.core.getResourceGroup({
                name: resourceGroupName,
            });

            return azure.core.ResourceGroup.get("global", result.id);
        }

        // Create a new resource group to use.
        return new azure.core.ResourceGroup("global", {
            // https://docs.microsoft.com/en-us/azure/architecture/best-practices/naming-conventions#general
            // Resource groups have a max length of 90.
            name: createNameWithStackInfo("global-" + sha1hash(pulumi.getStack()), 90, "-"),
            location: location,
        },
        { parent: getGlobalInfrastructureResource() });
    }
}
github pulumi / pulumi-cloud / azure / shared.ts View on Github external
function getOrCreateGlobalStorageAccount(): azure.storage.Account {
    const storageAccountId = azureConfig.get("storageAccountId");
    if (storageAccountId) {
        return azure.storage.Account.get("global", storageAccountId);
    }

    // Account name must be 24 chars or less and must be lowercase.
    // https://docs.microsoft.com/en-us/azure/architecture/best-practices/naming-conventions#storage
    const storageAccountName = makeSafeStorageAccountName(
        createNameWithStackInfo("global" + sha1hash(pulumi.getStack()), 24, /*delim*/ ""));

    return new azure.storage.Account("global", {
        resourceGroupName: globalResourceGroupName,
        location: location,
        name: storageAccountName,
        accountKind: "StorageV2",
        accountTier: "Standard",
        accountReplicationType: "LRS",
    }, { parent: getGlobalInfrastructureResource() });
}
github pulumi / pulumi-awsx / nodejs / awsx / ecs / taskDefinition.ts View on Github external
        const family = containerString.apply(s => name + "-" + utils.sha1hash(pulumi.getStack() + containerString));