Skip to content

This Repo houses some examples used to demonstrate concepts in a "Resource Protection and Segregation" Whiltepaper

Notifications You must be signed in to change notification settings

pulumi-demos/resource-protection-segregation

Repository files navigation

Azure Cosmos DB, an API Connection, and a Logic App - Multistack Approach

This is a multi-stack version of this example: https://github.com/pulumi/examples/tree/master/azure-py-cosmosdb-logicapp

It is used to show how stack references and the protect flag can be used to protect and segregate stacks/resources.

Pulumi Projects In the Repo

The BaseInfra project deploys the Resource Group, and CosmosDB.

The App_InLine_StackRef project uses a stack reference in the code to be able to deploy the web connection and workflow for the app on top of the BaseInfra stack.

The App_ESC_StackRef projects uses an ESC Environment and the ESC stacks provider to project the BaseInfra stack outputs to the App_ESC_StackRef stack as stack config.

Prerequisites

  1. Install Pulumi
  2. Configure Pulumi for Azure
  3. Configure Pulumi for Python

Set up the Environment

  1. Login to Azure
    $ pulumi config set azure-native:location westeurope
    $ az login

Deploy the BaseInfra Project

  1. Create a new stack:

    $ cd BaseInfra
    $ pulumi stack init dev
  2. Create a Python virtualenv, activate it, and install dependencies:

    This installs the dependent packages needed for our Pulumi program.

    $ python3 -m venv venv
    $ source venv/bin/activate
    $ pip3 install -r requirements.txt
  3. Set the required configuration variables for this program, and log into Azure:

    $ pulumi config set azure-native:location centralus
  4. Perform the deployment:

    $ pulumi up

Deploy the App_InLine_StackRef Project

  1. Create a new stack:

    $ cd App_InLine_StackRef
    $ pulumi stack init dev
  2. Create a Python virtualenv, activate it, and install dependencies:

    This installs the dependent packages needed for our Pulumi program.

    $ python3 -m venv venv
    $ source venv/bin/activate
    $ pip3 install -r requirements.txt
  3. Set the required configuration variables for this program, and log into Azure:

    $ pulumi config set azure-native:location centralus
    $ pulumi config set azure-cosmosdb-app:baseProjectName azure-cosmosdb-base
  4. Perform the deployment:

    $ pulumi up

Deploy the App_ESC_StackRef Project

  1. Create a new stack:

    $ cd App_ESC_StackRef
    $ pulumi stack init dev
  2. Create a Python virtualenv, activate it, and install dependencies:

    This installs the dependent packages needed for our Pulumi program.

    $ python3 -m venv venv
    $ source venv/bin/activate
    $ pip3 install -r requirements.txt
  3. Create the ESC Environment to Reference the BaseInfra Stack

    Using the YAML below, create an environment in the Pulumi UI or by using pulumi env init [<org-name>/][<project-name>/]<environment-name> -f FILE_WITH_BELOW_YAML.

    # Use the stacks provider to get and project the kubeconfig from the given K8s cluster stack.
    values:
        stack-outputs:
            fn::open::pulumi-stacks:
                stacks:
                    cosmosdb-base-infra:
                        # Set this to the name of the stack being referenced
                        stack: azure-cosmosdb-base/dev
        pulumiConfig:
            cosmosdb_account_name: ${stack-outputs.cosmosdb-base-infra.cosmosdb_account_name}
            resource_group_name: ${stack-outputs.cosmosdb-base-infra.resource_group_name}
            resource_group_location: ${stack-outputs.cosmosdb-base-infra.resource_group_location}
            db_name: ${stack-outputs.cosmosdb-base-infra.db_name}
            db_container_name: ${stack-outputs.cosmosdb-base-infra.db_container_name}
    
  4. Set the required configuration variables for this program, and log into Azure:

    $ pulumi config set azure-native:location centralus

    Edit the stack config file (e.g. Pulumi.dev.yaml) with:

    environment
      - PROJECT/ENVIRONMENT
    

    Where PROJECT/ENVIRONMENT references the environment created above.

  5. Perform the deployment:

    $ pulumi up

Using the Infrastruture

  1. At this point, you have a Cosmos DB collection and a Logic App listening to HTTP requests. You can trigger the Logic App with a curl command:

    $ cd AppProject
    $ curl -X POST "$(pulumi stack output endpoint)" -d '"Hello World"' -H 'Content-Type: application/json'
    

    The POST body will be saved into a new document in the Cosmos DB collection.

  2. Once you are done, you can destroy all resources and stacks by running the following in the AppProject folder and then the BaseProject folder:

    $ pulumi destroy
    $ pulumi stack rm

About

This Repo houses some examples used to demonstrate concepts in a "Resource Protection and Segregation" Whiltepaper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages