How to use the command 'pulumi up' (with examples)
The ‘pulumi up’ command is used to create or update the resources in a stack. It allows you to preview and deploy changes to your program and/or infrastructure. It is a powerful command that enables you to easily manage and update your infrastructure in a declarative manner.
Use case 1: Preview and deploy changes to a program and/or infrastructure
Code:
pulumi up
Motivation: When making changes to your program and/or infrastructure, it is important to preview the changes before deploying them. The ‘pulumi up’ command allows you to see the changes that will be applied without actually performing them. This gives you an opportunity to review the changes and ensure they are as expected before applying them.
Explanation: The ‘pulumi up’ command is executed without any additional arguments. It operates on the current stack in the current directory. It analyzes the program and/or infrastructure changes since the last deployment and shows a preview of the changes to be applied. This allows you to verify the changes before applying them.
Example output:
Previewing update (dev):
Type Name Plan
+ pulumi:pulumi:Stack my-stack-dev create
+ ├─ pulumi:providers:aws us-west-2 create
+ │ ├─ aws:ec2:SecurityGroup web-security-group create
+ │ │ ├─ aws:ec2:SecurityGroupRule http-ingress create
+ │ │ └─ aws:ec2:SecurityGroupRule ssh-ingress create
+ └─ aws:ec2:Instance web-server create
Resources:
+ 7 to create
Use case 2: Automatically approve and perform the update after previewing it
Code:
pulumi up --yes
Motivation: In some cases, you may want to automate the deployment process and skip the manual approval step. The ‘–yes’ flag allows you to automatically approve and perform the update after previewing it. This can be useful when you trust the changes and want to easily deploy them without any additional interaction.
Explanation: The ‘–yes’ flag is added to the ‘pulumi up’ command. It signifies that the update should be automatically approved and performed without requiring manual confirmation. This flag is useful when you want to automate the deployment process and skip the approval prompt.
Example output:
Updating (dev):
Type Name Status
+ pulumi:pulumi:Stack my-stack-dev created
+ ├─ pulumi:providers:aws us-west-2 created
+ │ ├─ aws:ec2:SecurityGroup web-security-group created
+ │ │ ├─ aws:ec2:SecurityGroupRule http-ingress created
+ │ │ └─ aws:ec2:SecurityGroupRule ssh-ingress created
+ └─ aws:ec2:Instance web-server created
Outputs:
instanceId : "i-0123456789"
Resources:
+ 7 created
Use case 3: Preview and deploy changes in a specific stack
Code:
pulumi up --stack stack
Motivation: When working with multiple stacks, you may want to specify which stack to update. The ‘–stack’ flag allows you to target a specific stack for previewing and deploying changes. This gives you the flexibility to update a specific stack while working with multiple independent environments.
Explanation: The ‘–stack’ flag is added to the ‘pulumi up’ command, followed by the stack name. It specifies the stack where the changes will be applied. This allows you to isolate and update a specific stack while working with multiple stacks in the same project.
Example output:
Previewing update (prod):
Type Name Plan
+ pulumi:pulumi:Stack my-stack-prod create
+ ├─ pulumi:providers:aws us-east-1 create
+ │ ├─ aws:ec2:SecurityGroup web-security-group create
+ │ │ ├─ aws:ec2:SecurityGroupRule http-ingress create
+ │ │ └─ aws:ec2:SecurityGroupRule ssh-ingress create
Resources:
+ 5 to create
Conclusion:
The ‘pulumi up’ command is a versatile tool for managing and updating your infrastructure. By previewing and deploying changes to your program and/or infrastructure, you can confidently make updates and ensure they are as expected. The ability to automate the approval and target specific stacks makes it even more powerful for managing complex environments.