AWS StackReference Architecture
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-ts-stackreference-architecturecd pulumi-examples/aws-ts-stackreference-architectureThis will deploy a Data VPC and an application VPC that is peered. It will deploy an RDS Instance into the Data VPC and it will run a sample application in ECS that is fronted with an ALB.
The system has the following layers and need to be deployed in the following order to allow the correct data to be used between the system:
- Networking
- Database
- Application
Pre-Requisites#
- Install Pulumi.
- Install Node.js.
- Install a package manager for Node.js, such as NPM or Yarn.
- Configure AWS Credentials.
Network#
-
Change to the networking project
Terminal window cd networking -
Install the dependencies.
Terminal window npm install -
Create a new Pulumi stack named
dev.Terminal window pulumi stack init dev -
Set the Pulumi configuration variables for the project.
Terminal window pulumi config set aws:region us-west-2If you wish to control the number of availability zones that the VPC will be created within, you can do this by setting:
Terminal window pulumi config set azCount 3 -
Deploy the networking stack
Terminal window pulumi up
Database#
-
Change to the database project
Terminal window cd database -
Install the dependencies.
Terminal window npm install -
Create a new Pulumi stack named
dev.Terminal window pulumi stack init dev -
Set the Pulumi configuration variables for the project:
Terminal window pulumi config set aws:region us-west-2pulumi config set dbUsername MyRootUserpulumi config set dbPassword --secret MyPassword1234!You need to set a stack reference to the networking stack so that the RDS Instance can be deployed into the correct VPC that was created in the networking stack. The stack needs to be in the form
<organization_or_user>/<projectName>/<stackName>e.g.myUsername/multicloud/dev:Terminal window pulumi config set networkingStack stack72/networking-layer/devIf you wish to specify an initial database name in the RDS Instance, then you can do so by setting the following:
Terminal window pulumi config set dbName myDatbaseName -
Deploy the database stack
Terminal window pulumi up
Application#
-
Change to the application project
Terminal window cd application -
Install the dependencies.
Terminal window npm install -
Create a new Pulumi stack named
dev.Terminal window pulumi stack init dev -
Set the Pulumi configuration variables for the project:
Terminal window pulumi config set aws:region us-west-2You need to set a stack reference to the networking stack so that the RDS Instance can be deployed into the correct VPC that was created in the networking stack. The stack needs to be in the form
<organization_or_user>/<projectName>/<stackName>:Terminal window pulumi config set networkingStack stack72/networking-layer/devYou need to set a stack reference to the database stack so that the Application Instance can get the correct credentials and database information for application startup. The stack needs to be in the form
<organization_or_user>/<projectName>/<stackName>:Terminal window pulumi config set application-layer:databaseStack stack72/database-layer/dev -
Deploy the application stack
Terminal window pulumi up
You can then take the output albAddress and hit it with curl or in the browser to see the application running.
Clean Up#
In each of the directories, run the following command to tear down the resources that are part of our stack.
-
Run
pulumi destroyto tear down all resources. You’ll be prompted to make sure you really want to delete these resources.Terminal window pulumi destroy -
To delete the stack, run the following command.
Terminal window pulumi stack rmNote: This command deletes all deployment history from the Pulumi Console and cannot be undone.